Skip to content

Instantly share code, notes, and snippets.

@xuru
xuru / ubuntu-12.04-lts.erb
Created June 20, 2012 22:08
Chef bootstrap script for ubuntu 12.04 LTS that actually works
bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
if [ ! -f /usr/bin/chef-client ]; then
apt-get update
apt-get install -y libreadline5 libruby1.9.1 ruby1.9.1 ruby1.9.1-dev build-essential wget rubygems1.9.1
fi
LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8 export LC_CTYPE LANG
@xuru
xuru / apt-upgrade.sh
Created July 10, 2012 17:42
non-interactive debian/ubuntu upgrade
#! /bin/sh
PATH=/usr/sbin:/sbin:/usr/bin:/bin
cat <<EOF > /etc/apt/apt.conf.noninteractive
APT::Get::Assume-Yes "true";
APT::Get::Show-Upgraded "true";
APT::Quiet "true";
DPkg::Options {"--force-confmiss";"--force-confold"};
DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";};
@xuru
xuru / has_remote_file_modified.rb
Created September 28, 2012 18:56
has_remote_file_modified: Ruby method to examine the http header and see if a file is newer on the remote system
class Chef
class Recipe
def has_remote_file_modified(uri, filepath)
require 'net/http'
http = Net::HTTP.new(uri.host, uri.port)
req = Net::HTTP::Head.new(uri.path)
if uri.user
req.basic_auth uri.user, uri.password
end
@xuru
xuru / argparseexample.py
Created November 12, 2012 22:52
argparse for the impatient
import argparse
parser = argparse.ArgumentParser(description='Spawn an army of test-robot '
'agents for the purpose of automated testing')
parser.add_argument('-c', '--create-test', action='store_true',
help='Create a new test...')
parser.add_argument('-t', '--test-case', dest='testcase',
default="robot_script.json" help='Test case file name (i.e. robot_script.json)')
# the default action here is to store False in opts.dumptest, and is not
@xuru
xuru / json_diff.py
Created November 28, 2012 17:00
Determines if two python objects differ (only json types supported)
def json_diff(obj, other, order_matters=True):
""" This method assumes json types: dict, list, strings, numbers, booleans and null """
if isinstance(obj, dict) and isinstance(other, dict):
if set(obj.keys()) != set(other.keys()):
return True
for key in sorted(obj.keys()):
if json_diff(obj[key], other[key], order_matters):
return True
elif isinstance(obj, list) and isinstance(other, list):
@xuru
xuru / observable_dict.py
Created December 7, 2012 17:23
Using the observer pattern, ObservableDict can be used to monitor changes to the dictionary.
class Observable:
'''Mixin for objects that need to be observed.'''
_observers = None
def observe(self, observer):
if not self._observers:
self._observers = []
self._observers.append(observer)
@xuru
xuru / client.conf
Last active December 11, 2015 06:28
openvpn madness
client
dev tap
proto tcp
remote 50.112.165.49 443
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert vagrant-eric_plaster.crt
@xuru
xuru / qmetry.py
Created February 22, 2013 19:46
suds starter
import suds
WSDL_URL = "http://mycompany.qmetry.com/myid/WEB-INF/ws/service.php?wsdl"
class QMetry(object):
def __init__(self, timeout=90):
client = suds.client.Client(WSDL_URL)
self.service = client.service
@xuru
xuru / ipy.py
Created March 5, 2013 16:02
Embed ipython when using a cmd.Cmd (or kmd.Kmd) shell
from IPython.core.completer import IPCompleter
from IPython.config.loader import Config
import rl
def setup_ipython():
try:
get_ipython()
except NameError:
@xuru
xuru / reset.scpt
Created March 21, 2013 21:02
Reset the simulator
tell application "iPhone Simulator"
activate
end tell
tell application "System Events"
tell process "iPhone Simulator"
tell menu bar 1
tell menu 2
click menu item 5
end tell
end tell