Skip to content

Instantly share code, notes, and snippets.

class Environment(Template):
def __init__(self, name, region):
self.name = name
self.region = region
self.vpc = boto.vpc.connect_to_region(region)
self.ec2 = boto.ec2.connect_to_region(region)
self.outputs = {}
resources = self.resources(self.environment(), self.images())
@whilp
whilp / a_b
Last active December 19, 2015 06:19
a
Element = namedtuple("Element", "name children attrs")
def E(name, *children, **attrs):
return Element(name, list(children), attrs)
def serialize(element):
# Short circuit if the element is just text.
if not hasattr(element, "children"):
return element
tag = element.name
@whilp
whilp / README.md
Last active December 16, 2015 11:49

apt-get update if necessary

Some Vagrant baseboxes (like Opscode's bento boxes) ship with stale apt package indexes. When you run vagrant up and your main provisioner tries to install a package, you get an error. Here's a quickfix that takes advantage of Vagrant's support for multiple provisioners:

  config.vm.provision :shell do |shell|
    shell.inline = 'test -f $1 || (sudo apt-get update -y && touch $1)'
    shell.args = '/var/run/apt-get-update'
  end
@whilp
whilp / gist:5285644
Created April 1, 2013 15:40
Thoughts on Monitorama.eu from Boston 2013
- prep AV between speakers
- put mic on speaker so they can move about
- alternative speakers: science (CERN?), news (guardian?), disaster management
- publish slides before talks/workshops
- provide local mirror for things like Vagrant baseboxes
Processing WelcomeController#index (for 10.0.2.2 at 2013-01-14 22:13:27) [GET]
Parameters: {"controller"=>"welcome", "action"=>"index"}
ActiveRecord::StatementInvalid (PG::Error: ERROR: relation "settings" does not exist
LINE 4: WHERE a.attrelid = '"settings"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"settings"'::regclass
@whilp
whilp / formatter.py
Created August 11, 2012 22:10
Data formatting
#!/usr/bin/env python
# unicode_literals + unittest2 will give you handy diffs when the test methods fail.
from __future__ import unicode_literals
try:
import unittest2 as unittest
except ImportError:
import unittest
@whilp
whilp / gitconfig
Created March 29, 2012 22:30
gitconfig
[alias]
st = status -s
ci = commit
ca = commit -a
glog = log --oneline --decorate --graph
tags = tag -l
man = ls-files
bare = config --bool core.bare true
[mergetool]
prompt = false
@whilp
whilp / gist:1070435
Created July 7, 2011 20:11
Pattern: distributed, deterministic kicks
$ dsh -gHOSTGROUP 'echo /sbin/service foo restart | sudo at now + $(hostname | hashrange 60) minutes'
@whilp
whilp / gist:1024678
Created June 14, 2011 10:56
Test if an IP is active
>>> import socket
>>> s = socket.socket(socket.AF_INET)
>>> s.bind(("127.0.0.1", 0))
>>> s.bind(("10.0.0.1", 0))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in bind
socket.error: [Errno 22] Invalid argument