Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
OliverJAsh / foo.md
Last active September 4, 2023 15:31
`Option` vs non-`Option`

Option vs non-Option

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
@shazron
shazron / delete_all_greenkeeper_branches.sh
Last active April 8, 2021 13:44
Delete all Greenkeeper branches
#!/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"`
@OliverJAsh
OliverJAsh / foo.md
Last active May 31, 2021 07:25
JavaScript function declarations vs. expressions
@caseywatts
caseywatts / 0 push to talk.md
Last active September 21, 2023 13:55
Push To Talk - Google Meet Bookmarklet

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

Push To Talk in a Google Hangout (Meet)

  1. 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)
@slikts
slikts / fizzBuzz.js
Last active December 5, 2018 11:33
Enterprise edition
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',
}))
@zkxs
zkxs / map_capslock_to_f13.reg
Created December 22, 2016 18:28
Windows registry patch to use CAPSLOCK as F13
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
@ljharb
ljharb / array_iteration_thoughts.md
Last active May 22, 2024 09:22
Array iteration methods summarized

Array Iteration

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.

Intro

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

Comparison of Typescript and Flow

Common Features

  • Lots of type inference

  • Null/undefined checking

Similar syntax
@broofa
broofa / pre-commit
Last active February 23, 2024 08:55
Git pre-commit hook that runs `eslint` with the `--fix` option to fix up issues where possible, and adds "fix"ed files into the commit
#!/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));
}
};