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
#!/usr/bin/env ruby | |
# Submission for Ruby Christmas Contest (http://contest.dimelo.com/) | |
# Author: Adrien Jarthon (http://adrienjarthon.com) | |
data = {"login" => "defunkt", | |
"followers" => 4674, | |
"commits" => 8901, | |
"repositories" => [{"watchers" => 79, "forks" => 9, "name" => "choice"}, | |
{"watchers" => 28, "forks" => 1, "name" => "mapreducerb"}, |
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
repository = 5 | |
repository = 1 if repository.watchers < 5 && repository.forks < 5 | |
repository += 50 if repository.watchers > 20 | |
repository += 50 if repository.forks > 20 | |
repository = 100 if repository.watchers > 50 && repository.forks > 50 | |
commit = 1 | |
follower = 2 |
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
foo # NameError: undefined local variable or method `foo' for main:Object | |
foo = "bar" unless defined?(foo) | |
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
class MyMiddleWare | |
REDIRECT = [302, { 'Content-Type' => 'text/html; charset=utf-8', 'Location' => '/admin' }, []] | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
if <blabla> | |
REDIRECT |
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 ActiveSupport | |
module Cache | |
class AtomicMemCacheStore < MemCacheStore | |
ALREADY_STORED = "STORED\r\n" | |
cattr_accessor :grace_period | |
@@grace_period = 3.minutes | |
def read(key, options = nil) | |
result = super | |
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
# Author: Pieter Noordhuis | |
# Description: Simple demo to showcase Redis PubSub with EventMachine | |
# | |
# Update 7 Oct 2010: | |
# - This example does *not* appear to work with Chrome >=6.0. Apparently, | |
# the WebSocket protocol implementation in the cramp gem does not work | |
# well with Chrome's (newer) WebSocket implementation. | |
# | |
# Requirements: | |
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby |
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
it "should detect text_part and remain consistent" do | |
m = Mail.new(:content_type => 'mixed/multipart') | |
p = Mail::Part.new(:content_type => 'mixed/alternative') | |
p.add_part(Mail::Part.new(:content_type => 'text/html', :body => 'HTML TEXT')) | |
p.add_part(Mail::Part.new(:content_type => 'text/plain', :body => 'PLAIN TEXT')) | |
a = Mail::Part.new(:content_type => 'text/plain', :body => 'signature') | |
m.add_part(p) | |
m.add_part(a) | |
m.text_part.body.decoded.should == 'PLAIN TEXT' | |
m.to_s |
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
#This is a Rack middle to release the connections checkout from the connection pool | |
#in a rack multithreaded environment | |
# This is mandatory outside of ActionController, as ActiveRecord request you to handle the | |
# release of the connections into the pool. If you don't do it, every n thread (where n is | |
# the AR connection pool size) will be stucked waiting for a 5s AR empty pool timeout | |
module Rack | |
module ActiveRecord | |
def initialize(app) | |
@app = app | |
end |