Skip to content

Instantly share code, notes, and snippets.

@cmaitchison
cmaitchison / git-multi-status.sh
Created June 5, 2013 08:58 — forked from aroberts/git-multi-status.sh
git-multi-status == git-status for all subdirectories
#!/bin/bash
# usage: $0 source_dir [source_dir] ...
# where source_dir args are directories containing git repositories
red="\033[00;31m"
green="\033[00;32m"
yellow="\033[00;33m"
blue="\033[00;34m"
purple="\033[00;35m"
@cmaitchison
cmaitchison / after_commit_with_transactional_fixtures.rb
Last active August 4, 2016 03:30 — forked from charleseff/after_commit_with_transactional_fixtures.rb
testing after_commit hooks with transactional fixtures in Rails 4
require 'active_record/connection_adapters/abstract/transaction'
module ActiveRecord
module ConnectionAdapters
class SavepointTransaction < OpenTransaction
def perform_commit_with_transactional_fixtures
commit_records if number == 1
perform_commit_without_transactional_fixtures
end
alias_method_chain :perform_commit, :transactional_fixtures
@cmaitchison
cmaitchison / mars_rover.rb
Last active December 14, 2015 18:59
mars rover problem in 3 lines of ruby 2 code
IO.read('i').lines.drop(1).each_slice(2){|p,t|x,y,h=p.split;x,y,h=[x.to_i,y.to_i,h.to_sym];z={N:[->{y+=1},:W,:E],E:[->{
x+=1},:N,:S],S:[->{y-=1},:E,:W],W:[->{x-=1},:S,:N]};t.strip.split(//).map{|c|if c=='M';z[h][0].call;elsif c=='L';h=
z[h][1];else;h=z[h][2];end};puts"#{x} #{y} #{h}"}
@cmaitchison
cmaitchison / chef_client_baseline.sh
Last active October 12, 2015 20:29
Ubuntu 12.04 Chef-client baseline (AWS)
#!/bin/bash -xe
#THIS SCRIPT MUST BE RUN AS ROOT
#configure locale
echo "export LANGUAGE=en_AU.UTF-8" > /tmp/locale
echo "export LANG=en_AU.UTF-8" >> /tmp/locale
echo "export LC_ALL=en_AU.UTF-8" >> /tmp/locale
cat /etc/bash.bashrc >> /tmp/locale
cp /tmp/locale /etc/bash.bashrc
@cmaitchison
cmaitchison / chef_server_bootstrap.sh
Created November 15, 2012 05:16
ubuntu 13.04 chef-server bootstrap (aws)
#!/bin/bash -xe
#THIS SCRIPT MUST BE RUN AS ROOT
#configure SSH
SSH_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuwaDITgrsmxVvSJ+HEir4iW2eBb8XqB3wIxCWJwmhiB2S6MkdX1CFcj8boHL2RIYgKN0yiTCVlOdQFjhyRpnd8NbS0RW7753SE1hzkgOg+2e1B15lf1PCSD5OPWAtpb1eYlLcs6hns+yFhYCFeQrKLBL2/si8D8OcQcTR7BjjFQEWdhjl4cYiT68cr57yFT+c/f32ZTynEWukC2YIGMjJ1nACUOYF8CSp6RUrD2kY3C1Pb1Q5V3jwi0lhay4aF5AWp28hPVtYASBe2BrYXp8uErhnmWxgXNV19P0NSHE7TBXd9nXz/njI2SDP/p2N/vHquz/Ybxs4F+kGGXknUFitQ== cmaitchison@gmail.com"
echo $SSH_KEY >> /home/ubuntu/.ssh/authorized_keys
#configure locale
echo "export LANGUAGE=en_AU.UTF-8" > /tmp/locale
@cmaitchison
cmaitchison / valid.rb
Created October 11, 2012 13:10 — forked from notahat/valid.rb
Testing fail?
# By leaning hard on the declarative nature of let(), you get to use
# a pattern where there is a single shared example whose
# expected result is defined at a lower level in the code.
# It is not really a pattern that is intuitive to everyone when
# they read this sort of code for the first time, so I am not about
# to claim it is better than other approaches, only different.
# There is no need for explicit tests to assert that the correct
# arguments are passed to the validators in this example, because
# if the arguments are not correct the doubles will not return the
@cmaitchison
cmaitchison / chef_solo_bootstrap.sh
Created September 19, 2012 11:38
Ubuntu 12.04 Chef-solo bootstrap (Ninefold)
#!/bin/bash -xe
#THIS SCRIPT MUST BE RUN AS ROOT
ADMIN_USER=admin
ADMIN_GROUP=admin
#add admin group
(cat /etc/group | grep -E '\b$ADMIN_GROUP\b') || sudo groupadd $ADMIN_GROUP
#add admin user
@cmaitchison
cmaitchison / chef_solo_bootstrap.sh
Created August 17, 2012 09:45
CentOS 6.3 Chef-Solo bootstrap (RackSpace)
#!/bin/bash -xe
#THIS SCRIPT MUST BE RUN AS ROOT
ADMIN_USER=admin
ADMIN_GROUP=admin
#add admin group
(cat /etc/group | grep -E '\b$ADMIN_GROUP\b') || sudo groupadd $ADMIN_GROUP
@cmaitchison
cmaitchison / chef_solo_bootstrap.sh
Created August 11, 2012 06:22
Ubuntu 12.04 Chef-Solo bootstrap (VPSBlocks)
#!/bin/bash -xe
#THIS SCRIPT MUST BE RUN AS ROOT
ADMIN_USER=admin
ADMIN_GROUP=admin
#add admin group
(cat /etc/group | grep -E '\b$ADMIN_GROUP\b') || sudo groupadd $ADMIN_GROUP
#add admin user
@cmaitchison
cmaitchison / chef_solo_bootstrap.sh
Created July 21, 2012 08:31
Ubuntu 12.04 Chef-Solo bootstrap (AWS)
#!/bin/bash -xe
#THIS SCRIPT MUST BE RUN AS ROOT
#configure SSH
SSH_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuwaDITgrsmxVvSJ+HEir4iW2eBb8XqB3wIxCWJwmhiB2S6MkdX1CFcj8boHL2RIYgKN0yiTCVlOdQFjhyRpnd8NbS0RW7753SE1hzkgOg+2e1B15lf1PCSD5OPWAtpb1eYlLcs6hns+yFhYCFeQrKLBL2/si8D8OcQcTR7BjjFQEWdhjl4cYiT68cr57yFT+c/f32ZTynEWukC2YIGMjJ1nACUOYF8CSp6RUrD2kY3C1Pb1Q5V3jwi0lhay4aF5AWp28hPVtYASBe2BrYXp8uErhnmWxgXNV19P0NSHE7TBXd9nXz/njI2SDP/p2N/vHquz/Ybxs4F+kGGXknUFitQ== cmaitchison@gmail.com"
echo $SSH_KEY >> /home/ubuntu/.ssh/authorized_keys
#configure locale
echo "export LANGUAGE=en_AU.UTF-8" > /tmp/locale