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 'bundler/setup' | |
require 'fiber' | |
require 'csv' | |
require 'pp' | |
require 'eventmachine' | |
def a_slow_api_call(row) | |
sleep 0.3 | |
row.collect(&:to_i).inject(&:+) |
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
#routes | |
match 'posts/search(/:search)' => 'posts#search', as: 'post_search' | |
#model | |
def self.search(search) | |
search_condition = "%" + search + "%" | |
find(:all, :conditions => ['title LIKE ? OR content LIKE ?', search_condition, search_condition]) | |
end | |
#controller | |
def search |
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 self.cached_scope_for_user(user_id) | |
Rails.cache.fetch "scope_for_user_#{user_id}" do | |
results = Model.where("user_id = ?)", user_id) | |
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
class Contact < ActiveRecord::Base | |
after_save :expire_contact_all_cache | |
after_destroy :expire_contact_all_cache | |
def self.all_cached | |
Rails.cache.fetch('Contact.all') { all } | |
end | |
def expire_contact_all_cache | |
Rails.cache.fetch('Contact.all', :force => true) do |
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
# Puppet configurations | |
class base { | |
## Update apt-get ## | |
exec { 'apt-get update': | |
command => '/usr/bin/apt-get update' | |
} | |
} |
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
var Browser = { | |
getAgent: function() | |
{ | |
return navigator.userAgent.toLowerCase(); | |
}, | |
isMac: function(userAgent) | |
{ | |
var agent = userAgent || this.getAgent(); | |
return !!agent.match(/mac/i); |