This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TemplateHaskell #-} | |
module ElmDerive where | |
import Language.Haskell.TH | |
makeElm :: Name -> Q [Dec] | |
makeElm t = do | |
-- Get list of constructors for type t | |
TyConI (DataD _ _ _ constructors _) <- reify t | |
x <- [d| x = "hi" |] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
region = "eu-west-1"; | |
in | |
{ | |
resources.ec2KeyPairs.waw-pair = { inherit region; }; | |
resources.ec2SecurityGroups.http-ssh = { | |
inherit region; | |
rules = [ | |
{ fromPort = 22; toPort = 22; sourceIp = "0.0.0.0/0"; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import collections | |
# Generic n-ary tree | |
RoseTree = collections.namedtuple('RoseTree', 'a children') | |
def gen_int(): | |
def _gen_int(rng, size): | |
return rng.randrange(0, size) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pycosat | |
import numpy | |
import itertools | |
WORLDS_HARDEST_RIDDLE_ACCORDING_TO_TELEGRAPH = """\ | |
8........ | |
..36..... | |
.7..9.2.. | |
.5...7... | |
....457.. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random, turtle | |
def maze(w=10, h=10): | |
# This is the random spanning tree implementation | |
seen = set() | |
# Add some walls to confine the maze | |
for i in xrange(-1, w+1): | |
seen.add((i, -1)) | |
seen.add((i, h+1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dbus | |
bus = dbus.SystemBus() | |
NM = 'org.freedesktop.NetworkManager' | |
def get_manager(): | |
proxy = bus.get_object(NM, '/org/freedesktop/NetworkManager') | |
return dbus.Interface( | |
proxy, NM) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
MODEL = """\ | |
53..7.... | |
6..195... | |
.98....6. | |
8...6...3 | |
4..8.3..1 | |
7...2...6 | |
.6....28. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment | |
import Data.Array.Repa as R | |
import Data.Array.Repa.Algorithms.Randomish as RR | |
import Criterion.Main | |
import Criterion.Config | |
ra = RR.randomishDoubleArray (ix2 1000 3) 0 1 1 | |
main = defaultMainWith defaultConfig {cfgSamples = ljust 10} (return ()) [ | |
bgroup "pairwise-random" [ |