Skip to content

Instantly share code, notes, and snippets.

View matthewd's full-sized avatar

Matthew Draper matthewd

View GitHub Profile
@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
@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)')"
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 / 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
@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: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

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:b74b0de5244b2a95952b
Last active August 29, 2015 14:00
gsub forwarding with $1
class X < String
def evil_call(meth, args, block, &wrap_block)
block.binding.eval(<<-END, __FILE__, __LINE__+1).call(to_str, meth, args, wrap_block)
lambda do |str, meth, args, block|
str.send(meth, *args, &block)
end
END
end
def gsub(*args, &block)
@matthewd
matthewd / post-checkout.sh
Created June 14, 2014 07:16
Per-branch Gemfile.lock
#!/bin/bash
if [ "$3" = 1 ]; then
old_branch="`git name-rev --name-only --no-undefined "$1" | cut -d'~' -f1`"
new_branch="`git name-rev --name-only --no-undefined "$2" | cut -d'~' -f1`"
if [ "$old_branch" != "$new_branch" ]; then
mv -f "Gemfile.lock" ".Gemfile/lock.$old_branch"
if [ -f ".Gemfile/lock.$new_branch" ]; then
mv -f ".Gemfile/lock.$new_branch" "Gemfile.lock"
diff --git a/vmdb/lib/acts_as_ar_model.rb b/vmdb/lib/acts_as_ar_model.rb
index e23a20f..d6838a8 100644
--- a/vmdb/lib/acts_as_ar_model.rb
+++ b/vmdb/lib/acts_as_ar_model.rb
@@ -1,16 +1,3 @@
-class ActsAsArModelColumn < ActiveRecord::ConnectionAdapters::Column
- attr_reader :options
-
- def initialize(name, options)
- type = options.kind_of?(Symbol) ? options : options[:type]