Skip to content

Instantly share code, notes, and snippets.

@pillowfactory
pillowfactory / gist:1331639
Created November 1, 2011 19:28
ConfBot Base Functionality
* Schedule
* Who's speaking now?
* Who's speaking next?
* When's lunch?
* What's the Google map URL?
* Current Speaker's SpeakerRate URL?
* Last Speaker's SpeakerRate URL?
* Relay non-commands to convore (just an idea)
describe ".import" do
context "with no mapping block" do
context "given a single record" do
it "returns an empty collection" do
CsvMapper.import(nil).should be_empty
end
end
context "given a collection with only one record" do
it "returns an empty collection" do
CsvMapper.import([['John', 'Doe']]).should be_empty
@pillowfactory
pillowfactory / new_csv_mapper.rb
Created April 6, 2011 04:52
Work in progress example of desired use/functionality of CsvMapper
# Import with CSV Mapper
CsvMapper.import('path') do
start_at_row 1 # Skip the first row (probably a header row)
stop_at_row 10 # Stop parsing on the 10th row
map_to Business do
business_name # Parse to String by default
net_worth :type => Float # Parse column value Float
net_worth.to_f # Parse column value Float
# Given a CSV record format like:
# john,doe,blonde,26
CsvMapper.import('blah') do
map_to Person
first_name # maps to string by default
last_name # maps to string by default
_SKIP_ # skip the 'hair color' column
@pillowfactory
pillowfactory / gist:828394
Created February 15, 2011 22:27
How bad of practice is it to do something like this?
require 'rubygems'
require 'active_support'
module CustomName
def self.included(base)
base.alias_method_chain :name, :update
end
def name_with_update
['custom', name_without_update].join(' ')
jQuery('#label-switch').change(function(){
var showLabels = (jQuery(this).is(':checked') ? 1 : 0);
})
def possessify(word)
result = word.to_s.dup
if word.empty?
result
else
result.ends_with?('s') ? result << "'" : result << "'s"
end
end
function rvm_require_ruby
{
if ! rvm list strings | grep -q "^$1" ; then
echo "ERROR: Requires Ruby Version: '$1'"
return 1
fi
return 0
}
function rvm_require_ruby {
if [ "`rvm list | grep $1`" = "" ]
then
echo "ERROR: Requires Ruby Version: $1"
exit
fi
}
function rvm_use {
rvm_require_ruby $1
rvm use $1
# Given
class Business
attr_accessor :name, :net_worth
attr_accessor :line_1, :line_2, :city, :state, :zip
end
# Import with CSV Mapper
CsvMapper.import('path_to_file.csv') do
map_to Business
start_at_row 1 # Skip the first row (probably a header row)