Skip to content

Instantly share code, notes, and snippets.

View weppos's full-sized avatar

Simone Carletti weppos

View GitHub Profile
@weppos
weppos / capistrano_database_yml.rb
Created July 27, 2008 10:04
Provides a couple of tasks for creating the database.yml configuration file dynamically when deploy:setup is run.
#
# = Capistrano database.yml task
#
# Provides a couple of tasks for creating the database.yml
# configuration file dynamically when deploy:setup is run.
#
# Category:: Capistrano
# Package:: Database
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2010 The Authors
@weppos
weppos / capistrano_passenger_deploy.rb
Created July 29, 2008 14:59
Provides tasks for deploying a Rails application with Passenger (aka mod_rails).
#
# = Capistrano Passenger deploy tasks
#
# Provides tasks for deploying a Rails application with Passenger (aka mod_rails).
#
# Category:: Capistrano
# Package:: Passenger
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2008 The Authors
# License:: MIT License
@weppos
weppos / capistrano_fastcgi_deploy.rb
Created July 29, 2008 15:37
Provides tasks for deploying a Rails application with FastCGI.
#
# = Capistrano FastCGI deploy tasks
#
# Provides tasks for deploying a Rails application with FastCGI.
#
# Category:: Capistrano
# Package:: FastCGI
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2008 The Authors
# License:: MIT License
@weppos
weppos / title_helper.rb
Created August 3, 2008 20:46
Provides helpers for managing page title.
#
# = Rails Title Helper
#
# Provides helpers for managing page title.
#
# Category:: Rails
# Package:: Helpers
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2008 The Authors
# License:: MIT License
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !^id=([0-9]*)$
RewriteRule .* - [env=send_x_robot:true]
Header set X-Robots-Tag "noindex" env=send_x_robot
#
# = SuperStruct
#
# SuperStruct is an enhanced version of the Ruby Standard library <tt>Struct</tt>.
#
# Compared with the original version, it provides the following additional features:
# * ability to initialize an instance from Hash
# * ability to pass a block on creation
#
# You can read more at http://www.simonecarletti.com/blog/2010/01/ruby-superstruct/
require 'ipaddr'
require 'benchmark'
class IPAddr
def self.valid_ipv4?(addr)
if /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/ =~ addr
return $~.captures.all? {|i| i.to_i < 256}
end
false
end
require 'rubygems'
require 'benchmark'
require 'nokogiri'
TIMES = 50_000
doc = Nokogiri::XML(File.new("test.xml"))
node = doc.at_xpath("./strategies")
Benchmark.bmbm do |x|
module CacheKey
extend self
def expirable(range = :minute, time = ::Time.current)
key = case range
when :always
::Time.current
when :never
nil
when :second
MongoDb vs PostgreSQL (single table with 777,229 records)
--------------------------------------------------------
# Number of Records in the table
=> 777229
# Size of the Table
# PostgreSQL (Data + Indexes)
+----------------+