Skip to content

Instantly share code, notes, and snippets.

# Replace Inheritance with Delegation
# http://refactoring.com/catalog/replaceInheritanceWithDelegation.html
# class Roster < Array
# attr_accessor :title
# def to_s
# out = "#{title}\n"
# each do |item|
# out += "#{item}\n"
@shepmaster
shepmaster / privacy_filter.rb
Created December 12, 2011 04:15 — forked from steveklabnik/privacy_filter.rb
A spec for a filter
class PrivacyFilter
class << self
def filter(controller)
@controller = controller
first_article? or administrator? or user?
end
def first_article?
@controller.params[:id] == 1
['a','b','c'].each do |char|
it "returns xxx for #{char}" do
process(char).should == 'xxx'
end
end
var x = function(userid) {
return function(resp) {
var user_name = JSON.parse(resp)["full_name"];
console.log(userid);
build += "<li><a class='user' id='user-" + userid + "' href='#show-" + userid + "'>" + user_name + "</a></li>";
remaining -= 1;
if (remaining == 0) {
make_users_list(obj, build);
hide_spinner();
$("#login").hide();
require 'spec_helper'
describe Api::V1_2::TokensController do
def parsed_response(response)
JSON.parse(response.body)
end
describe "POST create" do
let(:params) { {} }
@shepmaster
shepmaster / spec.rb
Last active December 20, 2015 05:39 — forked from enricostano/spec.rb
describe 'conversations/base' do
subject do
Timecop.freeze(10.minutes.ago) do
FactoryGirl.create(:conversation)
end
end
before :each do
assign(:object, subject)
@shepmaster
shepmaster / anagram.rb
Last active December 22, 2015 06:18 — forked from alekst/anagram
class AnagramTest < MiniTest::Unit::TestCase
class Anagram
def initialize(word)
@word = word
# If you create the array here, then the results will be
# collected over multiple calls to `match`. Not sure if that is
# intended or not, so I'll assume it's ok to change.
end
@shepmaster
shepmaster / anagram.rb
Last active December 22, 2015 07:18 — forked from alekst/gist:6436407
class AnagramTest < MiniTest::Unit::TestCase
class Anagram
def initialize(word)
@word = word
@anagram = Array.new
end
def match(candidates)
candidates.each do |candidate|
if candidate.turning_into_letters == @word.turning_into_letters
@shepmaster
shepmaster / dna.rb
Last active December 22, 2015 11:28 — forked from alekst/dna.rb
class DNATest < MiniTest::Unit::TestCase
# You don't have to put your classes inside of the test case, but it
# doesn't hurt for these examples
class DNA
def initialize(string)
@string = string
# You can provide a default value for hashes. This also avoids
# hardcoding the letters here.
@counts = Hash.new(0)
def new
@transaction_fee = current_company.transaction_fee
@transaction_cost = current_company.transaction_cost
@withdrawal = current_company.withdrawals.new
@available_amount = Withdrawal.available_amount(current_company.id)
@transactions = current_company.transactions.where("payment_status = 'ready_to_pay'")
end