Skip to content

Instantly share code, notes, and snippets.

@jmitchell
jmitchell / protobuf_regenerate.sh
Created May 10, 2019 20:15
Regenerate Elixir modules from protobuf schema at the specified URL. Depends on nix package manager.
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p elixir_1_8 erlang protobuf curl
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.03.tar.gz
## Adapted from directions at https://github.com/tony612/protobuf-elixir
# lives at ./script/protobuf_regenerate.sh
set -ex
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p autoreconfHook python3 ncurses "(with haskellPackages; [ alex happy hscolour ])" "(with python36Packages; [ sphinx ])"
set -ex
REV=838aeb9b254efb3df7ed0cedeb945ec7c7789c90
BUILD_FLAVOUR=validate
THREADS=7
SKIP_PERF_TESTS=YES
VERBOSE=2
Hi Matt
@jmitchell
jmitchell / TestFrameworkDemo.hs
Last active June 9, 2018 22:55
Avoid function argument ordering bugs by using the type system
{-
At the recent Seattle Haskell Learners' Group we touched on a common
programming bug, namely when a programmer mistakenly passes arguments
to a function in the wrong order. Let's consider an example of this
bug and ways to avoid it in Haskell.
Automated tests frequently need a mechanism to say, "the actual
computed value should equal some expected value." When the two values
differ the test framework should produce a useful message like,
@jmitchell
jmitchell / Chess.dhall
Last active April 4, 2018 21:04
WIP: Chess in Dhall
let List/replicate = https://ipfs.io/ipfs/QmQ8w5PLcsNz56dMvRtq54vbuPe9cNnCCUXAQp6xLc6Ccx/Prelude/List/replicate in
let File = Natural in
let Rank = Natural in
let Square = { file : File, rank : Rank } in
let Move = { from : Square, to : Square } in
let Side = < white : {} | black : {} > in
let white = < white = {=} | black : {} > in
let black = < black = {=} | white : {} > in
@jmitchell
jmitchell / ipfs-test.sh
Created January 1, 2018 00:06
Test IPFS read-what-you-write latency by adding a new uuid to the network and timing how long it takes to read it
#!/usr/bin/env bash
hash=`uuidgen -r | ipfs add -q`
url="https://ipfs.io/ipfs/$hash"
time curl "$url"
echo $url
@jmitchell
jmitchell / Classy.hs
Last active December 27, 2017 00:29
Next Level MTL
-- TH expansions of `makeClassy` and `makeClassyPrisms`
data DbConfig = DbConfig
{ _dbConn :: DbConnection
, _dbSchema :: Schema
}
makeClassy ''DbConfig
{-
class HasDbConfig t where

Keybase proof

I hereby claim:

  • I am jmitchell on github.
  • I am jmitchell (https://keybase.io/jmitchell) on keybase.
  • I have a public key whose fingerprint is 51EC DFAF 4AA3 1F42 A647 B8E3 E5A4 0FFC 0760 68CC

To claim this, I am signing this object:

@jmitchell
jmitchell / SetMap.idr
Created September 16, 2017 21:16
Key-value mapping in Idris where set of keys that have values is encoded in the type
import Data.List
data SetMap : List k -> Type -> Type where
Empty : SetMap [] _
Insert : DecEq k =>
(key : k) ->
v ->
SetMap keys v ->
{auto prf : isElem key keys = No _} ->
SetMap (key :: keys) v
@jmitchell
jmitchell / Makefile
Last active September 11, 2017 05:09
Call C from x86-64 assembly
main: main.o hello.o
gcc -o main main.o hello.o
main.o: main.asm
nasm -felf64 -o main.o main.asm
hello.o: hello.c
gcc -c -o hello.o hello.c
.PHONY: clean