Skip to content

Instantly share code, notes, and snippets.

View mithrandi's full-sized avatar

Tristan Seligmann mithrandi

View GitHub Profile
@mithrandi
mithrandi / gist:8922bd4fbff4b7263d4b
Created March 13, 2015 14:11
Agent timeout example
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 / legacy
Created February 20, 2015 11:00
Axiom legacy declaration generator
#!/usr/bin/env python
from twisted.python.reflect import namedAny
template = """
declareLegacyItem(
typeName=%r,
schemaVersion=%d,
attributes=dict(
%s))
"""
@mithrandi
mithrandi / dnsmasq.conf
Created February 2, 2015 17:58
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 / route53
Created February 2, 2015 17:51
route53 update script for ip-up.d
#!/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 = '...'
@mithrandi
mithrandi / lenses-monadic.hs
Created January 13, 2015 14:39
Lenses example with IO
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 / lenses.hs
Created January 13, 2015 02:14
Lens example
{-# 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
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 August 29, 2015 14:13
weakref example
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
@mithrandi
mithrandi / Dockerfile
Last active August 29, 2015 14:12
Dockerfile for Halcyon
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"]
@mithrandi
mithrandi / lambdacircus.coffee
Created May 1, 2014 07:24
LambdaCircus CoffeeScript / JS comparison
class Quote extends Backbone.Model
voteUp: =>
d = $.post(@get('voteUp'), undefined, undefined, 'json')
d.done (data) =>
@voted = true
@set data
voteDown: =>
d = $.post(@get('voteDown'), undefined, undefined, 'json')
d.done (data) =>