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 Slug | |
| class << self | |
| def [](slug) | |
| redis.hget(hash, slug) | |
| end | |
| private | |
| def redis |
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
| > $redis["foo"] = "bar" | |
| => "bar" | |
| > $redis["foo"] | |
| => "bar" | |
| > $redis["baz"] | |
| => nil | |
| > $redis.del("foo") | |
| => 1 | |
| > $redis["foo"] | |
| => nil |
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
| > $redis.set("foo", "bar") | |
| => "OK" | |
| > $redis.get("foo") | |
| => "bar" | |
| > $redis.get("baz") | |
| => nil | |
| > $redis.del("foo") | |
| => 1 | |
| > $redis.get("foo") | |
| => nil |
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
| $redis = Redis::Namespace.new("my_app", :redis => Redis.new) |
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
| gem 'redis' | |
| gem 'redis-namespace' |
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
| # app/controllers/post_controller.rb | |
| class PostsController < ApplicationController | |
| before_filter :find_post | |
| protected | |
| def find_post | |
| @post = Post.find(Slug[params[:id]]) | |
| rescue ActiveRecord::RecordNotFound |
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
| # app/controllers/posts_controller.rb | |
| class PostsController < ApplicationController | |
| before_filter :find_post | |
| protected | |
| def find_post | |
| unless @post = Post.where(:slug => params[:id]).first | |
| # what do we do 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
| class FilterAuth < ::Rack::Auth::Basic | |
| def initialize(app, options = { }, realm=nil, &authenticator) | |
| super(app, realm, &authenticator) | |
| @ip_filter = ::Rack::Access.new(app, options) | |
| end | |
| def call(env) | |
| # only need to do auth if the ip filter blocks the request | |
| response = @ip_filter.call(env) |
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
| MyApp::Application.config.middleware.use FilterAuth, "/" => [ "127.0.0.1" ] do |username, password| | |
| username == CORRECT_USERNAME && password == CORRECT_PASSWORD | |
| 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
| lambda { |c| 99.downto(0) { |n| puts n == 0 ? "" << c[29] << c[30] << c[0] << c[37] << c[30] << c[32] << c[23] << c[0] << c[21] << c[30] << c[34] << c[34] << c[28] << c[23] << c[33] << c[0] << c[30] << c[24] << c[0] << c[21] << c[23] << c[23] << c[32] << c[0] << c[30] << c[29] << c[0] << c[34] << c[25] << c[23] << c[0] << c[36] << c[20] << c[28] << c[28] << c[1] : "" << (n < 10 ? "" : c[6 + (n / 10)]) << c[6 + (n % 10)] << c[0] << c[21] << c[30] << c[34] << c[34] << c[28] << c[23] << (n > 1 ? c[33] : "") << c[0] << c[30] << c[24] << c[0] << c[21] << c[23] << c[23] << c[32] << c[0] << c[30] << c[29] << c[0] << c[34] << c[25] << c[23] << c[0] << c[36] << c[20] << c[28] << c[28] << c[5] << c[5] << c[5] << c[0] << (n < 10 ? "" : c[6 + (n / 10)]) << c[6 + (n % 10)] << c[0] << c[21] << c[30] << c[34] << c[34] << c[28] << c[23] << (n > 1 ? c[33] : "") << c[0] << c[30] << c[24] << c[0] << c[21] << c[23] << c[23] << c[32] << c[1] << c[5] << c[5] << c[5] << c[0] << c[19] << c[20] << c[27] << c[23] << c[0] << c[30] << c |