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
require 'coffee-script' | |
code = DATA.read | |
magic_code = <<_EOJS_ | |
_magic_code = ($) -> | |
#{code} | |
_magic_code(jQuery); | |
_EOJS_ | |
puts CoffeeScript.compile magic_code | |
__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
def hash_smash bench_size, bm | |
hash_1 = {} | |
hash_2 = {} | |
1.upto(bench_size) do |n| | |
k = "val#{n}" | |
hash_1[k] = { | |
name: k, | |
total: n * 2, | |
} |
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 NihMoney | |
def nih_money_units money | |
if money.cents % money.currency.subunit_to_unit == 0 | |
money.cents / money.currency.subunit_to_unit | |
else | |
money.cents.to_f / money.currency.subunit_to_unit | |
end | |
end | |
def nih_humanized_money_with_symbol money |
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 Challenge | |
def user_with_highest stat = :distance | |
User.with_highest stat, period, users | |
end | |
def period | |
start_date..end_date | |
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 Symbol | |
def with(arg) | |
lambda { |obj| obj.send(self, arg) } | |
end | |
end | |
tweedledee = Class.new.new | |
tweedledum = Object.new | |
heroes = [tweedledum, tweedledee] |
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
def cross values, n = 3 | |
Array.new(n, values).inject do |acc, i| | |
acc.product(i).map(&:flatten) | |
end | |
end | |
require 'set' | |
describe do | |
it "should cross itself" do |
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 | |
# post-checkout - git post checkout hook script | |
# | |
# This script will update the contents of .git/CURRENT_BRANCH with the name of | |
# the current branch after a checkout. | |
# | |
# Use it with rerun to restart foreman on branch changes. | |
# Bonus feature: sanity checks your Gemfile using $ bundle check | |
# | |
# Start foreman like this to watch CURRENT_BRANCH: |
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 | |
# testfor - gen test for class | |
# | |
# USAGE | |
# | |
# Generate a test skeleton for the Person class | |
# $ testfor Person | |
require 'active_support' | |
require 'active_support/core_ext/string/inflections' |
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
# Note minitest 2 doesn't run out of assertions so that test case would fail | |
gem 'minitest', '~> 4' | |
require 'minitest/unit' | |
require 'minitest/mock' | |
require 'minitest/autorun' | |
def do_nothing_with 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
begin | |
fail NoMethodError, "foo" | |
rescue StandardError => e | |
puts "NoMethodError is rescued by StandardError: #{e.inspect}" | |
rescue NoMethodError => e | |
puts "NoMethodError is not rescued by StandardError: #{e.inspect}" | |
p e | |
end | |
puts "NoMethodError is not a StandardError" unless NoMethodError.is_a? StandardError |
OlderNewer