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
    
  
  
    
  | # in routes.rb | |
| match "/app" => MyRackApp.build | |
| class MyRackApp | |
| self.build | |
| Rack::Auth::Basic.new(new) do |user, pass| | |
| [user, pass] == %w( john snow ) | |
| 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 benchmark | |
| times = 86400 | |
| Benchmark.bm do |b| | |
| b.report("object") do | |
| hash = {} | |
| times.times { hash[Date.today] ||= {} } | |
| puts hash.size | |
| end | |
| b.report("string") do | |
| hash = {} | 
  
    
      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_config = { :namespace => 'sidekiq', :url => YAML.load_file("#{Rails.root}/config/redis.yml")[Rails.env] } | |
| Sidekiq.configure_server do |config| | |
| config.redis = redis_config | |
| end | |
| Sidekiq.configure_client do |config| | |
| config.redis = redis_config | |
| 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
    
  
  
    
  | namespace :log do | |
| desc "Downloads application logs to ./log/deploy/<RAILS_ENV>/<TIMESTAMP>/" | |
| task :fetch, :roles => :app do | |
| source = "#{shared_path}/log/#{rails_env}.log*" | |
| files_per_host = {} | |
| run "ls #{source}" do |channel, stream, data| | |
| files_per_host[channel[:host]] = data.split("\n") | |
| end | |
| destination = File.join('log', 'deploy') | 
  
    
      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
    
  
  
    
  | public void code(PrintStream s) { | |
| e1.code(s); | |
| CgenSupport.emitFetchInt(CgenSupport.ACC, CgenSupport.ACC, s); | |
| CgenSupport.emitPush(CgenSupport.ACC, s); | |
| e2.code(s); | |
| CgenSupport.emitFetchInt(CgenSupport.ACC, CgenSupport.ACC, s); | |
| CgenSupport.emitLoad(CgenSupport.T1, 1, CgenSupport.SP, s); | |
| CgenSupport.emitAdd(CgenSupport.ACC, CgenSupport.T1, CgenSupport.ACC, s); | |
| CgenSupport.emitAddiu(CgenSupport.SP, CgenSupport.SP, 4, s); | |
| // Now that result of e1 + e2 is in the accumulator we | 
  
    
      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
    
  
  
    
  | module Definition | |
| def element(name) | |
| attr_accessor name | |
| define_method name.to_s+'?' do | |
| !!name # bound to local variable, not calling method. but !!send(name) is ugly | |
| end | |
| end | |
| end | |
| class Kitty | 
  
    
      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 Api::Post | |
| def self.first | |
| etag = $cache.read('data:etag') | |
| response = fetch_first(etag) | |
| if response == :not_modified | |
| puts 'cache HIT' | |
| else | |
| puts 'cache MISS' | |
| $cache.write 'data:etag', response.first | |
| $cache.write 'data', response.last | 
  
    
      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 'nokogiri' | |
| class Cache | |
| def initialize | |
| @store = {} | |
| end | |
| def read key | |
| @store[key] | |
| 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 Post < ActiveResource::Base | |
| end | |
| class PostsController | |
| def index | |
| json = Post.all :if_modified => true do |posts| | |
| posts.to_json | |
| 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_find_or_initialize_updates_collection_size_only_once | |
| number_of_clients = companies(:first_firm).clients_of_firm.size | |
| client = companies(:first_firm).clients_of_firm.find_or_initialize_by_name("name" => "Another Client") | |
| client.save | |
| assert_equal number_of_clients + 1, companies(:first_firm).clients_of_firm.size | |
| end |