Skip to content

Instantly share code, notes, and snippets.

vsync yairEO

Block or report user

Report or block yairEO

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@yairEO
yairEO / consoleLogEmphasize.js
Last active May 28, 2019
console.log emphasize first arg
View consoleLogEmphasize.js
console.log = ((_c) => (...args) => args.length > 1 ? _c("%c "+ args[0], 'background:indianred; color:white; border-radius:3px; padding:1px;', ...args.slice(1)) : _c(...args))(console.log);
@yairEO
yairEO / string_parts.js
Created May 25, 2019
Get parts of string between certain characters
View string_parts.js
var s = "@cartman ,[[kyle]] do not know:[[homer simpson]]";
var collect = false;
var t;
for( let i = 0; i < s.length; i++ ){
if( s[i] == '[' && s[i] == s[i+1]){
collect = true;
i = i + 1;
continue;
}
@yairEO
yairEO / memo.js
Created Apr 21, 2019
simple memoize
View memo.js
var foo = (memo => ()=> {
// if the function was already computed, return the computed value
if(memo) return memo;
// continue with regular logic and set "memo" to the output value for later calls
memo = 1;
return memo;
})()
@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 Jun 14, 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;
You can’t perform that action at this time.