This file contains hidden or 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 | |
# script/whitespace | |
# | |
# Strips whitespace from any files modified in git | |
# Also: | |
# - converts tabs to spaces | |
# - ensures a single newline at the end | |
class WhitespaceProcessor | |
def self.process(code) |
This file contains hidden or 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 TestConstraint | |
def matches?(*args) | |
Rails.logger.info("TestConstraint") | |
end | |
end | |
TestApp::Application.routes.draw do | |
constraints(TestConstraint.new) do | |
resources :posts | |
end |
This file contains hidden or 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 A | |
def protected_method | |
puts "success" | |
end | |
protected :protected_method | |
end | |
class B < A | |
def public_method |
This file contains hidden or 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
# Split unicode characters from supplementary planes (such as iOS 5 emoji) into surrogate pairs | |
# so that node.js can parse them. | |
def split_into_surrogate_pairs(text) | |
text.gsub(/[\u{10000}-\u{10ffff}]/) do |match| | |
codepoint = match.codepoints.first | |
pair = [0xD7C0 + (codepoint >> 10), 0xDC00 | codepoint & 0x3FF] | |
pair.pack("U*") | |
end | |
end |
This file contains hidden or 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 test_method_explicit_return | |
raise "This should bubble up" | |
ensure | |
return "No problem here" | |
end | |
def test_method_implicit_return | |
raise "This should bubble up" | |
ensure | |
"No problem here" |
This file contains hidden or 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 -rubygems | |
abort "Usage: links.rb USERNAME [days ago]" unless ARGV.length > 0 | |
trap("SIGINT") { puts; abort } | |
require "twitter" | |
require "active_support/core_ext" | |
username = ARGV[0] | |
since = ARGV[1] ? ARGV[1].to_i.days.ago.to_date : 1.year.ago.to_date |
This file contains hidden or 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! RSpec(args) | |
execute ":silent ! run-in-terminal.applescript 'rspec " . a:args . " %'" | |
endfunction | |
" command-R to run a focused spec | |
map <D-R> :call RSpec("-l " . <C-r>=line('.')<CR>)<CR> | |
" command-r to run all specs | |
map <D-r> :call RSpec("")<CR> |
This file contains hidden or 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
// Parses a text file of numbers and outputs each number with its locale and | |
// counts of numbers found per each locale. | |
// | |
// Usage: | |
// scala -classpath ./lib/offline-geocoder-1.9.jar:./lib/libphonenumber-4.5.jar ./locator.scala <input_file> | |
import java.util.Locale | |
import scala.io.Source | |
import scala.collection.mutable.Map | |
import com.google.i18n.phonenumbers._ |
This file contains hidden or 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 "java" | |
class Item | |
include java.util.concurrent.Delayed | |
def initialize(deliver_at) | |
@deliver_at = deliver_at | |
end | |
def get_delay |
This file contains hidden or 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 "java" | |
require "lib/vendor/libphonenumber-4.5.jar" | |
require "lib/vendor/offline-geocoder-1.9.jar" | |
class PhoneNumber | |
US_DIALING_PREFIX = "011" | |
US_COUNTRY_NAME = "US" | |
UNKNOWN = "Unknown" | |
import import java.util.Locale |