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
| 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 | |
| # |
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
| 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 | |
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
| 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) |
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
| # 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 |
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
| 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 |
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 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 |
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
| 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 |
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
| 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 | |
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
| require 'net/dns/resolver' | |
| # Custom Domain | |
| # | |
| # Require net-dns gem | |
| # | |
| # A Rack middleware to to resolve the custom domain to original subdomain | |
| # for your multi telent application. | |
| # | |
| # It's all transperant to your application, it performs cname lookup and |
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
| #-- | |
| # Copyright (c) 2009 Szymon Kurcab [email protected]> | |
| # | |
| # Permission is hereby granted, free of charge, to any person obtaining | |
| # a copy of this software and associated documentation files (the | |
| # "Software"), to deal in the Software without restriction, including | |
| # without limitation the rights to use, copy, modify, merge, publish, | |
| # distribute, sublicense, and/or sell copies of the Software, and to | |
| # permit persons to whom the Software is furnished to do so, subject to | |
| # the following conditions: |