Skip to content

Instantly share code, notes, and snippets.

@justanotherdot
justanotherdot / type_compatibility.ts
Last active September 6, 2017 22:57
Type compatibility is sometimes no better than a cast.
// Our ideal type.
interface Foo {
readonly a: number;
}
type Section = Foo[];
type Group = Section[];
// Now we start messing with TS.
// `extends` and `optional?` allow us to add almost
// Trigger a timer after an event but do not throw away the initial event.
Observable.of(true)
.repeat()
.switchMap(val => Observable.timer(5000).mapTo(!val).startWith(val));
# Pick a random word from `/usr/share/dict/words'.
cat /usr/share/dict/words | tail -n $(( RANDOM % `wc -l /usr/share/dict/words | cut -f1 -d' '` )) | head -1

Keybase proof

I hereby claim:

  • I am justanotherdot on github.
  • I am justanotherdot (https://keybase.io/justanotherdot) on keybase.
  • I have a public key ASBlyFzHcoI9TxG3TnYwiEAB0Ikp3GHwBN_JLNr1SRpBHQo

To claim this, I am signing this object:

Reading List - 2018

Books

  • Coders at Work
  • Messy
  • Release it!
  • Game Engine Black Book
  • Twelve Steps to a Compassionate Life
  • Writing Without Bullshit
  • Programming Rust
@justanotherdot
justanotherdot / trello_delete_archived_cards.py
Created March 19, 2018 00:28
Batch delete of archived cards with Trello API
import requests
import json
import time
API_KEY = ""
API_TOKEN = ""
table_id = ""
url = "https://api.trello.com/1/boards/{}/cards/closed/?key={}&token={}".format(table_id, API_KEY, API_TOKEN)
#!/usr/bin/env sh
set -eu
version() {
echo "git-wash v0.1.0"
echo
}
usage() {
echo "usage: git wash <branch>"
@justanotherdot
justanotherdot / uuid4.ex
Created April 10, 2018 04:50
Minimal uuid4 implementation
defmodule UUID4 do
@moduledoc """
Rough sketch of a uuid4 implementation
"""
@doc false
def uuid4 do
<<u0::48, _::4, u1::12, _::2, u2::62>> = :crypto.strong_rand_bytes(16)
<<u0::48, 4::4, u1::12, 2::2, u2::62>>
end
@justanotherdot
justanotherdot / exhaustion_check.ts
Created April 23, 2018 01:47
Exhaustivity Checks in TypeScript
// Both TypeScript and Flow can check for this but rely on a hack.
// There is a reliance for a clause where an illegal assignment
// would take place to a value of type `never` or `empty`
// (ts and flow respectively)
type Maybe<T> = { tag: 'Just', payload: T } | { tag: 'Nothing' };
function pure<T>(x: T): Maybe<T> {
return { tag: 'Just', payload: x };
}
const talk = (optText) => {
let text = optText || Array.from(document.querySelectorAll('p')).map(p => p.outerText).join(' ');
let t2s = new SpeechSynthesisUtterance(text);
let voices = window.speechSynthesis.getVoices();
t2s.voice = voices.filter(v => v.name === 'Samantha')[0]; // Samantha is the standard US voice and lives at index 32 when I call this for my browser. Your locale may change this ordering.
t2s.onend = function(e) { console.log('Read in ' + e.elapsedTime + ' seconds'); };
window.speechSynthesis.speak(t2s);
};
// You can stop the output by calling...