Skip to content

Instantly share code, notes, and snippets.

@whylom
whylom / README.md
Created April 23, 2012 18:01
How to install Graphite on Vagrant with Chef

Here are some quick notes on installing Graphite on a Vagrant virtual machine using Chef recipes from GitHub. This more or less assumes you know what you're doing with Vagrant and Chef.

Notes

  • I used the "lucid32" Ubuntu base box you see in most Vagrant examples (http://files.vagrantup.com/lucid32.box)
  • Where possible, I used the cookbooks from Opscode. I was forced to use alternatives for Python (did not work for me) and for Graphite (no Opscode cookbook as of now).
  • The Graphite recipe depends on the Python, Apache2, and runit recipes.
  • I'm running the apt recipe first to update the Ubuntu package manager. The out-of-date manager that ships with the lucid32 box errored out for me when running the Python recipe.

Cookbooks Used

@whylom
whylom / gist:3018099
Created June 29, 2012 13:58
git purge (delete unmerged branches starting with "_")

When using Git, I find myself doing a lot of what I call "exploratory merging" into a throwaway local branch. This is to preview what a scary merge might look like master, or to isolate a bug in a staging environment by selectively merging in certain of the branches that have been deployed.

The names of my throwaway branches always start with an underscore, so I can easily see them when I git branch. Below is a Bash one-liner (aliased as git purge) that deletes unmerged branches whose names start with "_".

[alias]
  purge   = !git branch --no-merged | tr -d "* " | grep ^_ | xargs git branch -D
@whylom
whylom / gist:4383284
Created December 26, 2012 21:29
How many commits did we push to master in 2012?

Get the first commit of 2012

$ git log --pretty=format:'%H' --after="2011-12-31" | tail -1
d41d8cd98f00b204e9800998ecf8427e

Count the number of commits since then (inclusive)

$ git rev-list d41d8cd98f00b204e9800998ecf8427e^..HEAD | wc -l 
44555
@whylom
whylom / trick.rb
Created January 17, 2013 19:28
Neat Sinatra trick
set(:probability) { |value| condition { rand <= value } }
get '/win_a_car', :probability => 0.1 do
"You won!"
end
get '/win_a_car' do
"Sorry, you lost."
end
@whylom
whylom / README.md
Last active December 17, 2015 19:49
Ruby script that enhances the standard `git branch` listing by organizing and color coding remotes (origin, root, etc).

This is a Ruby script that enhances the standard git branch listing by organizing and color coding remotes (origin, root, etc).

screenshot

  • Branches whose remote is origin (the default) are listed at the top.
  • Branches whose remote is not origin are listed next, with the remote displayed in magenta. This makes it easier to see branches that are shared with other developers.
  • A hardcoded list of staging branches are displayed at the bottom in gold.
@whylom
whylom / .powrc
Created September 26, 2013 15:47
.powrc for RVM gemset
if [ -f "$rvm_path/scripts/rvm" ]; then
source "$rvm_path/scripts/rvm"
rvm use $(cat .ruby-version)@$(cat .ruby-gemset)
fi
@whylom
whylom / sync.rake
Last active March 22, 2016 19:44
Rake task to copy assets between S3 buckets. Requires the aws-s3 gem (http://amazon.rubyforge.org/)
# add a new "put_copy" method to the Amazon client's S3Object class
# to enable copying an object from 1 bucket to another
# http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html
class AWS::S3::S3Object
def self.put_copy(source_key, target_key, source_bucket, target_bucket, options = {})
original = open(url_for(source_key, source_bucket))
default_options = { :content_type => original.content_type }
store(target_key, original, target_bucket, default_options.merge(options))
acl(target_key, target_bucket, acl(source_key, source_bucket))
end
@whylom
whylom / to_hash.rb
Last active December 25, 2015 20:19
Array#to_hash converts an array of instances into a hash using the provided pair of methods to determine the key & value of each row
# example class
class State < Struct.new(:name, :code)
def self.all
[
State.new('Alabama', 'AL'),
State.new('Alaska', 'AK'),
State.new('Arizona', 'AZ')
]
end
end
@whylom
whylom / README.md
Last active August 29, 2015 13:57
Superhash!

Superhash!

A wrapper for Hash that lets you access keys via dynamic methods (like Ruby's OpenStruct) but also:

  • works recursively
  • also lets you use Hash methods like [] and keys

Example

### Keybase proof
I hereby claim:
* I am whylom on github.
* I am whylom (https://keybase.io/whylom) on keybase.
* I have a public key whose fingerprint is B2D6 34F6 025A 0830 0169 3C32 80F6 B36C A0C7 7A66
To claim this, I am signing this object: