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
# plain ActiveRecord | |
Benchmark.measure do | |
User.where(:activated => true).limit(200000).map(&:first_name) | |
end | |
# => 58.210000 12.970000 71.180000 ( 73.134415) | |
# writing the improved SQL by hand | |
Benchmark.measure do | |
ActiveRecord::Base.connection.select_all("select * from users where activated = 1 limit 200000").map { |attrs| attrs[:first_name] } | |
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
# setup from controller and model code | |
params = {game_id: 3598462, play_by_play_string: true} | |
sort_order = [:play_index, :asc] | |
plays = Play.where(:game_id => params[:game_id]).order_by(sort_order) | |
plays = plays.first.class.prune_plays(plays) | |
methods = [:initial_screen] | |
play_by_play_string = params[:play_by_play_string] | |
if play_by_play_string | |
methods = plays.first.class.play_by_play_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
#!/bin/bash | |
# Enables automatic rebase when pulling for each existing branch in your | |
# projects. This is useful in conjunction with the 'branch.enablerebase always' | |
# option, which enables this setting on new branches but leaves existing | |
# branches intact. | |
# | |
# Pass this a directory which contains all of your projects and it will enable | |
# thie option for all existing local branches in each Git repo within it. |
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
# desired_cluster is a hash of roles and their counts (e.g., {web: 2, redis: 1} | |
def equalize_servers fog, app, environment, desired_cluster | |
current_cluster = filtered_servers(fog, app, environment).group_by { |server| server.tags["role"] } | |
to_build = {} | |
to_destroy = [] | |
current_cluster.each do |role, servers| | |
if desired_cluster.has_key? role | |
# we want some, but do we have the right amount? | |
difference = desired_cluster[role] - servers.count |
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
Run options: include {:focus=>true} | |
All examples were filtered out; ignoring {:focus=>true} | |
Automation::CLI | |
.perform(command) | |
passes the given command to the shell | |
.say(message) | |
displays the given message | |
.perform_in(dir, &block) |
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
79c79 | |
< let s:code = "print ($: + begin; require %q{rubygems}; Gem.all_load_paths.sort.uniq; rescue LoadError; []; end).join(%q{,})" | |
--- | |
> let s:code = "print ($:)" |
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
#!/bin/bash | |
echo "Updating Homebrew and bash completion" | |
brew update | |
echo " | |
# homebrew completion files for installed libraries | |
if [ -f `brew --prefix`/etc/bash_completion ]; then | |
. `brew --prefix`/etc/bash_completion | |
fi | |
" >> ~/.bash_profile |
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
# Assumes a Comment model with a message attribute contianing the text of the | |
# comment. Change these to suit your needs. | |
class Comment | |
validate :disallow_phone_numbers_and_email_addresses | |
# possibly not the most performant, but it's clear | |
# assumes you have arrays of regexes you want to dissalow | |
def disallow_phone_numbers_and_email_addresses | |
if PHONE_NUMBERS.any? { |regex| message =~ regex } | |
errors.add(:message, "cannot contain phone numbers.") |
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
testing download |
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
#!/usr/bin/env ruby | |
# | |
# Simple script to perform SCM (svn, hg, git) commands across your workspace | |
# Edit the SHARED_WORKSPACE environment variable if your code isn't checked out to ~/workspace | |
# Skip to the end for the actual execution ... to keep it all in one file, had to define the class first | |
# Get the latest version from https://gist.github.com/1090808 | |
USAGE = <<-end_usage | |
SSS performs SCM commands on all projects in your workspace. Set the | |
SHARED_WORKSPACE environment variable if your workspace is not ~/workspace. |