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
More Codez |
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
activty stream |
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
#!/usr/bin/env ruby | |
# Usage: ./encode-test /path/to/encode.c | |
require 'fileutils' | |
def directory(path) | |
path = File.expand_path(path) | |
if File.directory?(path) | |
path |
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 User < ActiveRecord::Base | |
has_many :tasks | |
def self.with_flagged_comments | |
includes(:task).merge(Task.with_flagged_comments) | |
end | |
end | |
class Task < ActiveRecord::Base | |
belongs_to :user |
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
isFunction = (obj) -> | |
toString.call(obj) == '[object Function]' | |
Object.prototype.delegate = () -> | |
args = Array.prototype.slice.call(arguments); | |
[methods, options] = [args[0..(args.length - 2)], args[(args.length - 1)]] | |
for method in methods | |
delegation = (method, delegatedMethod) -> | |
@[method] = -> |
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 UserSearch | |
attr_reader :name, :email | |
def initialize(options = {}) | |
@name = options[:name] | |
@email = options[:email] | |
end | |
def results | |
scope = User.scoped |
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
describe UserSearch do | |
describe "#results" do | |
it "returns all Users" do | |
user = User.create! | |
expect(described_class.new.results).to eq([user]) | |
end | |
context "a :name option is provided" do | |
it "returns Users with a matching first name" do | |
user = User.create!(first_name: "William") |
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 User < ActiveRecord::Base | |
attr_accessible :email, :first_name, :last_name | |
def self.name_matching(name) | |
where("lower(first_name) LIKE lower(:name) | |
OR lower(last_name) LIKE lower(:name)", name: name + "%") | |
end | |
def self.email_matching(email) | |
where("lower(email) LIKE lower(?)", email + "%") |
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
describe User do | |
describe ".name_matching" do | |
let!(:user) { User.create!(first_name: "Gaius", last_name: "Baltar") } | |
it "scopes to Users with matching first names" do | |
expect(User.name_matching("Gaius")).to eq([user]) | |
end | |
it "scopes to Users with matching last names" do | |
expect(User.name_matching("Baltar")).to eq([user]) |
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 UserSearch | |
attr_reader :name, :email | |
def initialize(options = {}) | |
@name = options[:name] | |
@email = options[:email] | |
end | |
def results | |
scope = User.scoped |
OlderNewer