Skip to content

Instantly share code, notes, and snippets.

View matthewd's full-sized avatar

Matthew Draper matthewd

View GitHub Profile

Keybase proof

I hereby claim:

  • I am matthewd on github.
  • I am matthewd (https://keybase.io/matthewd) on keybase.
  • I have a public key whose fingerprint is 4BBC 6089 979B 399C AD3C 246D 9C0D 2BE6 590D 2B86

To claim this, I am signing this object:

@matthewd
matthewd / gist:6541214
Last active December 22, 2015 22:39
Calling an association through another, without hm:t?
class Order < AR::Base
has_many :widgets
has_many :parts, through: :widget
end
class Widget < AR::Base
has_many :parts
end
class Part < AR::Base
@matthewd
matthewd / common-setup.sh
Last active December 17, 2015 14:29
.common/setup
#!/bin/bash
COMMON=.common
if [ ! -d "$HOME/$COMMON" ]; then
if ! which git >/dev/null 2>&1; then
if which apt-get >/dev/null 2>&1 && which sudo >/dev/null 2>&1; then
if ! sudo apt-get install git-core; then
echo "Failed to install git; can't check out files" >&2
exit 1
@matthewd
matthewd / gist:1697002
Created January 29, 2012 03:33
Check for unused aliases
check_an_alias() {
alias_name="$1"
typed_cmd=(${(zQ)2})
alias_result=(${(zQ)3})
while [[ "${alias_result[1]}" = "noglob" ]] || [[ "${alias_result[1]}" = "nocorrect" ]]; do
shift alias_result
done
if [[ "${#alias_result}" -gt "${#typed_cmd}" ]]; then
diff --git a/ants/visualizer/visualize_locally.py b/ants/visualizer/visualize_locally.py
index 7dc6ec1..7a3d6b4 100755
--- a/ants/visualizer/visualize_locally.py
+++ b/ants/visualizer/visualize_locally.py
@@ -35,10 +35,12 @@ def generate(data, generated_path):
data = data.replace('\n', '\\\\n')
content = path_re.sub(mod_path, content)
- content = insert_re.sub(data, content)
+ contents = insert_re.split(content, 2)
@matthewd
matthewd / check-puppet-packages.sh
Created October 2, 2011 18:06
Identify Debian packages that are not installed by Puppet
#!/bin/bash
# These were copied from /usr/local/bin/kvmCreate_squeeze.sh. Some or
# all probably shouldn't be listed here.
extra_packages="locales netbase net-tools ifupdown iptables linux-image-2.6-amd64"
# This is what debootstrap installs for 'minbase'
base_packages="apt $(aptitude -F %p search '?priority(required)')"
@matthewd
matthewd / diff-configs.sh
Created September 30, 2011 19:48
Diff /etc files against the versions supplied in Debian packages
#!/bin/bash
# This script will make a best-effort attempt at showing modifications
# to package-provided config files on a Debian system.
#
# It's subject to some pretty significant limitations: most notably,
# there's no way to identify all such config files. We approximate the
# answer by looking first at dpkg-managed conffiles, and then hoping
# that most of the time, if maintainer scripts are managing files
# themselves, they're using ucf. So, DO NOT TRUST THIS SCRIPT to find
2011/09/09 19:05:38 [DEBUG] processing critical: devshm_dev_shm -> : 98
2011/09/09 19:05:38 [DEBUG] processing warning: devshm_dev_shm -> : 92
2011/09/09 19:05:38 [DEBUG] processing unknown_limit: devshm_dev_shm -> 4
2011/09/09 19:05:38 [DEBUG] processing field: e2.com.au::portia.e2.com.au::df::devshm_dev_shm
2011/09/09 19:05:38 [DEBUG] rrd filename is: /var/lib/munin/e2.com.au/portia.e2.com.au-df-devshm_dev_shm-g.rrd
2011/09/09 19:05:38 [DEBUG] value: e2.com.au::portia.e2.com.au::df::devshm_dev_shm: unknown (crit: :98) (warn: :92)
2011/09/09 19:05:38 [DEBUG] processing critical: _dev_md2 -> : 98
2011/09/09 19:05:38 [DEBUG] processing warning: _dev_md2 -> : 92
2011/09/09 19:05:38 [DEBUG] processing unknown_limit: _dev_md2 -> 4
2011/09/09 19:05:38 [DEBUG] processing field: e2.com.au::portia.e2.com.au::df::_dev_md2
#!/usr/bin/env ruby
lib_path = File.expand_path("../../lib", __FILE__)
$:.unshift lib_path
require 'uri'
require 'net/http'
require 'optparse'
tango:src/rbx[hydra]% rbx -Xgc.large_object=5000 reverse.rb 4900
user system total real
Reversing string 4900 long 3.644228 0.004000 3.648228 ( 3.751245)
tango:src/rbx[hydra]% rbx -Xgc.large_object=2700 reverse.rb 2665
user system total real
Reversing string 2665 long 13.372836 0.028001 13.400837 ( 13.470050)