Skip to content

Instantly share code, notes, and snippets.

@aharpole
aharpole / gist:11385660
Last active August 29, 2015 14:00
CSV.parse unexpected behavior
1.9.3-p545 :002 > headers = "col,is,cool"
=> "col,is,cool"
1.9.3-p545 :003 > csv = CSV.parse(headers,{headers:true})
=> #<CSV::Table mode:col_or_row row_count:1>
1.9.3-p545 :004 > tworows = "#{headers}\nabc,def,ghi"
=> "col,is,cool\nabc,def,ghi"
1.9.3-p545 :005 > other_csv = CSV.parse(tworows,{headers:true})
=> #<CSV::Table mode:col_or_row row_count:2>
1.9.3-p545 :006 > csv.headers
=> [] #I expect this to be ["col", "is", "cool"]
@aharpole
aharpole / atom_builder_example.rb
Created February 22, 2014 03:59
Using Rails Atom builder with non-AR objects
atom_feed do |feed|
feed.title "Some title"
feed.updated Time.now
@feed_entries.each do |item|
feed.entry item, {id:42, url:"http://this_object.com/url"} do |entry|
#code for entry here
end
end
end
@aharpole
aharpole / README.md
Last active August 29, 2015 13:56
CC validation refactoring exercise

You need RSpec installed to run these tests.

gem install rspec
rspec credit_card_spec.rb

The CreditCard class is currently working but the code is in need of some refactoring. Refactor it (ensuring that the specs continue to pass) and when you are finished, share the gist with us.

Feel free to include in your gist a README containing an explanation of your refactorings and any thoughts or philosophies behind what you did. We're particularly interested in understanding what you personally consider to be good code, and this exercise will help us see into that a bit.

@aharpole
aharpole / test_missing_integer.rb
Created February 10, 2014 21:28
Fullscreen candidate Ruby exercise
require "minitest/autorun"
#To run the test, make sure you have the minitest gem installed and just type ruby test_missing_integer.rb at the prompt
#after downloading this file.
#To submit the exercise, put the code into a gist and share with us.
#this method takes an array with 99 elements. The elements are the integers 1 through 100, but one is missing.
#The elements aren't sorted in any particular order.
#This method returns the number that's missing.
@aharpole
aharpole / rspec_example.rb
Created January 11, 2014 05:46
rspec example
thing.should have_cookie
@aharpole
aharpole / rspec_predicate_matchers_1.rb
Created January 11, 2014 05:45
RSpec Predicate Matchers code snippet
def has_cookie?
true
end
@aharpole
aharpole / query.sql
Created January 11, 2014 05:43
Putting records at the front of a query result
select * from forum_topics where forum_id=42 order by (sticky_topic=true) desc
@aharpole
aharpole / empty_commit.sh
Last active January 2, 2016 21:59
an example of doing an empty commit
git commit —allow-empty -m 'Look ma, no diffs!'
@aharpole
aharpole / mailto-cash.html
Created December 12, 2013 22:05 — forked from veganstraightedge/mailto-cash.html
Sample mailto link to send me money
<a href="mailto:[email protected][email protected]&subject=$1">Give Aaron some MONAY</a>
def do_error_prone_thing
toss_peanut_and_try_catching_it_in_your_mouth
rescue PeanutNotCaught => e
casually_pretend_it_did_not_happen
end