This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const pause = (duration) => new Promise(res => setTimeout(res, duration)); | |
| const retry = (retries, fn) => | |
| fn().catch(err => retries > 1 ? retry(retries - 1, fn) : Promise.reject(err)); | |
| const backoff = (retries, fn, delay = 500) => | |
| fn().catch(err => retries > 1 | |
| ? pause(delay).then(() => backoff(retries - 1, fn, delay * 2)) | |
| : Promise.reject(err)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { transform, isEqual, isObject } from 'lodash'; | |
| /** | |
| * Deep diff between two object, using lodash | |
| * @param {Object} object Object compared | |
| * @param {Object} base Object to compare with | |
| * @return {Object} Return a new object who represent the diff | |
| */ | |
| function difference(object, base) { | |
| return transform(object, (result, value, key) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* ES5, using Bluebird */ | |
| var isMomHappy = true; | |
| // Promise | |
| var willIGetNewPhone = new Promise( | |
| function (resolve, reject) { | |
| if (isMomHappy) { | |
| var phone = { | |
| brand: 'Samsung', | |
| color: 'black' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @mixin transform($property) { | |
| -webkit-transform: $property; | |
| -ms-transform: $property; | |
| transform: $property; | |
| } | |
| .box { @include transform(rotate(30deg)); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function increment(input) { return input + 1;} | |
| function decrement(input) { return input - 1; } | |
| function double(input) { return input * 2; } | |
| function halve(input) { return input / 2; } | |
| var initial_value = 1; | |
| var pipeline = [ | |
| increment, | |
| increment, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Avoid "Cannot read property of undefined" | |
| // https://silvantroxler.ch/2017/avoid-cannot-read-property-of-undefined/ | |
| export function getSafe(fn) { | |
| try { | |
| return fn(); | |
| } catch (e) { | |
| return undefined; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Building-blocks to use for composition | |
| const double = x => x + x; | |
| const triple = x => 3 * x; | |
| const quadruple = x => 4 * x; | |
| // Function composition enabling pipe functionality | |
| const pipe = (...fns) => input => [...fns].reduce((acc, fn) => fn(acc), input); | |
| // Composed functions for multiplication of specific values | |
| const multiply6 = pipe(double, triple); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const scream = str => str.toUpperCase() | |
| const exclaim = str => `${str}!` | |
| const repeat = str => `${str} ${str}` | |
| const string = 'Egghead.io is awesome' | |
| // Nested | |
| const result2 = repeat(exclaim(scream(string))) | |
| // EGGHEAD.IO IS AWESOME! EGGHEAD.IO IS AWESOME! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function RemoveAccents(strAccents) { | |
| var strAccents = strAccents.split(''); | |
| var strAccentsOut = new Array(); | |
| var strAccentsLen = strAccents.length; | |
| var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž'; | |
| var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz"; | |
| for (var y = 0; y < strAccentsLen; y++) { | |
| if (accents.indexOf(strAccents[y]) != -1) { | |
| strAccentsOut[y] = accentsOut.substr(accents.indexOf(strAccents[y]), 1); | |
| } else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Safety First | |
| git branch | grep ‘your_string_here’ | |
| # Delete'em | |
| git branch | grep 'your_string_here' | xargs git branch -D | |
| # Delete Remote too | |
| git branch | grep ‘your_string_here’ | xargs git push origin — delete |