Skip to content

Instantly share code, notes, and snippets.

View baburdick's full-sized avatar

Bruce Burdick baburdick

View GitHub Profile
# Write a MathService module that has a method that can sum an Array of Numbers
# It should raise an exception if not given an Array.
# It should raise an exception if any elements are not Numeric.
module MathService
def sum array_of_numbers
raise unless array_of_numbers.is_a? Array
sum = array_of_numbers.inject(0) do |s,n|
raise unless n.is_a? Numeric
s += n
# Write a ASIR::Transport::HTTP class
# Using HTTP::Client for transport send_request and receive_response.
# Using WEBrick for transport on the receive_request and send_response.
# Use the Marshal Coder for the Transport.
require 'rubygems'
require 'webrick'
gem 'httpclient'
require 'httpclient'
require 'uri'
# Write a ASIR::Transport::HTTP class
# Using HTTP::Client for transport send_request and receive_response.
# Using WEBrick for transport on the receive_request and send_response.
# Use the Marshal Coder for the Transport.
require 'rubygems'
require 'webrick'
gem 'httpclient'
require 'httpclient'
require 'uri'
# Write a ASIR::Transport::HTTP class
# Using HTTP::Client for transport send_request and receive_response.
# Using WEBrick for transport on the receive_request and send_response.
# Use the Marshal Coder for the Transport.
require 'rubygems'
require 'webrick'
gem 'httpclient'
require 'httpclient'
require 'uri'
time ruby -X+O -e "h=[]; 10000.times {|n| h = [n,n*n]}; c=0; ObjectSpace.each_object {|o| c+=1 }; puts c; GC.start; c=0; ObjectSpace.each_object {|o| c+=1 }; puts c; puts h.inspect"
@baburdick
baburdick / rvm_each.rb
Created August 25, 2011 02:24
A workable rvm_each
#!/bin/sh
USAGE="Usage: $0 [gemset] command [args]"
# No args?:
if [ "$#" == "0" ]; then
echo "$USAGE"
exit 1
fi
@baburdick
baburdick / properly_disable_ri.rb
Created September 8, 2011 00:12
properly_disable_ri
# Hack to disable_referential_integrity for postgres users with sane
# permissions, uses deferral of constraints instead of disablement of the
# superuser-owned per-table triggers. Allows testing with fixtures which
# otherwise produce RI_ConstraintTrigger Errors.
#
# source: http://kopongo.com/2008/7/25/postgres-ri_constrainttrigger-error
# ref: https://github.com/matthuhiggins/foreigner/issues/61
module ActiveRecord
module ConnectionAdapters
@baburdick
baburdick / gem list -dl
Created September 21, 2011 18:24
Mac OS X Lion and rvm installs OLD!
$ gem list -dl
*** LOCAL GEMS ***
rake (0.9.2)
Author: Jim Weirich
Rubyforge: http://rubyforge.org/projects/rake
Homepage: http://rake.rubyforge.org
Installed at: /Users/bruceb/.rvm/gems/ruby-1.8.7-p352
@baburdick
baburdick / your_home_dir.rvmrc
Created October 7, 2011 23:37
Mac OS X Lion, MacPorts, and rvm installs
export rvm_path="$HOME/.rvm"
# Make this work with OS X Lion... for now...
if [[ `uname -v` =~ "Darwin Kernel Version 11" ]] ; then
export CC=/usr/bin/gcc-4.2
#export CC=/usr/bin/i686-apple-darwin11-gcc-4.2.1
fi
# Export compile flags for MacPorts:
if [ -d /opt/local/bin ] ; then
@baburdick
baburdick / gist:3902641
Created October 16, 2012 23:06
rvm install is asking to overwrite every file
$ rvm --version
rvm 1.16.13 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
$ rvm install 1.9.3
No binary rubies available for: osx/10.7/x86_64/ruby-1.9.3-p286.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Installing Ruby from source to: /Users/bruceb/.rvm/rubies/ruby-1.9.3-p286, this may take a while depending on your cpu(s)...
ruby-1.9.3-p286 - #downloading ruby-1.9.3-p286, this may take a while depending on your connection...
ruby-1.9.3-p286 - #extracting ruby-1.9.3-p286 to /Users/bruceb/.rvm/src/ruby-1.9.3-p286