🧘♂️
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
# I have a function that looks up a monthly report which may or may not exist yet (e.g. if | |
# you look at the start of a month, before I've gotten around to generating that month's | |
# report) | |
# | |
# where the report isn't generated I just want to return "0" for each column in this report; | |
# so what I do is return an instance of the below object whenever there's no report | |
# available (thus avoiding any "try" unpleasantness) - something about this slightly | |
# bothers me though. Is there a more elegant/simpler way I should consider? | |
class NullZeroObject |
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
gem "rack-ssl", "1.3.2" | |
# when Capybara issue 409 or 422 get resolved, you can switch back to the official | |
# capybara gem | |
# https://github.com/jnicklas/capybara/pull/409 | |
# https://github.com/jnicklas/capybara/pull/422 | |
gem "capybara", git: "https://github.com/mcolyer/capybara.git", branch: "fix-ssl-redirects" |
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
namespace :audio do | |
desc "downsample, segment, and upload audio files" | |
task :load => :environment do | |
access_key_id = ENV['AWS_ACCESS_KEY_ID'] | |
secret_access_key = ENV['AWS_ACCESS_KEY'] | |
source_dir = ENV['SOURCE_DIR'] | |
fail "Must specify AWS_ACCESS_KEY_ID, AWS_ACCESS_KEY, and SOURCE_DIR" if access_key_id.blank? || secret_access_key.blank? || source_dir.blank? | |
filenames = Dir["#{source_dir}/**/**.*"] | |
fail "#{source_dir} is empty" if filenames.empty? |
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
html = IO.read("survey.html") | |
rows = Nokogiri::HTML(html).css("tr")[????].collect { |r| r.children.to_a.values_at(0,3).collect(&:content) }.sort_by(&:last).reverse.collect { |r| "#{r.first} - #{r.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
# As soon as I create a Rails migration I always want to open that file in an editor. | |
# I'd like to submit the following patch to Rails to create an --editor argument | |
# for the migration generator but I can't quite figure out the Thor way of doing this. | |
require 'rails/generators/active_record' | |
module ActiveRecord | |
module Generators | |
class MigrationGenerator < Base | |
argument :editor, :type => :string, :lazy_default => ENV['EDITOR'], :required => false, :banner => "/path/to/your/editor", :desc => "Open migration using specified editor (defaults to EDITOR)" |
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
# Two of the projects we'll be discussing are heavily dependent on code like the example below, which | |
# requests stock price information from Google's finance API and transforms the results into a hash | |
# for use in our database. This pattern shows up over and over in my projects. I always setup a separate | |
# codebase containing a bunch of worker" modules that just do stuff like this. | |
# | |
# I need to write a bunch more of these for a variety of data sources. My plan is to start you off | |
# on these, then graduate to more complex features. | |
# | |
# Here are two things for you to try: | |
# |
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
# I run this command once a week on all of my active projects | |
# It helps ensure that I'm always able to use the latest/greatest | |
# versions of various dependencies, or at least that I find out | |
# quickly when I've become locked into a particular version | |
# (which just happened with the latest versions of the Ruby gems | |
# Webmock and VCR | |
alias mrupd='git pull && bundle update && rdbm && rspec spec; sd' | |
# the alias stands for 'massive rails update' because I have a bunch of other aliases that |
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
# BEGINNER: how to get started with ruby | |
# http://www.rubystudyhall.com/getting_started_with_ruby | |
# http://tryruby.org | |
# irb | |
# run "Hello, World" from command line | |
# do simple calculations | |
# read a file and count the lines in it | |
# read a file from command line argument |
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
# Flatten a transparent image with a white background: | |
convert -flatten img1.png img1-white.png | |
# Make an image transparent | |
convert -transparent '#FFFFFF' nontransparent.gif transparent.png | |
# convert an image into tiles | |
convert -size 3200x3200 tile:single_tile.png final.png | |
# making a montage from a collection of images |