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
@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
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
" ... | |
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
old_instance_methods = Object.instance_methods | |
require 'minitest/spec' | |
$infected_assertions = Object.instance_methods - old_instance_methods | |
module Kernel | |
def expect object | |
Expect.new object | |
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
REMOTE_SHA=`git rev-parse origin/my_branch` | |
PULL_NUMBER=`git ls-remote origin | grep $REMOTE_SHA | grep pull | perl -n -e '/pull\/(.*)\/head/ && print $1'` | |
git ls-remote origin | grep refs\/pull\/$PULL_NUMBER\/merge | awk '{ print $1 };' |
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
module LoggingObserver | |
def self.included base | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def new *args | |
@instance = super | |
override_methods | |
@instance |
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
module FromHashable | |
def initialize hash | |
@hash = hash | |
set_ivars | |
set_methods | |
set_as_hash | |
end | |
private |
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
SELECT DISTINCT main_genres.* | |
FROM main_genres | |
JOIN movie_genres ON movie_genres.genre_id = main_genres.genre_id | |
JOIN netflix_instant_movies ON netflix_instant_movies.id = movie_genres.netflix_instant_movie_id | |
JOIN rotten_tomatoes ON rotten_tomatoes.netflix_instant_movie_id = netflix_instant_movies.id | |
JOIN netflix_instant_movie_imports ON netflix_instant_movie_imports.netflix_instant_movie_id = netflix_instant_movies.id | |
JOIN netflix_instant_imports ON netflix_instant_imports.id = netflix_instant_movie_imports.netflix_instant_import_id | |
WHERE netflix_instant_imports.id = | |
(SELECT id | |
FROM netflix_instant_imports |
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
module Curryable | |
def def_function &block | |
@function = block | |
end | |
def call arg | |
unless @function | |
raise StandardError, 'must define a function with def_function' | |
end |