Skip to content

Instantly share code, notes, and snippets.


David Philipson dphilipson

View GitHub Profile
dphilipson /
Last active Mar 8, 2022
How to Read Rust

How to Read Rust without Knowing Rust

So you need to read a Rust program and you've never seen rust before?

Rust has a well-earned reputation for being a difficult language because of its strict ownership rules, complex type system, and general assumption that anyone learning it has unlimited time and patience. But there's good news! Just because Rust is hard to write doesn't mean it has to be hard to read.

In fact, once you learn a few basics, you might find that Rust is a fairly easy

dphilipson /
Last active Mar 3, 2021
The Simplest Git

The Simplest Git

A minimal set of commands for using Git to collaborate using pull requests.

Note that this is not the only way to do this, but it is one way that works. If someone says to do something else, they aren't necessarily wrong- it could just be a different means of accomplishing the same thing.

The short version

Check out the latest version of master from GitHub:

View ReactComponentBoilerplate.tsx
import classNames from "classnames";
import React, { memo, ReactElement } from "react";
import "./__NAME__.scss";
interface Props {
className?: string;
const __NAME__ = memo(function __NAME__({ className }: Props): ReactElement {
return (
dphilipson /
Last active Jul 15, 2022
React/TypeScript setup notes

React/TypeScript setup steps

Setting up the environment

  • Run
    yarn create react-app my-app --typescript
    cd my-app
dphilipson / functionArityOptimization.ts
Created Jun 15, 2018
Benchmarks demonstrating interesting properties of optimization around function arity in JavaScript
View functionArityOptimization.ts
import Benchmark from "benchmark";
const array: number[] = [];
for (let i = 0; i < 100000; i++) {
function map<T, U>(arr: T[], f: (item: T) => U): U[] {
const result: U[] = [];
for (let i = 0, { length } = arr; i < length; i++) {
dphilipson / redoodleSagas.ts
Created Feb 28, 2018
Combine redux-saga with Redoodle for marginally better static typing
View redoodleSagas.ts
import { TypedAction, TypedActionString } from "redoodle";
import {
} from "redux-saga/effects";
type HelperFunc0<A> = (action: A) => any;
type HelperFunc1<A, T1> = (arg1: T1, action: A) => any;
dphilipson / dateString.ts
Created Dec 12, 2017
Branded strings that represent dates in TypeScript.
View dateString.ts
enum DateStringBrand {}
export type DateString = string & DateStringBrand;
function of(date: string | number | Date): DateString {
// This branching needed to satisfy TypeScript.
const dateObject =
typeof date === "string"
? new Date(date)
: typeof date === "number" ? new Date(date) : new Date(date);
View SafeMap.ts
// ----- Definition -----
class SafeMap<V> {
private readonly o: { [key: string]: V } = {};
public put(key: string, value: V): void {
this.o[key] = value;
public has<K extends string>(key: K): this is SafeMapWithKey<K, V> {
dphilipson /
Created Apr 26, 2016
Computes expected number of packs required to complete a portion of your collection in Hearthstone
package me.dphil.statistics
import java.util.Random;
import java.util.concurrent.TimeUnit;
* Many people have written this before and many will write it again. I
* wrote it because it was faster than looking for someone else's solution.
public class PackStatistics {