Skip to content

Instantly share code, notes, and snippets.

View coffee-mug's full-sized avatar

Lucas Kostka coffee-mug

View GitHub Profile
@coffee-mug
coffee-mug / chainPromises.js
Created March 15, 2018 14:04
Chain promises in JS
// Promises, the big deal
// Here's a, a small function that returns a promise,
// which resolves itself at a random time between 0 and 1/2s, returning "My question num"
var a = (num) => {
return new Promise( (res, rej) => {
// return "My question num" between immediately and 1/2 s.
return setTimeout( () => res(`My question ${num}`), 500 * Math.random())
})
}
@coffee-mug
coffee-mug / hn_sorter.js
Created June 21, 2017 13:24
Script to sort HN links by comments count
/** Script to sort HN comments by post date **/
var itemsArray = [],
tb = document.querySelectorAll('table.itemlist > tbody > tr');
function sortBycom(a, b) {
var left = a[1].querySelector('td.subtext > a:last-child'),
right = b[1].querySelector('td.subtext > a:last-child');
// If no comments has been made yet, push them at the end