Skip to content

Instantly share code, notes, and snippets.

@pbyrne
pbyrne / conditional_array.rb
Last active December 21, 2015 03:18
I'm building a small array dynamically and then picking the maximum value. I have problems with each formulation. Which choice is less evil?
# This option has the most clarity, but I generally hate local variables in a
# method, preferring to use tap.
def calculated_foo
available_foos = []
available_foos << bar
available_foos << baz.qux if baz
available_foos.max
end
# It's a little less clear, unless you know what tap is, and `end.max` is
@pbyrne
pbyrne / .bashrc
Created July 2, 2013 15:19
Putting the local install of MySQL into your PATH
export PATH=/usr/local/mysql/bin:$PATH
@pbyrne
pbyrne / ssl_url_replacer.rb
Last active December 15, 2015 11:58
Sample implementation of the SslUrlReplacer that we discussed at the whiteboard.
# Search and replace page elements in the CMS for old SSL URLs and replace with
# a new domain.
#
# Example:
#
# CMS::SslUrlReplacer.new(Site.first, "foo.bar.com", "foobar.example.com").perform
class CMS::SslUrlReplacer
# Public: Initialize a new SslUrlReplacer
#
# site - An instance of Site
@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

@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.

#!/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 / 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?
@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 nobody@example.com or some
# other dummy address so no exception is raised when attempting to deliver.
#
# Feel free to crib from TstMailer, of course.
#
@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 = 'romain@softr.li'
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: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