Skip to content

Instantly share code, notes, and snippets.

vsync yairEO

View GitHub Profile
@yairEO
yairEO / composition.js
Created Apr 15, 2019
Composition example
View composition.js
function last(n){
return next => next - n;
}
function second(n){
return next => next * n;
}
function first(n){
return next => next + n;
@yairEO
yairEO / deepBind.js
Created Feb 20, 2019
deepBind for object methods at any depth with any context
View deepBind.js
function deepBind(O){
for(var key in O)
// if value is an object, go deeper
if( O[key] instanceof Object && typeof O[key] == 'object' )
deepBind.call(this, O[key])
// look for a value which is a function and bind it
else if( typeof O[key] == 'function' )
O[key] = O[key].bind(this);
}
@yairEO
yairEO / localstore.js
Created Jan 30, 2019
localstorge helper
View localstore.js
const localstore = {
NAMESPACE : '',
/**
* Set localStorage value in a given key
* @param {String} name
* @param {*} value
*/
set( name, value='' ){
try {
@yairEO
yairEO / styled.js
Created Jan 9, 2019
Better Styled-Components
View styled.js
const styleParams = {
height : '2.8rem',
handleWidth : 14,
handleExtraHeight: 16
}
export const StyledSlider = styled(Slider)(props => {
const { theme:{slider} } = props;
const { width, height, handleWidth, handleExtraHeight } = Object.assign({}, styleParams, props.styleParams || {});
@yairEO
yairEO / clearTimeouts.js
Last active Oct 16, 2018
Clear all browser timeouts
View clearTimeouts.js
(function(_W){
var cache = [], // will store all timeouts IDs
_set = _W.setTimeout, // save original reference
_clear = _W.clearTimeout; // save original reference
// Wrap original setTimeout with a function
_W.setTimeout = function( CB, duration, ...args ){
// also, wrap the callback, so the cache referece will be removed
// when the timerout has reached (fired the callback)
@yairEO
yairEO / jquery.scrollTo.js
Last active Apr 23, 2018
jQuery scroll-to plugin which can smoothly scroll to any position/element
View jquery.scrollTo.js
/**
* Scroll To / jQuery plugin (this plugin is written poorly)
* @author Yair Even Or
* @version 1.0.1 (April 3, 2013)
*/
(function($){
"use strict";
var root = $('html, body');
@yairEO
yairEO / events.namespace.js
Last active Feb 26, 2019
Event Handler Namespace in Vanilla JavaScript
View events.namespace.js
var events = {
on(event, cb, opts){
if( !this.namespaces ) // save the namespaces on the DOM element itself
this.namespaces = {};
this.namespaces[event] = cb;
var options = opts || false;
this.addEventListener( event.split('.')[0], cb, options );
return this;
@yairEO
yairEO / easing.js
Created Oct 17, 2017 — forked from gre/easing.js
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
View easing.js
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: function (t) { return t },
// accelerating from zero velocity
easeInQuad: function (t) { return t*t },
// decelerating to zero velocity
@yairEO
yairEO / jQuery.toggle2classes.js
Created Oct 3, 2017
Toggle between two classes
View jQuery.toggle2classes.js
$.fn.toggle2classes = function(class1, class2){
if( !class1 || !class2 )
return this;
return this.each(function(){
var $elm = $(this);
if( $elm.hasClass(class1) || $elm.hasClass(class2) )
$elm.toggleClass(class1 +' '+ class2);
View jQuery.addTempClass.js
$.fn.addTempClass = function(tempClass, duration){
if( !tempClass )
return this;
return this.each(function(){
var $elm = $(this),
timer;
$elm.addClass(tempClass);
You can’t perform that action at this time.