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
<%= stylesheet_link_tag :global, :cache => (Rails.env == 'development' ? nil : 'global') %> |
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 ActiveRecord | |
module ConnectionAdapters | |
class AbstractAdapter | |
protected | |
# Turn: | |
# User Load (6.3ms) SELECT * FROM "users" | |
# Into: | |
# User Load /app/views/_partial.erb:27 (6.3ms) in `_app_views_partial_erb` SELECT * FROM "users" |
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
# Problem: the query you want to build to bring back the right objects is complicated. When | |
# you try and eagerly load the objects you need it all breaks and goes to shit. This often | |
# happens if you are using "group" or "count", for instance. If you don't eagerly load the | |
# objects you need then you have an n+1 (or worse) problem as you make an additional query | |
# for each object you use. | |
# So try doing the query in two parts: 1) get the primary key for each object you need, | |
# 2) eagerly load all the objects that match. | |
# Grab the ids. Don't worry about eagerly loading. The important thing is that it doesn't |
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
deployment: | |
staging: | |
branch: master | |
commands: | |
- git push [email protected]:yakify-ci.git: | |
timeout: 600 | |
dependencies: | |
pre: |
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"') |
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
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
# 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
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
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%") |
OlderNewer