Skip to content

Instantly share code, notes, and snippets.

View yairEO's full-sized avatar
🙂
Writing code

Yair Even Or yairEO

🙂
Writing code
View GitHub Profile
@yairEO
yairEO / vsync_demos.css
Last active October 1, 2018 19:13
Basic CSS for simple Github demos
html, body{ min-height:100%; }
body{
font:14px Arial; margin:0;
background-image : linear-gradient(to left, #F3F3F3 100%, transparent 0%);
background-repeat : no-repeat;
background-size : 50% 1000%;
overflow-x:hidden;
} /* display:flex; flex-flow: column nowrap; align-items:center; justify-content:center; */
.forkLink{ position:fixed; z-index:100; border:0; top:0; width:70px; right:0; opacity:.8; transition:.15s ease-out; }
@yairEO
yairEO / jQuery.removeClassPrefix.js
Created February 21, 2017 11:38
jQuery extention to remove class by wild-card
/**
* remove class by wild-card
* http://stackoverflow.com/a/10835425/104380
*/
$.fn.removeClassPrefix = function(prefix){
this.each(function(){
var c = this.getAttribute('class'),
regex = new RegExp("(^|\\s)" + prefix + "\\S+", 'g');
@yairEO
yairEO / jQuery AJAX delay with timeout
Last active February 27, 2017 09:23
Wrapper for jQuery AJAX method which sets a random delay with simuulates real-world latency
(function(){
$._oldAjax = $.ajax; // save reference to the "real" ajax method
// override the method with a wrapper
$.ajax = function(){
var def = new $.Deferred(),
delay = typeof $.ajax.delay == 'undefined' ? 500 : $.ajax.delay,
delayTimeout,
args = arguments[0];
@yairEO
yairEO / jQuery.ajaxRetry.js
Last active January 12, 2022 14:55
jQuery AJAX smart retry
// enhance the original "$.ajax" with a retry mechanism
$.ajax = (($oldAjax) => {
// on fail, retry by creating a new Ajax deferred
function check(a,b,c){
var shouldRetry = b != 'success' && b != 'parsererror';
if( shouldRetry && --this.retries > 0 )
setTimeout(() => { $.ajax(this) }, this.retryInterval || 100);
}
return settings => $oldAjax(settings).always(check)
@yairEO
yairEO / console.json.js
Last active September 28, 2017 09:21
Console.json
console.json = console.json || function(argument){
for(var arg = 0; arg < arguments.length; ++ arg)
console.log( JSON.stringify(arguments[arg], null, 4) );
}
@yairEO
yairEO / jQuery.findClosest.js
Created April 29, 2017 11:05
jQuery plugin - find closest (inside / outside)
// http://stackoverflow.com/a/29823718/104380
jQuery.fn.findClosest = function (selector) {
// If we have a :this selector
var output = $(),
down = this.find(selector),
siblings,
recSearch,
foundCount = 0;
@yairEO
yairEO / jQuery.clickLimit.js
Last active September 5, 2017 11:57
jQuery special-event "clickLimit" [only fires the event if a duration threshold hasn't passed]
jQuery.event.special.clickLimit = {
delegateType: "mousedown",
bindType: "mousedown",
handle: function( event ) {
var handleObj = event.handleObj,
startTime = new Date().getTime(),
threshold = event.data.threshold || 500;
$(this)
.unbind('mouseup.clickLimit')
@yairEO
yairEO / dependencies.js
Created September 28, 2017 09:25
jQuery files dependencies loader
/**
* By - Yair Even-Or (2017) MIT license
* loads, using jQuery, dependency files.
* @param {Object} settings [files (Array), baseDir (String), sync (Boolean)]
* @return {Object} [promise]
*/
window.dependencies = {
/**
* @param {Object/Array} settings [either a "settings" object or a simple Array of files to load]
* @return {Object} [jQuery AJAX (promise)]
@yairEO
yairEO / lodash.formatBytes.js
Created September 28, 2017 09:31
lodash "formatBytes" mixin
_.mixin({
"formatBytes" : function(kiloBytes, decimals){
if(kiloBytes == 0) return ['0', 'KB'];
var k = 1024,
dm = decimals + 1 || 1,
sizes = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(kiloBytes) / Math.log(k));
return [parseFloat((kiloBytes / Math.pow(k, i)).toFixed(dm)).toLocaleString() , sizes[i]]; // parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' +
@yairEO
yairEO / jQuery.addTempClass.js
Created October 3, 2017 20:00
add temporary class
$.fn.addTempClass = function(tempClass, duration){
if( !tempClass )
return this;
return this.each(function(){
var $elm = $(this),
timer;
$elm.addClass(tempClass);