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
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 |
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 titleize(str);str.split(" ").map {|w| w.capitalize}.join(" ");end | |
titleize("x-men: the sky is the limit") |
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
self | |
#=> main | |
self.class | |
#=> Object | |
self.object_id | |
#=> -595331298 | |
o = Object.new | |
#=> #<Object:0xb940af38> |
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
module HelloWorld | |
def show | |
puts "Hello World!" | |
end | |
end | |
puts "#{HelloWorld} is a module class." | |
puts "See? #{HelloWorld.class}" |
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
# 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 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
# 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 | |
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 Eot | |
attr_accessor :date, :lat, :lng, :attributes | |
def initialize attributes | |
@attributes = [] | |
attributes.each_key do |k| | |
self.send("#{k}=", attributes[k]) | |
@attributes << attributes[k] |
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
# 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) |
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 'sinatra/base' | |
require 'rack/flash' | |
require 'warden' | |
require 'slim' | |
require 'sequel' | |
require 'sqlite3' | |
DB = Sequel.sqlite | |
DB.create_table :users do | |
primary_key :id |
OlderNewer