Skip to content

Instantly share code, notes, and snippets.

View dyerw's full-sized avatar
πŸ¦‘
still squiddin' after all these years

Liam Dyer dyerw

πŸ¦‘
still squiddin' after all these years
  • Chicago, IL
View GitHub Profile
@dyerw
dyerw / monads.ts
Last active March 11, 2025 21:01
First part of Wadler's "Monads for funtional programming" translated to TypeScript
// Monads for functional programming in TypeScript
// Here's a basic evaluator
type Term =
| { tag: 'Con', n: number }
| { tag: 'Div', arg1: Term, arg2: Term }
const con = (n: number): Term => ({ tag: 'Con', n });
const div = (arg1: Term, arg2: Term): Term => ({ tag: 'Div', arg1, arg2 });
@dyerw
dyerw / reselect.js
Last active August 18, 2021 21:06
Anti-Reselect Manifesto
// From https://react-redux.js.org/api/hooks#using-memoizing-selectors
import { createSelector } from 'reselect'
// A Selector is just a fn from State to T
type Selector<T> = (state: State) => T;
const selectCompletedTodosCount = createSelector( // This utility does nothing you can't do easily without it
(state) => state.todos,
(_, completed) => completed, // Why would we do this? This is just a roundabout way of parameterizing a fn.
curl https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/shakespeare.txt | say
@dyerw
dyerw / typelevel-fizzbuzz.ts
Created May 4, 2021 03:45
TS Type-level Fizzbuzz
type Count<A, S extends 0[] = []> = A extends S["length"]
? S
: Count<A, [...S, 0]>;
type IncC<A> = [...Count<A>, 0];
type DecC<A> = Count<A> extends [infer _H, ...(infer R)] ? R : [];
// Basic Arithmetic
type Inc<A> = IncC<A>["length"];
type Dec<A> = DecC<A>["length"];
import * as t from "io-ts";
import * as R from "fp-ts/lib/Record";
type AvroStringSchema = "string";
type AvroNullSchema = "null";
type AvroFieldSchema = { name: string; type: AvroSchema };
type AvroRecordSchema = {
type: "record";
namespace: string;
name: string;
@dyerw
dyerw / avro-to-ts.ts
Created June 18, 2020 21:55
Play with generating TS Interfaces from Avro Schemas
import * as ts from "typescript";
// Haven't dealt with arrays and records
type AvscType = "string" | "int" | "null";
type TsTypes =
| ts.SyntaxKind.StringKeyword
| ts.SyntaxKind.NumberKeyword
| ts.SyntaxKind.NullKeyword;
interface AvscField {
function fish_prompt
test $SSH_TTY; and printf (set_color red)(whoami)(set_color white)'@'(set_color yellow)(hostname)' '
test $USER = 'root'; and echo (set_color red)"#"
# Main
echo -n (set_color cyan)(prompt_pwd)(set_color purple)(__fish_vcs_prompt) (set_color red)'❯'(set_color yellow)'❯'(set_color green)'❯ '
end
@dyerw
dyerw / hearthpwnscrape.py
Created November 4, 2015 23:01
Scrapes hearthpwn.com for decklist data
import urllib2
from bs4 import BeautifulSoup
PAGES_TO_SCRAPE = 10
# Get HTML for all deck listing pages
htmls = []
for x in range(PAGES_TO_SCRAPE):
print "SCRAPING PAGE " + str(x + 1)
@dyerw
dyerw / alias.sh
Last active August 29, 2015 14:18
Git - Aliases
git config --global alias.history "log --follow --stat"
@dyerw
dyerw / assetcleaner.py
Last active February 28, 2024 05:09
AssetCleaner - Removes all unused assets from an XCode project
USAGE = \
"""
Searches an XCode project to determine which image
assets aren't being used then removes them.
WARNING: This will delete things permanently if your
project is not under source control.
"""
import os