Skip to content

Instantly share code, notes, and snippets.

@lkchoi
lkchoi / first-resolved.js
Created August 13, 2018 18:42
Util function to return the result of the first Promise to resolve
function firstResolved (promises) {
// https://stackoverflow.com/a/37235274
// This is a classic example where inverting your logic makes it much clearer.
// Your "race" in this case is that you want your rejection behavior to in
// fact be success behavior.
// If a request fails, count that as a resolution so it will keep waiting
// for other possible successes. If a request succeeds, treat it as a
// rejection so Promise.all immediately bails out.
promises = promises.map(p => p.then(
@lkchoi
lkchoi / flex.css
Last active September 22, 2018 13:48
css flexbox helper classes
/* container */
.flex { display: flex; }
/* direction */
.flex-col { flex-direction: column; }
.flex-row { flex-direction: row; }
.flex-col-r { flex-direction: column-reverse; }
.flex-row-r { flex-direction: row-reverse; }
/* wrap */
@lkchoi
lkchoi / spacing.css
Last active May 11, 2018 01:57 — forked from barmmie/gist:3b71786b48dd3b5043de
Padding And Margin CSS Helper
.m-xs { margin: 5px; }
.m-sm { margin: 10px; }
.m { margin: 15px; }
.m-md { margin: 20px; }
.m-lg { margin: 30px; }
.m-n { margin: 0; }
.m-l-none { margin-left: 0; }
.m-l-xs { margin-left: 5px; }
.m-l-sm { margin-left: 10px; }
.m-l { margin-left: 15px; }
@lkchoi
lkchoi / Add Line in Square Braces.sublime-macro
Last active July 22, 2016 23:50
Auto-indent when Enter is pressed between "[]" (square braces)
[
{"command": "insert", "args": {"characters": "\n\n"} },
{"command": "move", "args": {"by": "lines", "forward": false} },
{"command": "move_to", "args": {"to": "hardeol", "extend": false} },
{"command": "reindent", "args": {"single_line": true} },
{"command": "insert", "args": {"characters": "\t"} }
]