This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
require "open-uri" | |
url = "http://cloud-images.ubuntu.com/locator/ec2/releasesTable" | |
json_string = open(url).read | |
json_string.slice!(-6) # remove trailing comma, invalid json :\ | |
collection = JSON.load(json_string)["aaData"].inject([]) do |arr, row| | |
# ["us-west-2", "raring", "13.04", "i386", "instance-store", "20130706", "<a href=\"https://console.aws.amazon.com/ec2/home?region=us-west-2#launchAmi=ami-658e1d55\">ami-658e1d55</a>", "aki-fa37baca"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ruby-install | |
ruby_install_version = node["ruby_install"]["version"] | |
ruby_install_url = "https://github.com/postmodern/ruby-install/archive/v#{ruby_install_version}.tar.gz" | |
ruby_install_dir = "ruby-install-#{ruby_install_version}" | |
ruby_install_tar = "#{ruby_install_dir}.tar.gz" | |
execute "Install ruby-install" do | |
cwd "/tmp" | |
command <<-EOC | |
curl -Lo #{ruby_install_tar} #{ruby_install_url} && |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use capslock+a for the prefix key | |
set -g prefix C-a | |
# unbind initial prefix key to use later | |
unbind C-b | |
# more responsive default delay for vim | |
set -sg escape-time 1 | |
# tmux-pasteboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExponentialBackoff | |
def initialize(initial, max) | |
@initial = initial | |
@max = max | |
@current = initial | |
@step = 0 | |
end | |
def reset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Collateral < AR::B | |
has_attached_file :movie, url: "/uploads/:attachment/:id/:cache_key/:filename" | |
end |
minitest
is a great testing library and factory_girl
is a handy fixture replace library, especially when working with Rails.
It can get tedious to repeat FactoryGirl.
for every invocation of build
, create
, etcetera. Here is a handy shortcut to help reduce your Carpal Tunnel pain:
# for Test::Unit assertion style
class MiniTest::Rails::ActiveSupport::TestCase
include FactoryGirl::Syntax::Methods
end
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem "rails" | |
gem "pg" | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first = [1, 2, 3] | |
# => [1, 2, 3] | |
middle = [4, 5, 6] | |
# => [4, 5, 6] | |
last = [7, 8, 9] | |
# => [7, 8, 9] | |
all = [*first, *middle, *last] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo(a, *b, c) | |
puts [a, b, c].inspect | |
end | |
foo(1, 2, 3, 4, 5) | |
# => [1, [2, 3, 4], 5] |