Skip to content

Instantly share code, notes, and snippets.

@mdub
mdub / include-after.rb
Created May 16, 2013
Ruby module include order matters!
View include-after.rb
module M; end
module Soup; end
class C; include M; end
module M; include Soup; end
C.ancestors #=> [C, M, Object, Kernel, BasicObject]
@mdub
mdub / syslog-injection.sh
Created May 1, 2013
Redirect STDOUT and STDERR into syslog, using "logger", and bash process substitution
View syslog-injection.sh
# Redirect STDOUT/STDERR into syslog
exec > >(logger -p user.info) 2> >(logger -p user.warn)
@mdub
mdub / ssh_config
Created Apr 30, 2013
SSH connection sharing
View ssh_config
# (hint from http://blogs.perl.org/users/smylers/2011/08/ssh-productivity-tips.html)
ControlMaster auto
ControlPath /tmp/ssh_mux_%h_%p_%r
ControlPersist 10m
@mdub
mdub / autotest-xterm-title.rb
Last active Dec 16, 2015
Autotest feedback in the terminal title-bar
View autotest-xterm-title.rb
# Pop this in your ~/.autotest
def set_title(title)
if ENV["TERM"] =~ /^xterm/
puts "\e]0;#{title}\007"
end
end
Autotest.add_hook(:green) do
set_title "GREEN - all passed"
@mdub
mdub / pip-install-ansible.log
Last active Dec 16, 2015
pip install ansible log
View pip-install-ansible.log
Downloading/unpacking ansible
Running setup.py egg_info for package ansible
DATA FILES=[('/usr/share/ansible/', ['./library/add_host', './library/apt', './library/apt_key', './library/apt_repository', './library/assemble', './library/async_status', './library/async_wrapper', './library/authorized_key', './library/bzr', './library/cloudformation', './library/command', './library/copy', './library/cron', './library/debug', './library/django_manage', './library/easy_install', './library/ec2', './library/ec2_facts', './library/ec2_vol', './library/facter', './library/fail', './library/fetch', './library/file', './library/fireball', './library/gem', './library/get_url', './library/git', './library/group', './library/group_by', './library/hg', './library/homebrew', './library/ini_file', './library/lineinfile', './library/lvg', './library/lvol', './library/macports', './library/mail', './library/mongodb_user', './library/mount', './library/mysql_db', './library/mysql_user', './library/nagios', './library/net
View subl-edit.rb
#! /usr/bin/ruby
file = ARGV.first || '.'
args = [file]
args.unshift("-w") unless File.directory?(file)
exec("subl", *args)
@mdub
mdub / ssh-psql.sh
Created Nov 16, 2012
Postgres psql connection via SSH tunnel
View ssh-psql.sh
#!/bin/sh
db_host=db-server
db_user=supersecret
db_name=myapp_production
port=65432
ssh_ctl=/tmp/$$-ssh-ctl-sock
ssh -S $ssh_ctl -fnN -L $port:localhost:5432 $db_host
@mdub
mdub / valid.rb
Created Oct 11, 2012 — forked from adzap/valid.rb
Testing fail?
View valid.rb
# I have a class that delegates functionality to a couple of objects that it
# constructs. I want to test this in isolation. I want to make sure that the
# objects are constructed with the right arguments. I also want to make sure
# that the results from the objects are handled correctly.
#
# I'm finding it hard to structure the code and test in a way that isn't
# cumbersome. What's below works, but it feels like a lot of stubbing and setup
# for something the should be simpler.
#
# Anyone got a better approach for this?
@mdub
mdub / enum_type.rb
Created Aug 1, 2012
Easy enumerated types
View enum_type.rb
# Provide support for defining enumerated types.
#
# Example
#
# class Colour
#
# extend EnumType
#
# define :red do
# # ...
@mdub
mdub / gist:2946149
Created Jun 18, 2012
ST2 custom keybindings
View gist:2946149
[
{ "keys": ["super+ctrl+r"], "command": "reveal_in_side_bar" },
{ "keys": ["super+shift+\\"], "command": "reindent" },
{ "keys": ["alt+m"], "command": "markdown_preview", "args": {"target": "browser"} }
]