This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ... | |
function! OpenRelatedCoffeeFile(action) | |
let action = a:action | |
if match(expand('%'), 'app/assets') != -1 | |
exec action . " " . expand("%:s?app/assets?spec?:s?.js.coffee?_spec.js.coffee?") | |
else | |
exec action . " " . expand("%:s?^spec?app/assets?:s?_spec??") | |
endif | |
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cohabitant < ActiveRecord::Base | |
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i | |
validates_presence_of :department, :location, :contact_name, :contact_email | |
validates :contact_email, :format => { :with => VALID_EMAIL_REGEX } | |
has_and_belongs_to_many :notifications | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@cohabitant = Cohabitant.find(2) | |
@cohabitant.notification_ids | |
# => [11, 13, 14] | |
@cohabitant.notifications.each do |n| | |
puts n.created_at.strftime("%A, %B %e, %Y") + " by #{n.user.name}" | |
end | |
# => Tuesday, June 26, 2012 by New Guy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@notification = Notification.find(11) | |
@notification.cohabitant_ids | |
# => [2, 3, 6] | |
@notification.cohabitants.each { |c| puts c.contact_name } | |
# => Cool Lady | |
# => Cool Guy | |
# => Super Awesome Dude |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateCohabitantsNotifications < ActiveRecord::Migration | |
def change | |
create_join_table :cohabitants, :notifications | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateCohabitantsNotifications < ActiveRecord::Migration | |
def change | |
create_table :cohabitants_notifications, :id => false do |t| | |
t.string :cohabitant_id, :null => false | |
t.string :notification_id, :null => false | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Resource < ActiveRecord::Base | |
module Types | |
ACTIVE = 'active' | |
CANCELLED = 'cancelled' | |
CEASED = 'ceased' | |
DITCHED = 'ditched' | |
MEDIA = 'media' | |
ONE_TIME = 'one time' | |
ARCHIVED = 'archived' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
/usr/local/Cellar/bison/3.0.4/bin/bison lispcalc.y && gcc -lm -o lispcalc lispcalc.tab.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- [Design an *iterative* process for multiplying to integers that] uses a | |
-- logarithmic number of steps. | |
double :: Integer -> Integer | |
double x = x + x | |
halve :: Integer -> Integer | |
halve x = x `div` 2 | |
multiply :: Integer -> Integer -> Integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ... | |
-- ... | |
-- [Assume your language doesn't have a multiplication function or | |
-- table. Given `double` and `half` functions,] design a | |
-- multiplication procedure that uses a logarithmic number of steps. | |
double :: Integer -> Integer | |
double x = x + x | |
halve :: Integer -> Integer |