Skip to content

Instantly share code, notes, and snippets.

Michael Blume MichaelBlume

View GitHub Profile
MichaelBlume / gist:3921530
Created Oct 20, 2012
Transformations on JSON schemas. Also strictness.
View gist:3921530
def rec_schema_transform(transform):
def recur(schema):
if not isinstance(schema, dict):
for k, v in schema.items():
if k in ("properties", "patternProperties", "dependencies"):
for _, subschema in v.items():
elif k in ("additionalProperties", "additionalItems") and v:
MichaelBlume / escroll.hs
Created Oct 26, 2012
Cute script for drawing attention to errors in scrolling log output
View escroll.hs
#!/usr/bin/env runhaskell
import Data.List
import Control.Concurrent
import System.IO
takeBlock :: [String] -> (String, [String])
takeBlock (firstLine:moreLines) = (block, restLines) where
block = intercalate "\n" (firstLine:indLines)
(indLines, restLines) = span (isPrefixOf " ") moreLines
MichaelBlume /
Created Oct 27, 2012
Beeminder writing check
#!/usr/bin/env python
import envoy
import requests
import time
r ="find /Users/mike/Dropbox/writing | grep -v DS_Store | xargs wc -c")
count = r.std_out.split()[-2]
kb_written = int(count) // 1024
url = ""
View split-with.clj
(defn my-split-with [pred coll]
(let [p (promise)
passes ((fn step [c]
(if-let [[x & xs] (seq c)]
(if (pred x)
(cons x (step xs))
(do (deliver p c) nil))
(do (deliver p nil) nil))))
MichaelBlume / babel.hs
Last active Dec 18, 2015
prints the library of babel
View babel.hs
import Control.Monad
chars :: [Char]
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ,.'\"-;:?!()"
incrementS :: [[Char]] -> [[Char]]
incrementS [] = [chars]
incrementS ([_] : r) = chars : (incrementS r)
incrementS ((c:cs) : r) = cs : r
MichaelBlume / gist:6968441
Last active Dec 25, 2015
obj: reify for python
View gist:6968441
# Writing some unit tests in Python, I found myself homesick for Clojure's `reify`.
from functools import partial
class Blank(object): pass
def obj(*fs):
o = Blank()
for f in fs:
setattr(o, f.func_name, partial(f, o))
MichaelBlume / Chat.hs
Last active Jan 3, 2016
Transforms gchat logs into tumblr chat posts
View Chat.hs
#!/usr/bin/env runhaskell
module Main (main) where
-- When you copy a conversation out of your google chat logs, it looks like
-- this
-- Alice
-- hi
-- how are you
-- Bob Smith
from itertools import takewhile, ifilter
def fibs():
fib0 = 1
fib1 = 1
while True:
yield fib0
newfib = fib0 + fib1
fib0 = fib1
fib1 = newfib
View java8_postinst.bash
echo -n "Updating system so it uses the new JDK..."
update-alternatives --quiet --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0/bin/java" 2
update-alternatives --quiet --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0/bin/javac" 2
update-alternatives --quiet --set java /usr/lib/jvm/jdk1.8.0/bin/java
update-alternatives --quiet --set javac /usr/lib/jvm/jdk1.8.0/bin/javac
echo "done."
exit 0
View schema->gen.clj
(ns schema->gen
"Functions for generating test data from schemas."
(:require [four.stateful :as four]
[re-rand :refer [re-rand]]
[schema.core :as sch]
[simple-check.generators :as gen]))
(defn ^:private re-randify-regex
"schema requires ^$ while re-rand forbids them"
You can’t perform that action at this time.