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 ErrorPages < Ambulance::App | |
# idea 0: rails' rescue_from | |
rescue_from CanCan::AccessDenied, ActiveRecord::NotFound, ActionController::RoutingError do |exception| | |
render file: 'public/404.html', status: :not_found, layout: false | |
end | |
# idea 1: | |
routes ActiveRecord::NotFound, | |
ActionController::RoutingError, to: 404 |
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 NullUser | |
User.reflections.each do |key, value| | |
name = key.to_s | |
if value.collection? | |
eval <<-RUBY | |
def #{name} | |
#{value.klass}.none | |
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
nothing.o: nothing.c |
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
source 'https://rubygems.org' | |
gem 'benchmark-ips' | |
gem 'activesupport' | |
gem 'jbuilder' | |
gem 'rabl' | |
gem 'oj' |
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
gem "kaminari" | |
gem "twitter-bootstrap-rails", :group => :assets |
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
source 'https://rubygems.org' | |
ruby '1.9.3' | |
-gem 'rails', '3.2.8' | |
+gem 'rails', git: "git://github.com/rails/rails.git", branch: "3-2-stable" | |
gem 'thin' | |
gem 'pg' | |
... |
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
# lib/jbuilder_ext/object_methods.rb | |
module JbuilderExt | |
module ObjectMethods | |
def __class__ | |
(class << self; self; end).superclass | |
end | |
def is_a?(klass) | |
klass == __class__ | |
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 Object | |
def tap(method = nil, *args, &block) | |
return super() if method.nil? && args.empty? && block_given? | |
public_send(method, *args) | |
self | |
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
@client = Koala::Facebook::API.new(access_token) | |
# Check if the user likes the given url or not. | |
url = "http://example.com" | |
@client.fql_query("SELECT url FROM url_like WHERE user_id=me()").map do |like| | |
like["url"] | |
end.include?(url) | |
# Get how many likes the url got. | |
@client.fql_query("SELECT like_count FROM link_stat WHERE url=\"#{url}\"")["like_count"] |
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
yuki@ubuntu:~$ ab -n 1000 -c 100 http://randb2012.misscon.net/ | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking randb2012.misscon.net (be patient) | |
Completed 100 requests | |
Completed 200 requests | |
Completed 300 requests | |
Completed 400 requests |