Skip to content

Instantly share code, notes, and snippets.

View kivanio's full-sized avatar
🏠
Working from home

Kivanio Barbosa kivanio

🏠
Working from home
View GitHub Profile
@kivanio
kivanio / gist:191947
Created September 23, 2009 12:27 — forked from mattetti/gist:191596
# For this experiment you need to have 2 instances of couchdb 0.10
# one running on port 5984 and one on port 5983
require 'rubygems'
require 'couchrest'
server = CouchRest.new("http://127.0.0.1:5984")
server2 = CouchRest.new("http://127.0.0.1:5983")
begin server.database('replication-test-1').delete!; rescue; nil; end
begin server2.database('replication-test-2').delete!; rescue; nil; end
DB_A = server.database!('replication-test-1')
module Rack
class GoogleAnalytics
TRACKING_CODE = <<-EOCODE
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("{{ID}}");
require "net/http"
# Example Usage:
#
# use Rack::Proxy do |req|
# if req.path =~ %r{^/remote/service.php$}
# URI.parse("http://remote-service-provider.com/service-end-point.php?#{req.query}")
# end
# end
#
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
Warden::Strategies.add(:bcrypt) do
def valid?
params[:username] || params[:password]
end
def authenticate!
return fail! unless user = User.first(:username => params[:username])
if user.encrypted_password == params[:password]
success!(user)
# Removendo porcarias
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
# Git
git :init
file(".gitignore") do
<<-EOF
@kivanio
kivanio / album.rb
Created October 26, 2009 01:01 — forked from rklemme/album.rb
require 'yaml'
Track = Struct.new :title, :duration
# An Album represents an audio medium which has title,
# interpret, a pause duration between tracks and a list
# of individual tracks.
class Album
attr_reader :title, :interpret, :pause
module AttributesSort
def self.included(receiver)
Array.class_eval do
def do_sort(options = {})
type = self.first.class
type.instance_eval do
def do_attributes_sort(collection, options={})
attributes = options[:sort_by].inject("["){|attribute_string, attribute| attribute_string << "object.#{attribute},"} + "]"
collection.sort_by{|object| eval(attributes)}
end
require 'nokogiri'
require 'pstore'
#
# Rack::DomainSprinkler
#
# Modifies outgoing HTML markup so that common static assets like script source
# files, images, and stylesheets will be served from one of a number of domains
# rather than just a single one in order to improve parallelization of resource
@kivanio
kivanio / rbl.rb
Created November 6, 2009 10:57 — forked from anonymous/rbl.rb
require 'rubygems'
require 'net/dns/resolver'
DEFAULT_SERVERS = [ 'dnsbl.ahbl.org' ]
module Rack
class RBL
# List of RBL servers to check against
attr_accessor :servers