Skip to content

Instantly share code, notes, and snippets.

View radist2s's full-sized avatar

Alex Batalov radist2s

  • Georgia, Tbilisi
View GitHub Profile
@radist2s
radist2s / .htaccess
Last active December 29, 2015 16:09
Simple Web Server file throttle sending via PHP. (Low bandwidth emulation)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.+\.(?:jpg|jpeg|gif|png))$ /throttle.php?$1 [L]
</IfModule>
@radist2s
radist2s / load-script.js
Last active May 31, 2016 11:52
JS Script loader
/**
* Usage:
* loadScript('//exmp.com/script.js')
* loadScript('//exmp.com/script-another.js', function(){runCallback()}, {'data-attribute': 'has'})
* Will not be loaded, because loaded earlier:
* loadScript('//exmp.com/script.js')
**/
/** @type {loadScript} */
var loadScript = (function () {
@radist2s
radist2s / url-parser.js
Last active September 5, 2017 11:25
Javascript Simple url creator. Trim slashes.
var site_url = window.site_url,
site_path = window.site_path
var escapeRegExp = function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
/**
* @param {boolean} [leftTrim]
* @param {boolean} [rightTrim]
@radist2s
radist2s / functions.php
Last active June 23, 2017 11:55
Wordpress ajax suffixer. (Need to work with WP chaching plugins like WP Super Cache, W3 Total cache, etc)If page has url "http://xmp.com/tax/tem/page-name" then ajax version of this page is "http://xmp.com/tax/tem/page-name/ajax"In template you can check AJAX request via const "IS_AJAX" (if (IS_AJAX){})
<?php
/**
* Detect ajax request
*/
add_filter('parse_request', function ($query_vars)
{
if (is_admin())
{
return $query_vars;
}
/**
* jQuery.reduce - a jQuery plugin for functional programming
* @author Alex Batalov, John Hunter
* use: $('.elements').reduce(function(memo){return memo + $(this).height()}, 0);
* fnReduce is called with arguments: [valueInitial, value, i, arr]
*
* created 2010-09-17
* modiffied 2013-12-09
*/
@radist2s
radist2s / resolved.js
Last active August 29, 2015 13:56
Return only resolved $.Deferred objects.
$.resolved = function () {
var defers = arguments,
defersResolvedData = [],
alwaysCount = 0
var resolvedDeferWrapper = $.Deferred()
var always = function checkQueue() {
if (++alwaysCount === defers.length) {
resolvedDeferWrapper.resolveWith($, defersResolvedData)
@radist2s
radist2s / RequestAnimationFrame.js
Last active November 29, 2015 14:52 — forked from paulirish/rAF.js
RequestAnimationFrame Polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
!window.requestAnimationFrame && (window.requestAnimationFrame = null)
!window.cancelAnimationFrame && (window.cancelAnimationFrame = null)
@radist2s
radist2s / gulp-less-sourcemap-config.js
Created May 7, 2014 19:19
Gulpfile for LESS compilation with external sourcemap file support
var gulp = require('gulp');
var less = require('gulp-less');
var path = require('path');//
var fs = require('fs');
var ensureDirectory = function (filepath) {
var dir = path.dirname(filepath),
cmd,
existsSync = fs.existsSync || path.existsSync;
if (!existsSync(dir)) {
@radist2s
radist2s / ready-checker.js
Created May 20, 2014 17:30
Simple ready checker (simple deferred) + Dom ready Checker
var ReadyChecker = (function () {
/**
* Simple Deferred
* @param {Function} readyCheckerResolver
* @param {Function} [callback]
* @constructor
*/
function ReadyChecker (readyCheckerResolver, callback) {
this.onReady(callback)
@radist2s
radist2s / transition-end-event-name.js
Last active October 25, 2017 14:21
Get transition complete event name
var transitionEventName
function getTransitionEndEventName() {
if (transitionEventName !== undefined) {
return transitionEventName
}
var detectedTransition,
el = document.createElement('transitiondetector'),
transitions = {