Skip to content

Instantly share code, notes, and snippets.

View gist:6c79fd8ca3c560bf1caa
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)
View basic example
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"; }
View ElmDerive.hs
{-# 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" |]
View monad-control.nix
with (import <nixpkgs> {}).pkgs;
let monad-control = pkgs.haskellngPackages.callPackage ./monad-control-0.3.nix {};
pkg = haskellngPackages.callPackage
({ mkDerivation, base, monad-control, stdenv, yesod }:
mkDerivation {
pname = "yesod-nix";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
View quickcheck.hs
module Main where
import Python
import Test.QuickCheck
import Test.QuickCheck.Monadic
square :: Int -> IO Int
square = defVV "export = lambda x: x * x"
View deps.nix
with (import <nixpkgs> {}).pkgs;
let
importDeps = stdenv.mkDerivation {
name = "importDeps";
src = fetchurl {
url = "file:///home/tom/testbed/nix-import-stuff/ext.zip";
sha256 = "0ivhsn2pp1sgzsywnd2x673ff5q62v9715kkw5vyf63rfh7fw9h4";
};
phases = "unpackPhase installPhase";
View config.md

Backwards compatible configuration

If some record can change it's a good idea to use a sum type, e.g. you start out with your new program like this:

data Wibble = WibbleV0 { port :: Int, name :: String }

A year later you have a new feature that requires more info. Now you

View json flatten.py
def get_records():
df = pandas.read_json('1.json')
df = pandas.io.json.json_normalize(df['accidents'])
for _, row in df.iterrows():
for c in row['casualties']:
for i in row['involved']:
row['caualty_severity'] = c['severity']
row['caualty_gender'] = c['gender']
row['caualty_class'] = c['class']
row['caualty_vehicle'] = c.get('vehicle', 'unknonwn')
View ipython3.nix
{ stdenv, fetchurl, buildPythonPackage, pythonPackages, zeromq3, pyqt4 ? null
, notebookSupport ? true # ipython notebook
, qtconsoleSupport ? true # ipython qtconsole
, pylabSupport ? true # ipython --pylab (backend: agg - no gui, just file)
, pylabQtSupport ? true # ipython --pylab=qt (backend: Qt4Agg - plot to window)
}:
# ipython qtconsole works with both pyside and pyqt4. But ipython --pylab=qt
# only works with pyqt4 (at least this is true for ipython 0.13.1). So just use
# pyqt4 for both.
@teh
teh / puzzle
Last active Aug 29, 2015
puzzle
View puzzle
include "globals.mzn";
set of 1..5: a = 1..5; % Nicola, Ed, David, Nick, Nigel
set of 1..5: b = 1..5; % Guinea, Squirrel, Pitbull, Badger, Fish
set of 1..5: c = 1..5; % Moccachino, FlatWhite, Chai, Double Espresso, Decaf
set of 1..5: d = 1..5; % Car, Bike, Train, Plane, Walk
set of 1..5: e = 1..5; % Tartan, Paisly, Gingham, Striped, Polka
array[a] of var a: A;
array[b] of var b: B;