Skip to content

Instantly share code, notes, and snippets.

@DouglasAllen
DouglasAllen / Ch13TestStudents.java
Created May 3, 2014 12:11
Introduction to OOP with Java (5th Ed), McGraw-Hill Wu/Otani Chapter 13 Sample Program: Illustrate a sample processing of Student and its subclasses
package Chapter13;
/*
Introduction to OOP with Java (5th Ed), McGraw-Hill
Wu/Otani
Chapter 13 Sample Program: Illustrate a sample processing of
Student and its subclasses
def titleize(str);str.split(" ").map {|w| w.capitalize}.join(" ");end
titleize("x-men: the sky is the limit")
@DouglasAllen
DouglasAllen / irb_session.rb
Last active August 29, 2015 14:13
Classes are Objects
self
#=> main
self.class
#=> Object
self.object_id
#=> -595331298
o = Object.new
#=> #<Object:0xb940af38>
module HelloWorld
def show
puts "Hello World!"
end
end
puts "#{HelloWorld} is a module class."
puts "See? #{HelloWorld.class}"
# Create a SQLite3 db file from a SQL structure file.
require "yaml"
require "active_record"
if $0 == $PROGRAM_NAME
include ActiveRecord::Tasks
file = "./config/database.yml"
config = YAML.load_file(file)
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
#run DemoApp::Application
app = Rack::Builder.new do
class Eot
attr_accessor :date, :lat, :lng, :attributes
def initialize attributes
@attributes = []
attributes.each_key do |k|
self.send("#{k}=", attributes[k])
@attributes << attributes[k]
# File lib/rack/sendfile.rb, line 112
def call(env)
status, headers, body = @app.call(env)
if body.respond_to?(:to_path)
case type = variation(env)
when 'X-Accel-Redirect'
path = F.expand_path(body.to_path)
if url = map_accel_path(env, path)
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
@DouglasAllen
DouglasAllen / gist:1a30612c975820d4316e
Last active August 29, 2015 14:27 — forked from jamiehodge/gist:1327195
Warden and Sinatra example
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