Skip to content

Instantly share code, notes, and snippets.

View blairanderson's full-sized avatar

Blair Anderson blairanderson

View GitHub Profile
@blairanderson
blairanderson / JStwitter.rb
Created June 7, 2012 03:22
This is a JStwitter client lesson
require 'jumpstart_auth'
class JSTwitter
attr_reader :client
def run
puts "Welcome to the JSL Twitter Client!"
command = ""
while command != "q"
printf "enter command: "
@blairanderson
blairanderson / home-buying-101
Created October 25, 2012 03:23
Checklist for Buying a Home
Home Buying Checklist
Property Address
Asking Price
Real Estate Taxes
The Neighborhood
Near Work
Near Schools
Near Shopping
Near Expressways
Near Public Transportation
(1..100).each do |each|
if each % 3 == 0 and each % 5 == 0
puts "FizzBuzz"
elsif each % 3 == 0
puts "Fizz"
elsif each % 5 == 0
puts "Buzz"
else
puts each
end
@blairanderson
blairanderson / gist:4719918
Created February 6, 2013 03:12
to create an array of hashes
def parse_file(filename)
@people = []
@contents.each do |row|
person = {}
person[:id] = row[0]
person[:regdate] = row[:regdate]
person[:first_name] = clean_first_name(row[:first_name])
person[:last_name] = clean_last_name(row[:last_name])
person[:email] = clean_email(row[:email_address])
person[:phone] = clean_phone(row[:homephone])
@blairanderson
blairanderson / gist:4736331
Last active December 12, 2015 07:28
Before and After!
#------------------BEFORE----------------------------
def width #column width for 'queue print'
first_name_length = [12]
last_name_length = [12]
email_length = []
city_length = []
street_length = []
@queue.each do |person|
first_name_length << person[:first_name].length
last_name_length << person[:last_name].length
@blairanderson
blairanderson / router.rb
Created February 27, 2013 21:46
registration
require 'rubygems'
require 'sinatra'
require 'json'
require 'sequel'
require 'pg'
require 'haml'
require 'shotgun'
get '/' do
haml :index
@blairanderson
blairanderson / route.rb
Created February 28, 2013 00:18
look at this
def process_params(params)
@identifier = params[:identifier]
@rooturl = params[:rootUrl]
if missing_parameters?(params)
halt 400, "Bad Request! missing required parameters"
else
"#{{identifier: @identifier}.to_json}"
end
end
@blairanderson
blairanderson / Guardfile
Last active December 14, 2015 09:49
My favorite guardfile
guard 'rspec', :cli => "--color --format nested --fail-fast --drb" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
@blairanderson
blairanderson / query.rb
Last active December 15, 2015 04:59 — forked from pjb3/query.rb
Create a ruby hash by chaining methods.
class Query
def initialize
@hash = {}
end
def method_missing(name, *args)
value = args.length > 0 ? args.first : true
@hash.merge!(name => value)
self
end
@blairanderson
blairanderson / series.rb
Created March 25, 2013 15:32
series warmup
class Series
attr_reader :digits
def initialize(input)
@digits = input.split("").map{|i| i.to_i}
end
def slices(input)
slices = []
digits.count.times do |i|
slices << digits[i...i+input]