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
if Config::CONFIG['host'] =~ /mswin/i | |
def socket_active? | |
return false if not @sock or @sock.closed? | |
begin | |
@sock.write("\0") | |
Timeout.timeout(0.1){ @sock.read } # TODO make 0.1 configurable | |
rescue Exception | |
false | |
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
# RubyRedis is an alternative implementation of Ruby client library written | |
# by Salvatore Sanfilippo. | |
# | |
# The aim of this library is to create an alternative client library that is | |
# much simpler and does not implement every command explicitly but uses | |
# method_missing instead. | |
require 'socket' | |
class RedisClient |
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 Contact < ActiveRecord::Base | |
belongs_to :customer | |
belongs_to :project | |
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
require 'benchmark' | |
OK = "OK".freeze | |
Ok = "OK".freeze | |
Benchmark.bm(30) do |b| | |
b.report('upcase constant') do | |
5_000_000.times { 'OK' == OK } | |
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
# Refactoring proposal for ActiveSupport bytes calculations | |
require "benchmark" | |
ONE = 1 | |
module Bytes | |
def bytes | |
self | |
end | |
alias :byte :bytes |
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
require "benchmark" | |
CONDITION = false | |
ONE = 1 | |
Benchmark.bm(30) do |b| | |
b.report("if not true") do | |
counter = 0 | |
5_000_000.times { counter += ONE if !CONDITION } | |
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
require "benchmark" | |
require "rubygems" | |
require "activesupport" | |
module Enumerable | |
def else(&block) | |
self.respond_to?('empty?') && self.empty? ? yield : self | |
end | |
def else_try(&block) |
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
require "benchmark" | |
TIMES = 5_000_000 | |
HASH = { "foo" => "1000", "bar" => "2000" } | |
Benchmark.bm(30) do |b| | |
b.report("old implementation") do | |
TIMES.times do |i| | |
keys = %w(foo bar) | |
result = HASH.inject({}) do |hash, value| |
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 User | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
has n, :subscriptions | |
has n, :feeds, :through => :subscriptions, :mutable => true | |
end | |
class Subscription |