Skip to content

Instantly share code, notes, and snippets.

View sethdavis512's full-sized avatar
🤖

Seth Davis sethdavis512

🤖
View GitHub Profile
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));
@sethdavis512
sethdavis512 / diffObjects.js
Created October 11, 2018 17:01
Lodash Diff Objects
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) => {
/* ES5, using Bluebird */
var isMomHappy = true;
// Promise
var willIGetNewPhone = new Promise(
function (resolve, reject) {
if (isMomHappy) {
var phone = {
brand: 'Samsung',
color: 'black'
@mixin transform($property) {
-webkit-transform: $property;
-ms-transform: $property;
transform: $property;
}
.box { @include transform(rotate(30deg)); }
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,
// 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;
}
}
// 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);
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!
@sethdavis512
sethdavis512 / replace-char.js
Last active August 4, 2022 06:33 — forked from alisterlf/gist:3490957
Remove Accents
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
# 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