Skip to content

Instantly share code, notes, and snippets.

Avatar

Tristan Seligmann mithrandi

View GitHub Profile
@mithrandi
mithrandi / Dockerfile
Last active Aug 29, 2015
Dockerfile for Halcyon
View Dockerfile
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y build-essential git pigz zlib1g-dev vim curl libpq-dev
ADD . /halcyon
RUN ["/halcyon/halcyon", "paths"]
ENTRYPOINT ["/halcyon/halcyon"]
View gist:10ef1d58f3ee2d189632
def test_storeOverCollectedItem(self):
"""
If an item is replaced in the cache, the finalizer from the first item
does not remove the second item.
"""
o1 = Object(1)
self.cache.cache(42, o1)
gc.disable()
del o1
gc.collect()
@mithrandi
mithrandi / output
Last active Aug 29, 2015
weakref example
View output
mithrandi@lorien /tmp> pypy weakrefs.py
before disable: w() = <__main__.C object at 0x00007f5e52d41c58>
after del: w() = <__main__.C object at 0x00007f5e52d41c58>
after collect: w() = None
hi mom
after enable: w() = None
View lenses.hs
{-# LANGUAGE TemplateHaskell, Rank2Types, NoMonomorphismRestriction #-}
module Main where
import Control.Lens
import qualified Data.Map.Strict as M
data Deployment = Deployment
{ _deploymentName :: String
, _nodes :: [Node]
} deriving Show
@mithrandi
mithrandi / lenses-monadic.hs
Created Jan 13, 2015
Lenses example with IO
View lenses-monadic.hs
findDataset :: Dataset -> Maybe String
findDataset (view datasetName -> Just name) = M.lookup name datasets
findDataset (view datasetName -> Nothing) = Nothing
update_dataset_id :: Dataset -> IO Dataset
update_dataset_id d =
case findDataset d of
Just did -> return $ d & datasetId ?~ did
Nothing -> (\did -> d & datasetId ?~ did) <$> toString <$> nextRandom
@mithrandi
mithrandi / route53
Created Feb 2, 2015
route53 update script for ip-up.d
View route53
#!/usr/bin/python
from os import environ
from socket import gethostname
from boto import connect_route53
from boto.route53.record import ResourceRecordSets
IF_NAME = 'ppp4'
AWS_ACCESS_KEY = '...'
AWS_SECRET_KEY = '...'
View dnsmasq.conf
domain-needed
bogus-priv
resolv-file=/etc/ppp/resolv.conf
interface=eth0
addn-hosts=/etc/ppp/peeraddr
domain=mithrandi.net
dhcp-range=set:eth0,10.0.0.100,10.0.0.200,24h
dhcp-range=::,constructor:eth0,ra-stateless,ra-names
dhcp-host=f4:6d:04:af:b7:f2,10.0.0.7,lorien,72h
dhcp-host=00:1b:21:04:a6:24,e0:cb:4e:e6:ff:5d,10.0.0.10,gondolin,72h
@mithrandi
mithrandi / legacy
Created Feb 20, 2015
Axiom legacy declaration generator
View legacy
#!/usr/bin/env python
from twisted.python.reflect import namedAny
template = """
declareLegacyItem(
typeName=%r,
schemaVersion=%d,
attributes=dict(
%s))
"""
View gist:8922bd4fbff4b7263d4b
def fetch(..., clock=None):
if clock is None:
from twisted.internet import reactor as clock
def handleResponse(response):
# ...
d = agent.request(method, url, Headers(h), body)
call = clock.callLater(timeout, d.cancel)
def cancelTimeout(result):
@mithrandi
mithrandi / gist:fdeeb25cb05c846eceab
Last active Aug 29, 2015
Version of map handling deferreds/errors
View gist:fdeeb25cb05c846eceab
(ns clj-amp.core
(:require [manifold.deferred :as d]
[manifold.stream :as s]))
(defn- map'
"Like manifold.stream/map, except handles deferreds and closes the stream if an error occurs."
([f s]
(let [s' (s/stream)]
(s/connect-via
s
(fn [msg]