This file contains 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
def many n | |
n.times do |i| | |
yield i | |
end | |
end | |
many 9 do |i| | |
puts "#{i+1} Mississippi" | |
end |
This file contains 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
puts "Enter your local longitude." | |
lng = gets.strip.to_f | |
hours = lng / 15.0 | |
puts "Your mean solar transit is #{12 - hours} hours UTC." | |
puts "Do you want the true solar transit time?" | |
puts "Then gem install equationoftime or eot" | |
puts "see: 'https://rubygems.org/gems/equationoftime'" | |
This file contains 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 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 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 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 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 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 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' | |
host = 'swancygnet' | |
path = '/index.html' | |
port = 9292 | |
aSession = Net::HTTP.new( host='localhost', port=80, proxy=nil, proxy_port=nil ) | |
aSession.get( path, headers=nil, dest="" ) | |
response = Net::HTTP.get_response(host, path, port) |
This file contains 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' | |
class Simple < WEBrick::HTTPServlet::AbstractServlet | |
def do_GET request, response | |
status, content_type, body = do_stuff_with request | |
response.status = status | |
response['Content-Type'] = content_type | |
response.body = body | |
end |