Skip to content

Instantly share code, notes, and snippets.

View wit-Roman's full-sized avatar
🤓
Focusing

Roman wit-Roman

🤓
Focusing
View GitHub Profile
@wit-Roman
wit-Roman / Variety.js
Last active November 12, 2019 14:21
Множества
//1.Пересечение
function cross(arr1=[],arr2=[]) {
let answ = []
for ( let i = 0; i < arr1.length; i++ ) {
for ( let j = 0; j < arr2.length; j++ ) {
if (arr1[i] === arr2[j] && !answ.includes(arr1[i]) )
answ.push(arr1[i]);
}
}
return answ;
@wit-Roman
wit-Roman / algorithm.js
Last active May 26, 2020 10:09
basic algorithms
function search1(length=0,arr=[],x=0) {
if (length > 1000 || Math.abs(x) > 1000 ) return false;
for ( let i = 0; i < length; i++ ) {
if (Math.abs(arr[i]) > 1000) return false;
}
for ( let i = 0; i < length; i++ ) {
if (arr[i] === x) return 'YES';
}
return 'NO';
}
@wit-Roman
wit-Roman / controller.php
Last active September 6, 2018 07:47
Simple page catalog MVC
<?php
require_once('model.php');
$page = new PageGenerator();
if ( isset($_GET['min-row']) && isset($_GET['max-row']) )
$page->write_tobd_fromcsv($_GET['min-row'],$_GET['max-row']);
if ( isset($_GET['brand']) )
$page->create_new_brand_page($_GET['brand'],$_GET['image'],$_GET['mader'],$_GET['site'],$_GET['shipment'],$_GET['content']);
@wit-Roman
wit-Roman / onEventHadler.php
Last active April 17, 2018 08:05
Bitrix отправка: событие инфоблока -> почтовые шаблоны
/**
*@
Методы:
simple - перебор и присвоение свойств: наименование - значение
universal - полный поиск свойства: наименование - значение
autoFields - полный поиск свойства для шаблона: ключ - значение
taskAdminFAQNewTopic
taskCustomerFAQNewTopic
Доступные поля:
@wit-Roman
wit-Roman / wit-filter.php
Last active July 3, 2020 10:09
Woocommerce product filter
<?php
add_action( 'widgets_init', function(){ register_widget( 'Wit_Widget_Mader_and_Price_Filter' ); });
wp_enqueue_script( 'wit_filter_script', get_template_directory_uri() . '/inc/wit-filter.js', [], "1.0.0", true );
wp_localize_script( 'wit_filter_script', 'wit_filter_vars', array(
'wit_filter_ajax_url' => admin_url( 'admin-ajax.php' ),
));
add_action('wp_ajax_wit_filter', 'activate_wit_filter');
@wit-Roman
wit-Roman / index.php
Last active June 15, 2018 09:45
301 Redirect HTTPS if server bad config
if( $_SERVER["HTTP_X_FORWARDED_PROTO"] === "http" ) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
}
#apache
Options +FollowSymLinks
RewriteEngine On
#RewriteCond %{HTTP_HOST} !^www\.{HTTP_HOST}\.ru$ [NC]
@wit-Roman
wit-Roman / option.php
Last active October 17, 2017 14:22
Simple slider with control admin panel on wordpress
<?php
if ( ! defined( 'ABSPATH' ) ) {exit;}
if ( ! class_exists( 'wit_theme_options' ) ) {
class wit_theme_options {
public function __construct() {
if ( is_admin() ) {
@wit-Roman
wit-Roman / ajax-survey.js
Created October 17, 2017 14:09
Flex Surveys on WP-posts with editable several steps and variantions
jQuery(document).ready(function() {
/*
jQuery("#quest-content input[type=radio]").change(function() {
jQuery(".original-quest").remove();
if(this.value=="original") {
jQuery(this).after('<input class="original-quest" type="text">');
}
});
var elem = jQuery("#quest-form input[type=radio]");
@wit-Roman
wit-Roman / form.htm
Last active March 16, 2018 04:09
Custom form with several files upload validation on validation.js and wordpress
<form name="mes_form" method="POST" enctype="multipart/form-data">
<fieldset id="mes_data">
<input type="text" name="mes_name" placeholder="Ваше имя" class="message-input" />
<input type="text" name="mes_email" placeholder="Ваш адрес почты" class="message-input" />
<input type="hidden" name="mes_check" />
<textarea name="mes_text" placeholder="Ваше сообщение" class="message-input"></textarea>
</fieldset>
<fieldset id="mes_inputs">
<input type="file" name="mes_files[]" id="message-files" placeholder="Файлы для загрузки" class="message-input" size="0" multiple/>
<input type="submit" name="mes_submit" value="Отправить" id="message-submit" class="message-input" />
@wit-Roman
wit-Roman / wit-import.js
Last active October 19, 2017 12:11
Import table from google-spreadsheet to wp-db with wordpress+woocommerce
function ajax_get_json(url, callback) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
const data = JSON.parse(this.responseText);
callback(data);
}
};
xhttp.open("GET", url, true);
xhttp.send();