Skip to content

Instantly share code, notes, and snippets.

View jml's full-sized avatar

Jonathan Lange jml

View GitHub Profile
@jml
jml / UserAPI.hs
Last active October 10, 2015 16:20
-- Copyright (c) 2015 Jonathan M. Lange <jml@mumak.net>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
@jml
jml / strategies.py
Created October 10, 2015 14:16
nice graph tests
"""
Hypothesis strategies for testing ClusterHQ jira tools.
"""
import random
import networkx
from hypothesis.strategies import (
dictionaries,
def _flatten_graph_dict(d):
"""Map k [v] -> [(k, v)]"""
for k in d:
for v in d[k]:
yield (k, v)
# More complex arbitrary digraphs, where the nodes are integers, and each edge
# has a dictionary of text to text as metadata.
@jml
jml / breakfast.ipynb
Last active September 19, 2015 12:32
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jml
jml / adv.ipynb
Created September 17, 2015 07:44
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jml
jml / wtf
Created September 2, 2015 13:45
python 3.3 + pyrsistent
(Pdb) new_dict
pmap({'': '\x16)\x16\x11\x12\x16\x12\x16)\x06\x06\x11\x06\x11\x16\x12)\x12)\x06\x06)\x12\x12\x16)\x16\x12)\x12\x11\x11\x11\x12\x11\x11\x12\x06\x06', 'Zı': ')\x11\x12\x12\x06\x06\x12)))\x12\x06)\x16\x11\x11\x06\x11\x12\x16\x11\x06\x11\x16\x16', 'task_level': pvector([47, 633, 484, 681, 219, 27, 402, 525, 1812, 470, 523, 1]), 'MZMÖZ#ÖÖ': ')\x12\x11\x16\x06\x12\x11\x16\x06)\x11\x12)\x11\x12\x06\x06\x11\x12\x12\x06\x11)\x16\x11\x06\x16\x16\x11\x06))\x12)\x12\x16\x11\x12\x06\x11\x06\x12)\x06\x06))\x11\x06\x06\x12\x12)\x16\x12))', 'reason': 'Éo\t\tÉ\toÉ\toÉÉÉ\tooo\t\t\tÉoÉoÉoooo\t\t\tÉ', '<': ')\x06\x12\x16\x06\x06)\x16)\x12\x12\x16\x11\x06\x11\x12\x06)\x16\x06\x12\x12\x11\x06\x12\x16)\x12\x06\x11\x06\x16\x11\x16', '<ZÝııÝ': ')\x16\x16\x12\x06\x12))\x11\x11\x16\x16)\x11)\x06\x16)\x12\x16\x16)\x11\x11\x16\x12)', 'ÖıÝıZ##ıÝÖ#': '\x06\x06))\x11\x16\x11\x06\x16\x06\x11\x06\x11\x16\x16\x11\x12\x11\x11', 'action_status': 'failed', '#': ')\x06)\x06\x11\x16\x16\x12', 'exception': '¶q3\ng\x8aāG\x17¶¹GGXāĕ\x8a
addToKey :: Ord k => k -> a -> Map k [a] -> Map k [a]
addToKey key value =
M.alter f key
where f Nothing = Just [value]
f (Just values) = Just (value:values)
def orderable(*attributes):
def wrap(cl):
cl = _add_cmp(cl, attrs=attributes)
return cl
return wrap
def _attrs_to_tuple(obj, attrs):
"""
Create a tuple of values of *obj*'s *attributes*.
{ mkDerivation, base, bytestring, containers, directory, hspec, mtl
, optparse-applicative, parsec, QuickCheck, rainbow, regex-compat
, stdenv, text, time, transformers, unix, vector, yaml
}:
mkDerivation {
pname = "hodor";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
@jml
jml / popper.hs
Created June 2, 2015 18:01
Transform State computation to IO
import Control.Monad.State
import Data.IORef
pop :: State [a] a
pop = do
x:xs <- get
put xs
return x