Skip to content

Instantly share code, notes, and snippets.

Avatar
💃
On vacation

Vitaly Kondratiev VitalyKondratiev

💃
On vacation
View GitHub Profile
View link_scrapper.js
@VitalyKondratiev
VitalyKondratiev / _arrd.php
Created Jul 19, 2019
PHP: Recursive difference finder of 2 objects
View _arrd.php
<?php
function _arrd($array1, $array2, $label, $depth = 0, $has_diff = false) {
$array1 = (array)$array1;
$array2 = (array)$array2;
if (!$depth) {
$label .= ': ';
}
$diff = array_diff_assoc($array1, $array2);
if (count($diff)) {
echo "$label\n";
@VitalyKondratiev
VitalyKondratiev / get_object_by_property_value.cs
Last active Feb 10, 2019
Get object by value of selected property
View get_object_by_property_value.cs
object GetObjectByName<T>(string needle, T[] objs, string propertyName = "")
{
foreach (T obj in objs)
{
/*
* For string objects uses string value
* For another objects property searched by given string
* If property not found, uses obj.ToString() value
*/
string searched_value;
@VitalyKondratiev
VitalyKondratiev / proxylist.js
Created Jan 30, 2019
Getting list of working proxies on Node.js (node module, promise)
View proxylist.js
const osmosis = require('osmosis');
module.exports = function () {
return new Promise(function (resolve, reject) {
let proxies = [];
osmosis
.get('https://free-proxy-list.com/?search=1&up_time=60')
.find('.proxy-list tbody tr td:first-child a')
.set({ 'data': '@title' })
.error(error => reject(proxies))
.data(data => proxies.push(data.data))
@VitalyKondratiev
VitalyKondratiev / dl_require_template.js
Last active Jan 23, 2019
Loading modules from NPM at runtime
View dl_require_template.js
dl_require(['beauty', 'moment']).then(_modules => {
/* Demo data end */
var beauty = _modules.beauty;
var moment = _modules.moment;
beauty.beautifyConsole();
console.log('log:', 'you can put your code here');
console.info('info:', moment().format("dddd, MMMM Do YYYY, h:mm:ss a"));
/* Demo data end */
});
@VitalyKondratiev
VitalyKondratiev / functions.php
Created Nov 29, 2018
Wordpress taxonomy menu (wp_get_nav_menu_items hook)
View functions.php
add_filter("wp_get_nav_menu_items", function ($items, $menu, $args) {
$menu_id = 21; // Wordpress Menu ID
$menu_item_id = 48; // Wordpress Menu Item ID
$taxonomy_name = 'product_cat'; // Wordpress Taxonomy Code
$max_depth = 3; // Maximum level of menu depth
if( $menu->term_id != $menu_id || is_admin()) return $items;
$get_nav_from_terms = function (&$items, $terms, $parent_menu_id, $order, $depth = 1) use ($max_depth, &$get_nav_from_terms) {
if ($depth > $max_depth) return;
foreach ($terms as $term) {
$item = new stdClass();
@VitalyKondratiev
VitalyKondratiev / LaravelSeed-JavaScript.html.js
Created Nov 18, 2018
Экстрактор JetBrains DataGrip для создания Laravel Seeds
View LaravelSeed-JavaScript.html.js
var LINE_FEED = "\n";
var LINE_TABULATION = "\t";
var TABLE_NAME = (TABLE !== null ) ? TABLE.getName() : 'table';
function output() {
for (var i = 0; i < arguments.length; i++) {
OUT.append(arguments[i]);
}
}
@VitalyKondratiev
VitalyKondratiev / block_slidedown.js
Last active Oct 10, 2017
Плавное "выезжание" блока при скролле страницы
View block_slidedown.js
$(document).ready(function (){
$('.for-slidedown').addClass('slidedown-ready')
$(window).on('scroll', function (event) {
$('.for-slidedown.slidedown-ready').each(function () {
if (window.innerHeight + window.pageYOffset >= $(this).offset().top) {
$(this).removeClass('slidedown-ready');
}
});
});
});
@VitalyKondratiev
VitalyKondratiev / jquery.parallaxBackground.js
Last active Nov 16, 2017
Параллакс фоновой картинки элемента
View jquery.parallaxBackground.js
(function ($) {
jQuery.fn.parallaxBackground = function (options) {
options = $.extend({
min: 0,
max: 100,
speed: 1
}, options);
var previousScroll = 0;
var directionScroll;
@VitalyKondratiev
VitalyKondratiev / bootstrap_hover_dropdowns.js
Last active Nov 9, 2017
Открытие выпадающих списков по наведению (Bootstrap)
View bootstrap_hover_dropdowns.js
function is_touch_device() {
try {
document.createEvent("TouchEvent");
return true;
} catch (e) {
return false;
}
}
if (is_touch_device) return;
$('.pane-system-main-menu .nav .dropdown .dropdown-toggle').hover(function() {
You can’t perform that action at this time.