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 ApplicationController < ActionController::Base | |
# Rather than return a 500 (internal server error) let's just say we can't | |
# find what they are looking for. Typically, this is when someone hits one | |
# of our valid routes but asks for the .xml format or something. | |
rescue_from ActionController::UnknownFormat, with: :raise_unknown_format | |
def raise_unknown_format | |
render plain: 'Unknown Format', status: :not_found | |
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
### Keybase proof | |
I hereby claim: | |
* I am billhorsman on github. | |
* I am billhorsman (https://keybase.io/billhorsman) on keybase. | |
* I have a public key whose fingerprint is D96D 6222 E6CB 8A78 E03F A1A0 6C5C E69B 98D5 42B5 | |
To claim this, I am signing this object: |
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
# I didn't know that this test made the captured variable available as local variables. | |
if /(?<x>\d+)/ =~ "foo 123 bar" | |
puts x | |
end | |
# => 123 |
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
# This ensures that jQuery is reinitialized after the page:change event | |
gem 'jquery-turbolinks' |
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 | |
# This is how I see most wildcard searches done. It matches anywhere, including | |
# in the middle of a word. E.g. for "John Doe" | |
# "jo" => yes | |
# "do" => yes | |
# "oe" => yes | |
# | |
def self.search_anywhere(query) | |
where("LOWER(users.first_name) LIKE :query OR LOWER(users.last_name) LIKE :query OR LOWER(users.email) LIKE :query", query: "%#{query}.downcase%") |
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 | |
attr_accessor :first_name, :last_name | |
def name | |
out = [first_name, last_name].join(' ').strip | |
out =~ /\A([a-z\s'\-]*|[A-Z\s'\-]*)\Z/ ? out.titleize : out | |
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
# Using instance variables | |
describe "Foo" do | |
before do | |
@foo = FactoryGirl.create :foo | |
@bar = FactoryGirl.create :bar | |
end | |
it "sends message" do | |
assert @foo.msg("pow!") | |
# @bar is not used in this test |
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
namespace :code do | |
desc "Parse with ruby_parser and list files producing errors" | |
task :parse do | |
bad = [] | |
Dir.glob("**/*.rb").each do |filename| | |
if system("ruby_parse_extract_error #{filename} > /dev/null 2>&1") | |
print "." | |
else | |
bad << filename |
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
## The quick-and-nasty CVE-2013-0156 Heroku inspector! | |
## Originally brought to you by @elliottkember with changes by @markpundsack @ Heroku | |
## Download and run using: | |
## ruby heroku-CVE-2013-0156.rb | |
apps = `heroku list 2> /dev/null`.split("\n") | |
apps = apps.map {|app| | |
case app.strip | |
when /^===/ | |
# Some "heroku apps" lines have === formatting for grouping. They're not apps. |
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
$form.fileupload | |
dataType: "json" | |
done: (e, data) -> | |
result = if data.result? | |
# XHR (as used by, say, Chrome) gives you a simple JSON object | |
data.result | |
else | |
# iframe (as used by IE) gives you text back that you'll want to parse manually) | |
# Urgh. UTF8 value (passed by Rails form) causes JSON to fall over. Crappy solution on next line. | |
data = JSON.stringify(data).replace(/"name":"utf8","value":"[^"]*"/, '"name":"utf8","value":"REMOVED"') |
NewerOlder