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 / 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)"
}
@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 / 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 / cache.rb
Created December 10, 2010 16:09
Helper/Wrapper for the Rails caching mechanism.
class Cache
class << self
def read(key, &block)
if (value = self[key]).nil? and block_given?
value = block.call
self[key] = value
end
return value
end
<html>
<head>
<style>
input[type="button"]::-moz-focus-inner
{
border: 0;
}
.button, input[type="button"], input[type="submit"]
{
@simon-engledew
simon-engledew / application_controller.rb
Created August 11, 2010 10:09
ruby lambda in a different scope
class ApplicationController < ActionController::Base
def self.before_filter_in_instance(&block)
before_filter do |controller|
controller.instance_eval(&block)
end
end
# fails!
# params is not available
@simon-engledew
simon-engledew / post-commit
Created August 5, 2010 12:45
Post commit hook to play Hallelujah
#!/bin/sh
# post commit hook to play "Hallelujah" after a commit
FILENAME=~/.git/post-commit.mp3
DIRECTORY=`dirname $FILENAME`
if [ ! -d "$DIRECTORY" ]
then
mkdir "$DIRECTORY"
fi
@simon-engledew
simon-engledew / SEThreadInvocation.h
Created June 24, 2010 08:49
Thread invocation with varargs in Objective C
//
// SEThreadInvocation.h
//
#import <Foundation/Foundation.h>
@interface SEThreadInvocation : NSObject
{
NSThread * _thread;
NSInvocation * _invocation;
@simon-engledew
simon-engledew / run script for resque w. monit
Created February 16, 2010 12:59
A script to run Resque as a daemon.
#!/usr/bin/env ruby
if GC.respond_to?(:copy_on_write_friendly=); GC.copy_on_write_friendly = true; end
def pidfile
@pidfile ||= File.expand_path(File.join('..', '..', 'tmp', 'pids', 'consumer.pid'), __FILE__)
end
case ARGV.first
when 'start' then
openssl rand 9 -base64