Skip to content

Instantly share code, notes, and snippets.

View crdueck's full-sized avatar

Chris Dueck crdueck

View GitHub Profile
@crdueck
crdueck / type-family-map.hs
Created December 6, 2020 00:41
Type family inference
{-# LANGUAGE GADTs, TypeFamilies, DataKinds, TypeOperators #-}
import Type.Reflection
type family Map f xs where
Map f '[] = '[]
Map f (x ': xs) = f x ': Map f xs
data HList xs where
HNil :: HList '[]
@crdueck
crdueck / pacman-disowned
Created September 24, 2016 02:26
pacman-disowned
#!/bin/sh
tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$
db=$tmp/db
fs=$tmp/fs
mkdir "$tmp"
trap 'rm -rf "$tmp"' EXIT
pacman -Qlq | sort -u > "$db"
@crdueck
crdueck / dis.sh
Created September 24, 2016 02:24
dis
#!/bin/sh
function dis {
case "$1" in
--stash)
export DIS_STASH_FILE="$(mktemp)"
gdb -batch -ex "disassemble $3" $2 >> $DIS_STASH_FILE
cat $DIS_STASH_FILE
;;
@crdueck
crdueck / donut.py
Last active April 9, 2022 02:41
donut.py
#! /usr/bin/env python3
# Ported from http://www.a1k0n.net/2011/07/20/donut-math.html
# Run with 'python donut.py'
import math
R1 = 1
R2 = 2
K2 = 5
@crdueck
crdueck / Cards.hs
Last active June 24, 2016 21:30
Dominion WIP
{-# LANGUAGE GADTs #-}
import Control.Lens
import Control.Monad.Free
data Action
= Cellar | Chapel | Moat
| Chancellor | Village | Woodcutter | Workshop
| Bureaucrat | Feast | Gardens | Militia | Moneylender | Remodel | Smithy | Spy | Thief | ThroneRoom
| CouncilRoom | Festival | Laboratory | Library | Market | Mine | Witch
! URxvt settings
URxvt.scrollBar: off
!URxvt.font: xft:terminus:size=12:antialias=true
URxvt.intensityStyles: false
URxvt.letterSpace: -1
URxvt.perl-ext-common: default,matcher
URxvt.url-launcher: /usr/bin/firefox
URxvt.matcher.button: 1
! Common
@crdueck
crdueck / jump_consistent_hash.c
Created August 6, 2014 01:35
jump consistent hash
int32_t JumpConsistentHash(uint64_t key, int32_t num_buckets)
{
int64_t b = -1, j = 0;
while (j < num_buckets) {
b = j;
key = key * 2862933555777941757ULL + 1;
j = (b + 1) * (double(1LL << 31) / double((key >> 33) + 1);
}
return b;
}
@crdueck
crdueck / Signal.hs
Last active August 29, 2015 14:01
Signal
import Control.Applicative
import Control.Monad
import Data.Monoid
data SignalT m a
= Skip (m (SignalT m a))
| Emit a (m (SignalT m a))
instance Monad m => Functor (SignalT m) where
fmap f = go
@crdueck
crdueck / Par.hs
Created April 6, 2014 18:45
Self optimizing Par Arrow
{-# LANGUAGE Arrows, GADTs #-}
data Par a b where
Pure :: (a -> b) -> Par a b
Seq :: Par a b -> Par b c -> Par a c
Par :: (a -> (a1, a2)) -> Par a1 b1 -> Par a2 b2 -> ((b1, b2) -> b) -> Par a b
instance Category Par where
id = Pure id
@crdueck
crdueck / Actor.hs
Created November 26, 2013 13:08
actors in haskell
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverlappingInstances #-}
import Control.Applicative
import Control.Concurrent
import Control.Concurrent.STM
import Data.Dynamic
import Data.Monoid
import Data.Word
import qualified Data.Foldable as F