Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Arnell voidlock

View GitHub Profile
View snippet.rb
module Merb
class Worker
# :api: private
attr_accessor :thread
class << self
# ==== Returns
# Merb::Worker:: instance of a worker.
#
View snippet.rb
class Photo
include DataMapper::Resource
has n, :taggings
has n, :tags, :through => :taggings, 'taggings.deleted_at' => nil
end
class Tag
include DataMapper::Resource
View file.rb
require 'benchmark'
require 'logger'
logger = Logger.new("/dev/null")
logger.level = Logger::INFO
puts "Simple Strings"
Benchmark.bmbm do |x|
x.report("string form") {
100_000.times do
View file.rb
logger.info "some message"
logger.info { "some message" }
View file.rb
require 'benchmark'
require 'logger'
logger = Logger.new("/dev/null")
logger.level = Logger::INFO
puts "Small string substition"
array = []
1.upto(10) {|i| array << i}
View file.rb
require 'benchmark'
require 'logger'
logger = Logger.new("/dev/null")
logger.level = Logger::INFO
puts "Inspecting 1,000 item array"
array = []
1.upto(1_000) {|i| array << i}
View file.rb
require 'benchmark'
require 'logger'
logger = Logger.new("/dev/null")
logger.level = Logger::INFO
puts "Inspecting 1,000,000 item array"
array = []
1.upto(1_000_000) {|i| array << i}
View file.rb
require 'benchmark'
require 'logger'
require 'date'
logger = Logger.new("/dev/null")
logger.level = Logger::INFO
array = []
1.upto(10) {|i| array << i}
View gist:289104
require "rubygems"
require "redis"
redis = Redis.new
redis.delete "foo" # cleanup
puts "SETNX COMMAND:"
puts "Should be true:"
puts redis.set_unless_exists("foo", 1)
puts
View snippet.rb
require "geoip_city"
require "geoip"
require "benchmark"
db = '/usr/local/share/GeoIP/GeoIPCity.dat'
ip = '24.24.24.24'
geoip_c = GeoIP::City.new(db)
geoip_city = GeoIPCity::Database.new(db)
You can’t perform that action at this time.