Skip to content

Instantly share code, notes, and snippets.

@laser
laser / blog-adts-di.md
Last active May 12, 2020 09:54
An ADT-Based Alternative to Dependency Injection in TypeScript

Preface

Like unit testing but dislike mocks and stubs? Want to keep your business logic separate from your side effects? In this blog post, I'll demonstrate a novel approach to testing which relies not on the [Dependency Injection][4] pattern, but an algebraic data structure and some simple functions.

A Real World Example

I was recently working on a system for a real estate company which merged a

@laser
laser / stuff.md
Last active December 10, 2019 13:02
stuff

Inputs

Can we (today) vary these values at runtime?

  • window_size_mib (const here)
  • sector_size_gib (const here)
  • !*wrapping_variant (?)
  • drg_parents (const here)
  • expander_parents (const here)
  • graph_name (? - ignore)
@laser
laser / integrate.sh
Last active May 29, 2019 18:55
integrate rust-fil-proofs and go-filecoin
#!/usr/bin/env bash
expected_circle_config_sha256sum="2ea6a7c8f63088b107b6346685866629abdf165f0b457f8856880ea2dcfc63b1"
integration_branch=laser/test-integrations-$(date +%s)
go_filecoin_branch=master
go_filecoin_url=git@github.com:filecoin-project/go-filecoin.git
rust_fil_proofs_branch=master
@laser
laser / notes.md
Last active July 26, 2018 22:40
Erlang/OTP Review - First Meeting

Housekeeping

General rules for making a distributed book club like this not-awful:

  • keep your mic muted unless you're speaking
  • raise your hand if you have something to say and wait for someone to call on you
  • if you're raising your hand and nobody calls on you, type a message into the chat

Chapter 1

@laser
laser / pattern.java
Created July 18, 2018 03:00
pattern matching Java
public abstract class Tree {
// Constructor private so the type is sealed.
private Tree() {}
public abstract <T> T match(Function<Empty, T> a,
Function<Leaf, T> b,
Function<Node, T> c);
public static final class Empty extends Tree {
public <T> T match(Function<Empty, T> a,
@laser
laser / fj.sh
Created July 14, 2018 16:04
fork/join shell
echo ""
echo "$(date "+%T") 'fork' a process..."
# opens the file as input fd 666 before the background job (curl) is started
exec 666< <(curl -s 'http://www.fakeresponse.com/api/?sleep=4')
echo ""
echo "$(date "+%T") 'fork' second process..."
# opens the file as input fd 666 before the background job (curl) is started
exec 777< <(curl -s 'https://cdn.bringatrailer.com/wp-content/uploads/2017/09/59c4506ce4ca8_P6155050-e1506103879707.jpg')
@laser
laser / run-tests-one-file.sh
Last active June 12, 2018 21:05
How to Run All Tests in a Single Go File
go test ./... \
-v \
-run "$(cat commands/foo_test.go \
| grep -oE "^func Test[^(]*" \
| sed -e "s/func //" \
| tr "\n" "|" \
| sed -e "s/|$//")"
@laser
laser / postalcodes.js
Last active June 10, 2018 22:29
postal code regular expressions
var codes = {
"AD": "AD\\d{3}",
"AM": "(37)?\\d{4}",
"AR": "([A-HJ-NP-Z])?\\d{4}([A-Z]{3})?",
"AS": "96799",
"AT": "\\d{4}",
"AU": "\\d{4}",
"AX": "22\\d{3}",
"AZ": "\\d{4}",
"BA": "\\d{5}",

Keybase proof

I hereby claim:

  • I am laser on github.
  • I am lasericus (https://keybase.io/lasericus) on keybase.
  • I have a public key ASC9zkxig-oNF8OP2GS2jTNPEW0GOVoPMIfR0WvR0buulQo

To claim this, I am signing this object:

DHT|peer-id
0|uPody
1|nGjie
2|ur5o2
3|mM69R
4|26R1S
5|jyzxZ
6|wtMS5
7|MDKez
8|t26G5