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
export type Callback<T> = (value: T) => void; | |
export type Unsubscribe = () => void; | |
export default class Callbacks<T> { | |
private callbacks = new Set<Callback<T>>(); | |
subscribe(callback: Callback<T>): Unsubscribe { | |
this.callbacks.add(callback); | |
return () => this.unsubscribe(callback); | |
} |
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
type Timestamp = number; | |
type Callback = (error: Error | null, timestamp: Timestamp) => void; | |
/** | |
* The default number of milliseconds beyond the expected time of execution to | |
* wait before assuming failure. | |
*/ | |
const THRESHOLD = 10000; | |
/** |
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 Events = new Map(); | |
function startEvent() { | |
return { | |
start: Date.now(), | |
end: null, | |
}; | |
} | |
function endEvent(event) { |
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
function reversebinary (n) { | |
return parseInt(n.toString(2).split('').reverse().join(''), 2); | |
} |
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
// Found at https://www.glassdoor.com/Interview/Reddit-Senior-Software-Engineer-Interview-Questions-EI_IE796358.0,6_KO7,31.htm | |
// # a list of strings.Each string is a management / report relationship. | |
// # | |
// # EXAMPLE INPUT: | |
// # | |
// #[ | |
// # 'B,E,F', | |
// # 'A,B,C,D', | |
// # 'D,G,I', |
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
1. Create a bookmark with the code snippet as the URL. | |
2. Add it to your bookmarks bar. | |
3. On any FB page, click the bookmarklet to activate. (Your friends page is a good place to start!) | |
Now, when you move your cursor over names and icons a remove button should appear. Click the button, wait a second and that friend is no longer yours. |
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
function normalizeIndex (index, length) { | |
return (length + (index % length)) % length; | |
} |
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
function reduceRot13Cipher(map, c, i, abc) { | |
const off = 13; | |
const len = abc.length; | |
const j = (i + off) % len; | |
map[c] = abc[j]; | |
return map; | |
} | |
const rot13 = (() => { | |
const abc = 'abcdefghijklmnopqrstuvwxyz'; |
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
javascript:void !function(e,t,n,r,i,s){while(n--&&(i=t[n])>e);s=r.style,s.position="fixed",s.zIndex=-1>>>1,s.top=s.left="50%",s.marginTop=s.marginLeft=i/-2+"px",r.src="http://chart.apis.google.com/chart?cht=qr&chld=H|0&chs="+i+"x"+i+"&chl="+escape(location)}(Math.min(top.innerHeight,top.innerWidth),[100,150,200,250,300,350,400,500],8,document.body.appendChild(new Image)) |
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
function buildList(values) { | |
return values.reduceRight((next, value) => ({ value, next }), null); | |
} | |
function getValues(node) { | |
const values = []; | |
while (node) { | |
values.push(node.value); | |
node = node.next; | |
} |