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
#!/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 |
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
# 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)) |
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 Control.Monad | |
chars :: [Char] | |
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ,.'\"-;:?!()" | |
incrementS :: [[Char]] -> [[Char]] | |
incrementS [] = [chars] | |
incrementS ([_] : r) = chars : (incrementS r) | |
incrementS ((c:cs) : r) = cs : r |
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
(defn my-split-with [pred coll] | |
(let [p (promise) | |
passes ((fn step [c] | |
(lazy-seq | |
(if-let [[x & xs] (seq c)] | |
(if (pred x) | |
(cons x (step xs)) | |
(do (deliver p c) nil)) | |
(do (deliver p nil) nil)))) | |
coll)] |
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
#!/usr/bin/env python | |
import envoy | |
import requests | |
import time | |
r = envoy.run("find /Users/mike/Dropbox/writing | grep -v DS_Store | xargs wc -c") | |
count = r.std_out.split()[-2] | |
kb_written = int(count) // 1024 | |
url = "https://www.beeminder.com/api/v1/users/mblume/goals/writing/datapoints.json" |
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
#!/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 |
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
def rec_schema_transform(transform): | |
def recur(schema): | |
if not isinstance(schema, dict): | |
return | |
transform(schema) | |
for k, v in schema.items(): | |
if k in ("properties", "patternProperties", "dependencies"): | |
for _, subschema in v.items(): | |
recur(subschema) | |
elif k in ("additionalProperties", "additionalItems") and v: |
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
qualia = ("red", "blue", "cold", "pleasure") | |
memory_associations = { "red": ("anger", "hot") | |
, "blue": ("cold", "calm") | |
, "pleasure": ("hot", "good") | |
, "cold": ("blue", "calm") | |
} | |
def experience_qualia(in_qual): | |
for q in qualia: | |
if in_qual == q: |
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
def compose_defaults(*defaults): | |
'''I got annoyed that simplejson.dumps doesn't let you pass multiple | |
defaults. So here's this.''' | |
def new_default(obj): | |
for default in defaults: | |
try: | |
return default(obj) | |
except: | |
pass | |
raise TypeError("no default functions succeeded") |
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
'''Localdict -- reduce your typing by half when constructing a dictionary | |
literal from objects in the local context. | |
params = {'foo': foo, 'bar': bar, 'baz': baz} | |
can be replaced ith | |
params = localdict('foo', 'bar', 'baz') | |
''' |