Skip to content

Instantly share code, notes, and snippets.

View simon-engledew's full-sized avatar
🙈

Simon Engledew simon-engledew

🙈
View GitHub Profile
@simon-engledew
simon-engledew / netconf.py
Created March 27, 2011 09:45
snack based ncurses script for configuring ubuntu networking, first pass
from __future__ import with_statement
import snack, ipaddr, optparse, re, shlex
parser = optparse.OptionParser()
parser.add_option('--no-cancel', action='store_true', dest='no_cancel', help='Do not display a cancel button')
parser.add_option('--title', action='store', dest='title', default='Configure Networking', help='set the form title')
parser.add_option('--interface', action='store', dest='interface', default='eth0', help='interface to edit')
parser.add_option('--interfaces-file', action='store', dest='interfaces_file', default='/etc/network/interfaces', help='target interfaces file to edit')
parser.add_option('--dns-file', action='store', dest='dns_file', default='/etc/resolvconf/resolv.conf.d/base', help='target dns file to edit')
@simon-engledew
simon-engledew / chunks.py
Created June 7, 2011 16:22
python chunked encoding
import re
def from_pattern(pattern, type):
def coerce(value, *args):
value = str(value)
match = pattern.search(value)
if match is not None:
return type(match.group(1), *args)
raise ValueError("unable to coerce '%s' into a %s" % (value, type.__name__))
return coerce
@simon-engledew
simon-engledew / jail-union.sh
Last active September 26, 2015 01:18
Create a virtual build environment
function chroot_jail {
TEMP="/tmp/$$.$(date +%s)"
mkdir "$TEMP"
sudo unionfs "$1=RW:/=RO" "$TEMP" -o allow_other -o dev -o cow
trap "sudo fusermount -u \"$TEMP\" && rm -r \"$TEMP\"" INT TERM EXIT
sudo chroot "$TEMP" /bin/bash -c "$(cat)"
}
# config/environment.rb => require 'xmlrpc/client'
#XMLRPC::Config.const_set(:ENABLE_NIL_CREATE, true)
XMLRPC::Config.const_set(:ENABLE_NIL_PARSER, true) unless XMLRPC::Config.const_defined?(:ENABLE_NIL_PARSER)
module XmlRpc
class Api
class << self
def method_missing(method, *args)
@simon-engledew
simon-engledew / Dispatch.cs
Created August 25, 2011 14:57
Dispatch by Generic type
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Diagnostics;
using System.Threading;
namespace Ladybear
{
/// <summary>
/// Dispatches to an Action based on the first generic type parameter.
@simon-engledew
simon-engledew / BubbleBabble.cs
Created September 2, 2011 09:01
C-Sharp implemention of the Bubble Babble algorithm
public static class BubbleBabble
{
private static readonly string vowels = "aeiouy";
private static readonly string consonants = "bcdfghklmnprstvzx";
public static string Convert(byte[] bytes)
{
int seed = 1;
int rounds = 1 + bytes.Length / 2;
StringBuilder result = new StringBuilder();
@simon-engledew
simon-engledew / xmlbuilder.py
Created September 8, 2011 14:09
Python magic to concisely generate XML
import xml.dom.minidom as xml
class Document(object):
"""
XML Document Builder
@author Simon Engledew
example:
dom = Document.catalog(version="1.0")
@simon-engledew
simon-engledew / foreach.py
Created September 20, 2012 12:48
Python ForEach Naughtiness
import __builtin__
import operator
def merge(a, b):
a = a.copy()
a.update(b)
return a
class curry(object):
def __init__(self, fn, *args, **kwargs):
@simon-engledew
simon-engledew / post-receive
Created January 28, 2013 14:07
cow-say for git post-receive and campfire
#!/usr/bin/env python
import json
import requests
import json
import commands
import pipes
import sys
import glob
import os
@simon-engledew
simon-engledew / format.js
Last active December 26, 2015 08:59
String.format
String.format = function format()
{
var replacements = arguments;
return arguments[0].replace(/\{(\d+)\}/gm, function replace(string, match) {
return replacements[parseInt(match) + 1];
});
};