Skip to content

Instantly share code, notes, and snippets.

@teh
teh / typeapp.hs
Last active September 29, 2016 12:14
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds, PolyKinds, TypeOperators #-}
{-# LANGUAGE TypeFamilies, FlexibleInstances #-}
{-# LANGUAGE InstanceSigs #-}
-- When do I need TypeApplication?
-- When I need some intermediate types that change how
@teh
teh / stack.py
Last active August 24, 2016 14:10
#!/usr/bin/env python
"""
Welcome to Tom-does-another-disgusting-hack.
This is an executable shim for the stack binary whose only purpose is
to make the amazing intero mode [1] work in a non-stack environment (Nix
in our case).
Dump it somewhere and make sure it runs *instead* of the actual stack binary.
You will not be able to use stack at the same time.
import sklearn.base as base
import sklearn.linear_model as lm
import numpy
class ByThreshold(base.BaseEstimator, base.ClassifierMixin):
def __init__(self, estimator, threshold=0.95):
self.threshold = threshold
self.estimator = estimator
#!/usr/bin/env python
import sys
import time
import os
import subprocess
def main():
if sys.argv[1:] == ["path", "--project-root", "--verbosity", "silent"]:
print "/home/tom/src/intero"
@teh
teh / gist:c195cedccabcf54733e6bd0436b83c07
Created August 2, 2016 10:05
How to diff a nixops state file
$ cat .git/config
...
[diff "nixops"]
textconv = nixops export -s
$ cat .gitattributes
production/secrets/**/* filter=git-crypt diff=nixops
{%- extends 'full.tpl' -%}
{%- block input_group -%}
{%- endblock input_group -%}
{ fetchurl, stdenv }:
stdenv.mkDerivation rec {
name = "pies-1.2";
src = fetchurl {
url = "mirror://gnu/pies/${name}.tar.bz2";
sha256 = "18w0dbg77i56cx1bwa789w0qi3l4xkkbascxcv2b6gbm0zmjg1g6";
};
@teh
teh / wagner_fisher.py
Created January 18, 2016 12:26
wagner-fisher in numba
import numpy
import timeit
import numba
@numba.autojit(locals=dict(
best_k=numba.int64,
pos=numba.int64,
ins_del_count=numba.int64,
i=numba.int64,
j=numba.int64,
@teh
teh / n_queens.py
Created October 5, 2013 18:04
Solve n-queens with pycosat.
# Solve n-queens problem with picosat
import pycosat
import numpy
import itertools
def get_cnf(N):
cnf = []
# * convert to object because pycosat expects 'int's
# * add 1 because 0 is reserved in pycosat
@teh
teh / grind_coarseness.py
Created June 8, 2013 14:39
Measure average grind coarseness from a picture.
from PIL import Image
import numpy
from skimage.filter import sobel
from skimage.morphology import watershed
from scipy import ndimage as nd
grind = numpy.asarray(Image.open('grind.png')).mean(axis=2)
edges = sobel(grind)
markers = numpy.zeros_like(grind)