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
| using System; | |
| using System.Diagnostics; | |
| namespace SunriseCalculator | |
| { | |
| public class SolarInfo | |
| { | |
| public double SolarDeclination { get; private set; } | |
| public TimeSpan EquationOfTime { get; private set; } | |
| public DateTime Sunrise { get; private set; } |
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
| project :test => :shoulda, :renderer => :haml, :stylesheet => :sass, :script => :jquery, :orm => :activerecord | |
| #default routes | |
| APP_INIT = <<-APP | |
| get "/" do | |
| "Hello World!" | |
| end | |
| get :about, :map => '/about_us' do | |
| render :haml, "%p This is a sample blog created to demonstrate the power of Padrino!" |
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
| .DS_Store | |
| *.log |
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 'sinatra' | |
| require 'sinatra_warden' | |
| require 'warden' | |
| require 'rack/flash' | |
| require 'haml' | |
| User = Struct.new(:id, :name, :email) |
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
| class MyApplication < Sinatra::Base | |
| use Rack::Session::Cookie | |
| use Warden::Manager do |manager| | |
| manager.default_strategies :password | |
| manager.failure_app = MyApplication | |
| end | |
| Warden::Manager.serialize_into_session{ |user| user.id } |
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 'warden' | |
| require 'sinatra' | |
| require 'cgi' | |
| class LoginManager < Sinatra::Base | |
| Warden::Manager.serialize_into_session{|id| id } | |
| Warden::Manager.serialize_from_session{|id| id } | |
| def call(env) |
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
| 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
| require 'webrick' | |
| require 'erb' | |
| template = <<TEMPLATE | |
| <html> | |
| <head> | |
| <title>Ruby as PHP</title> | |
| </head> | |
| <body> | |
| <h1>Loop</h1> |
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 'sinatra/base' | |
| require 'rack/flash' | |
| require 'warden' | |
| require 'slim' | |
| require 'sequel' | |
| require 'sqlite3' | |
| DB = Sequel.sqlite | |
| DB.create_table :users do | |
| primary_key :id |
NewerOlder