Option<T> |
non-Option (T | undefined ) |
|
---|---|---|
accessing property | userOption.map(user => user.age) |
userNullish?.age |
calling a method | userOption.map(user => user.fn()) |
userNullish?.fn() |
providing fallback | ageOption.getOrElse(0) |
ageNullish ?? 0 |
filter | ageOption.filter(checkIsOddNumber) |
`ageNull |
#!/bin/bash | |
# Description: | |
# Delete all `greenkeeper/*` branches of your remote. | |
# Instructions: | |
# Run the script with the `--help` flag. | |
ORIGIN=origin | |
DRY_RUN=0 | |
THIS=`basename "$0"` |
- Sync/async generator forms
- Not constant, can be reassigned
- Hoisting can result in runtime exceptions (https://twitter.com/OliverJAsh/status/1247240674388447234)
Short link to this page: http://caseywatts.com/ptt
Other gists & tricks: http://caseywatts.com/gists-and-tricks
Unrelated update: my book is out! Debugging Your Brain is an applied psychology / self-help book
- Save this bookmarklet. Right-click on boomarks toolbar
Add Page...
- Name:
PTT
(push to talk) or whatever you'd like (maybe short so it stays on your bookmarks toolbar)
const Range = (a, b) => Array.from({ length: b - a }, (_, i) => a + i) | |
const NumTest = (n, text) => k => !(k % n) ? text : '' | |
const Tests = data => Object.entries(data).map(([n, text]) => NumTest(n, text)) | |
const RangeTest = tests => n => tests.map(fn => fn(n)).join('') || n | |
const RangeMap = (a, b, tests) => Range(a, b).map(RangeTest(tests)) | |
const fizzBuzz = (a, b) => RangeMap(a, b, Tests({ | |
5: 'Fizz', | |
3: 'Buzz', | |
})) |
Windows Registry Editor Version 5.00 | |
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout] | |
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,64,00,3a,00,00,00,00,00 | |
https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff
While attempting to explain JavaScript's reduce
method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.
JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List
is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu
#!/bin/bash | |
cd "$(git rev-parse --show-toplevel)" | |
ESLINT="node_modules/.bin/eslint" | |
pwd | |
if [[ ! -x "$ESLINT" ]]; then | |
printf "\t\033[41mPlease install ESlint\033[0m (npm install eslint)\n" | |
exit 1 | |
fi |
var flatten = (a, r, cb) => { | |
if (typeof a.length === 'undefined') { | |
r.push(a); | |
return cb; | |
} else if (a.length === 0) { | |
return cb; | |
} else { | |
return flatten(a[0], r, () => flatten(a.slice(1), r, cb)); | |
} | |
}; |