Skip to content

Instantly share code, notes, and snippets.

@zennro
zennro / gist:7944306
Created December 13, 2013 13:36 — forked from noomii/gist:1131067
class vim {
$version = "7.3"
Exec {
path => [
'/usr/local/bin'
,'/usr/bin'
,'/bin'
],
}
file { "/usr/local/src": ensure => directory }
@zennro
zennro / sigterm.py
Created December 24, 2013 11:27 — forked from honza/sigterm.py
"""
This snippet shows how to listen for the SIGTERM signal on Unix and execute a
simple function open receiving it.
To test it out, uncomment the pid code and kill the process with:
$ kill -15 pid
"""
import signal
import sys
#!/usr/bin/env python
#coding:utf-8
import sys, os, re
import logging
from tornado.ioloop import IOLoop
from tornado.iostream import IOStream
from tornado.netutil import TCPServer
#!/usr/bin/env python
#coding:utf-8
import sys, os, re
import logging
from tornado.ioloop import IOLoop
from tornado.iostream import IOStream
from tornado.netutil import TCPServer
@zennro
zennro / gist:9002924
Created February 14, 2014 15:24 — forked from zbal/gist:7800423
# Based on https://gist.github.com/fernandoaleman/5083680
# Start the old vagrant
$ vagrant init ubuntu_saucy
$ vagrant up
# You should see a message like:
# [default] The guest additions on this VM do not match the install version of
# VirtualBox! This may cause things such as forwarded ports, shared
# folders, and more to not work properly. If any of those things fail on

Virtualenv's bin/activate is Doing It Wrong

I'm a Python programmer and frequently work with the excellent [virtualenv][] tool by Ian Bicking.

Virtualenv is a great tool on the whole but there is one glaring problem: the activate script that virtualenv provides as a convenience to enable its functionality requires you to source it with your shell to invoke it. The activate script sets some environment variables in your current environment and defines for you a deactivate shell function which will (attempt to) help you to undo those changes later.

This pattern is abhorrently wrong and un-unix-y. activate should instead do what ssh-agent does, and launch a sub-shell or sub-command with a modified environment.

Problems

import socket
if __name__ == "__main__":
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 9000))
data = "some data"
sock.sendall(data)
result = sock.recv(1024)
print result
sock.close()
echo "Don't naively execute this file as a shell script. I didn't add error-handling"
echo "or anything like that. Execute all the commands by hand at the command line."
echo
echo "FIXME: this process is currently broken, see note in source code below."
exit 1
# In testing, we don't need to mess with unstable kernels any longer; 3.10 is in testing.
# That 3.10 kernel from testing has also been backported to wheezy; in wheezy-backports.
#
# This should mean debian stable (+backports) has everything you need to run docker,
import pyev
class FiveSecondTimer(object):
def __init__(self, data):
self.data = data
def __call__(self, watch, revents):
print 'foo', data
loop = pyev.default_loop()
import math
import random
class Qubit:
def __init__(self, a = 1, b = 0):
'''Initialize a single qubit'''
self.zero = complex(a)
self.one = complex(b)
def xgate(self):