Skip to content

Instantly share code, notes, and snippets.

deploy instance, copy image in to /mnt/foo.qcow2
apt-get install qemu-utils
modprobe nbd max_part=16
qemu-nbd -c /dev/nbd1 imagefile
mkdir /mnt/2
mount /dev/nbd1p1 /mnt/2
rsync -axv /mnt/2/ / --delete-after
apt-get install qemu-utils
umount /mnt/2
qemu-nbd -d /dev/nbd1
//Copy this over the contents at tddbin.com
//Replace the [] in the assert statements with a functional equivalant
//Reference here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
//Lambda syntax: (x,y) => x + y, works in firefox, try it out :)
function range(start, end, jump) {
jump = jump || 1
if (start && !end)
return actualRange(0, start, jump)
return actualRange(start, end, jump)
@rbtcollins
rbtcollins / answers
Created April 22, 2015 10:23
answers to problems
//Copy this over the contents at tddbin.com
//Replace the [] in the assert statements with a functional equivalant
//Reference here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
//Lambda syntax: (x,y) => x + y, works in firefox, try it out :)
function range(start, end, jump) {
jump = jump || 1
if (start && !end)
return actualRange(0, start, jump)
return actualRange(start, end, jump)
@rbtcollins
rbtcollins / gist:f570a2dd4aa4c0ea0264
Last active August 29, 2015 14:23
Python Monad notes
PyMonad
https://pypi.python.org/pypi/PyMonad/
Doesn't duck type Writer - subclass
class StringWriter(Writer):
logType = str
PyMonads
https://github.com/dustingetz/pymonads
Doesn't duck type Writer:
https://github.com/dustingetz/pymonads/blob/master/writer.py#L6
@rbtcollins
rbtcollins / demo.py
Last active February 8, 2018 02:42
Getting at the mystery object
from ctypes import *
pythonapi.PyDict_SetItemString.argtypes=[c_void_p, c_char_p, c_void_p]
class PyObject(Structure):
_fields_ = [("refcnt", c_size_t),
("typeid", c_void_p)]
pythonapi.PyThreadState_GetDict.restype = POINTER(PyObject)
pythonapi.PyDict_SetItemString(c_void_p(id(locals())), b"threaddict", pythonapi.PyThreadState_GetDict())
repr([1])
print(threaddict)
@rbtcollins
rbtcollins / build-system-abstraction.rst
Last active October 27, 2015 01:38
build system abstraction
PEP: XX
Title: Build system abstraction for pip/conda etc
Version: $Revision$
Last-Modified: $Date$
Author: Robert Collins <rbtcollins@hp.com>, Nathaniel Smith <njs@pobox.com>
Discussions-To: distutils-sig <distutils-sig@python.org>
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
class HandleEvent(testtools.StreamResult):
def __init__(self, callback):
self._buffers = {}
self._callback = callback
def status(self, test_id=None, test_status=None, test_tags=None,
runnable=True, file_name=None, file_bytes=None, eof=False,
mime_type=None, route_code=None, timestamp=None):
if not test_id:
return
import csv
f = open('income-distribution.csv', 'rt')
l = list(csv.reader(f))
pre = l[5:157]
# top edge, lower edge, %
brackets = [(14000, 0, 0.105), (48000, 14001, 0.175), (70000, 48001, 0.30), (200000, 70001, 0.33)]
total = 0
for (_, people, total_income, _) in pre:
people = float(people)
total_income = float(total_income) * 1000000
from operator import methodcaller
import random
import itertools
def card_values(card):
"""Get the possible values of a card in a blackjack game.
e.g. card_values(0) -> (1, 11)
:return: A tuple of the possible values.
"""
@rbtcollins
rbtcollins / __init__.py
Last active April 18, 2016 00:55
using testresources
from testresources import OptimisingTestSuite
def load_tests(standard_tests, module, loader):
# top level directory cached on loader instance
this_dir = os.path.dirname(__file__)
package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
standard_tests.addTests(package_tests)
return OptimisingTestSuite(standard_tests)