Skip to content

Instantly share code, notes, and snippets.

@pbyrne
pbyrne / enablerebase.sh
Created August 23, 2012 20:20
Since Git's branch.enablerebase config option only works on branches created after enabling the setting, this iterates over your projects and their branches to enable it for existing branches.
#!/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.
@pbyrne
pbyrne / gist:3692815
Created September 10, 2012 18:38
Ack! Performance!
# 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
@pbyrne
pbyrne / performance.rb
Created September 27, 2012 16:28
Performance Comparison
# 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
@pbyrne
pbyrne / gist:3975818
Created October 29, 2012 19:11
Sample Interactive Pull Request

Introduction

I want to prompt for some specific questions and then insert them into a template.

In no particular order:

  • title
  • description
  • qa plan
@pbyrne
pbyrne / google_bot_aware.gemspec
Created November 13, 2012 16:50 — forked from rchampourlier/google_bot_aware.rb
Rack middleware to make Rails deal correctly with GoogleBot's '*/*;q=0.6' Accept header
Gem::Specification.new do |s|
s.name = 'google_bot_aware'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'Romain Champourlier'
s.email = '[email protected]'
s.summary = 'Google Bot Aware'
s.description = "Strip extra characters from Google Bot's Accept header so that Rails knows to use default MIME type in response."
s.files = ['google_bot_aware.rb']
@pbyrne
pbyrne / gist:4665235
Last active December 11, 2015 21:48
Sample interceptor to interrupt outbound emails in non-production environments.
# put this in lib or a gem or something
class NonProductionInterceptor
def self.delivering_email(message)
# implement some mechanism to strip non-example.com and non-tstmedia.com email
# addresses from the delivery lists. also verify that if no delivery emails are
# left, either drop the email (if possible) or add [email protected] or some
# other dummy address so no exception is raised when attempting to deliver.
#
# Feel free to crib from TstMailer, of course.
#
@pbyrne
pbyrne / hello.sh
Last active December 14, 2015 22:09
Testing curling a script to share with the team. Instead of a monsterous one-liner pasted into an email, try `curl SOME_GIST | bash -s param1 param2`.
#!/bin/bash
name=$1
echo Hello, $name! How are you?
#!/bin/bash
main() {
CURRENT_ORG=$1
NEW_ORG=$2
STARTING_DIR=$(pwd)
# bomb out if not given current and new org names
[ -z $CURRENT_ORG ] || [ -z $NEW_ORG ] && missing_arguments
@pbyrne
pbyrne / instructions.markdown
Last active December 15, 2015 05:09
Instructions to set up a Sport Ngin laptop.

These instructions focus on performing Automation commands for our Node.js applications. Additional work is required to run the applications, and further work to run our Rails applications.

Prepare Laptop

Install Xcode and Command-Line Build Tools

NOTE: Let's try skipping this whole section for newly set up laptops. The addition of brew install gcc-apple42 below should eliminate this necessity.

@pbyrne
pbyrne / ruby-1.9.3.markdown
Last active March 16, 2020 22:39
Comparison of our core Rails app using Webrick, Puma, and Unicorn. Almost no effort was made to optimize either application server. Tests were performed on a MacBook Air using `siege` to hit the application homepage.

TL;DR

Unicorn was by far the best performing (5.94 trans/sec over the 1-minute test, 352 total). Puma (3.95 trans/sec, 235 total) appeared to perform no better than Webrick, despite the default behavior of using up to 16 threads. Perhaps increasing its worker count to the number of cores will improve its performance.

I've tried to run multiple Puma workers with the workers directive (per their sample documentaiton), but I receive errors about undefined method 'workers' for #<Puma::Configuration::DSL:0x007ffca4bde798>).

Webrick

Server

$ bundle exec rails server