This file contains 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
"use strict" | |
// promise constructor and methods | |
function P (callback) { | |
let status | |
let value | |
const thens = [] | |
const catches = [] | |
setTimeout(() => callback( | |
data => (status = "resolved", value = processData(data, thens)), | |
error => (status = "rejected", value = processData(error, catches)) |
This file contains 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
"use strict" | |
// race all promises once and resolve with the first resolved promise or reject with the last error. | |
function raceWithTimeout (promiseList) { | |
const TIMEOUT = 50 | |
return Promise.race([ | |
...promiseList.map(suppressReject), // if any resolve, resolve with that result. | |
lastRejectionWithTimeout(promiseList, TIMEOUT) // if all reject, reject with last error; if timeout, reject with latest error. | |
]) | |
} |
This file contains 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 dedup = list => list.reduce((uniques, item) => uniques.concat(uniques.includes(item) ? [] : [item]), []) | |
dedup(["a",2,"a",3,"b",2]) // ["a", 2, 3, "b"] |
This file contains 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
// point-free version | |
function combos (obj) { | |
return Object.keys(obj).reduce((results, key) => (Array.isArray(obj[key]) ? obj[key] : [obj[key]]).map(value => results.map(result => Object.assign({}, result, {[key]: value}))).reduce((flattened, list) => [...flattened, ...list]), [{}]) | |
} | |
test(combos({x: 1, y: [2, 3]}), [{x: 1, y: 2}, {x: 1, y: 3}]) | |
test(combos({x: [1, 2], y: 3}), [{x: 1, y: 3}, {x: 2, y: 3}]) | |
test(combos({x: [1, 2], y: [4, 5], z: 7}), [{x: 1, y: 4, z: 7}, {x: 2, y: 4, z: 7}, {x: 1, y: 5, z: 7}, {x: 2, y: 5, z: 7}]) | |
test(combos({x: [1, 2], y: [4, 5]}), [{x: 1, y: 4}, {x: 2, y: 4}, {x: 1, y: 5}, {x: 2, y: 5}]) | |
test(combos({x: [1, 2, 3], y: [4, 5]}), [ |
This file contains 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
// // Try it here: https://www.w3schools.com/HTML/html5_draganddrop.asp | |
// var dragElem = document.querySelector("#drag1") | |
// var dropElem = document.querySelector("#div2") | |
// simulateDragDrop(dragElem, dropElem) | |
function simulateDragDrop (dragElem, dropElem) { | |
var event = createEvent("dragstart") | |
dispatchEvent(dragElem, "dragstart", event) | |
var dropEvent = createEvent("drop") | |
dropEvent.dataTransfer = event.dataTransfer |
This file contains 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
"use strict" | |
// CONFIG | |
const ZENHUB_TOKEN = "GET IT FROM ZENHUB" | |
const GITHUB_TOKEN= "GET IT FROM GITHUB" | |
const ORG_NAME = "GITHUB ORG NAME" | |
const REPO_NAME = "REPO NAME" | |
// IMPORTS | |
const req = require("request-promise-native") | |
const moment = require("moment") |
This file contains 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
"use strict" | |
console.log("––– Con –––") | |
function Con () { | |
let privateData = 123 | |
private_makeMethodsPublic(this, [public_connect]) | |
function public_connect (username, password) { | |
privateData = username + password | |
} |
This file contains 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
git hist master.. | |
# last commit is abc1234 | |
# -Xtheirs resolves merge conflicts in favor of them (current branch) | |
git rebase -i abc1234^ -Xtheirs | |
# in vim: | |
# cwr[escape] | |
# :%s/^pick /squash /gc[enter] | |
# :wq[enter] | |
# Also worth noting to get a single commit with diff between |
This file contains 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
window.location.search.slice(1).match(/([^=&;]+)[=;]([^?=&;]*)/g).reduce((obj,kv)=>(obj[kv.split("=")[0].slice(1)]=kv.split("=")[1],obj),{}) |
This file contains 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
git co master && git branch -D master-backup ; git co -b master-backup && git co master | |
ls -ra db/ | grep -E '\.![0-9]+\!' # should return no results | |
cat known/location/of/secret | grep secret # should return results | |
LC_CTYPE=C && LANG=C && git filter-branch --tree-filter "find . -type f -exec sed -i '' -e 's/secret/replacement/g' {} \;" -f | |
ls -ra db/ | grep -E '\.![0-9]+\!' # should return no results | |
cat known/location/of/secret | grep secret # should return no results | |
git filter-branch --tree-filter "grep -r 'secret' * || true" | |
git push -f origin master |