You are on page 1of 42

Sinatra

Zero & XDite


惡搞、惡搞、惡搞
Make Ur Calendar Icon
Yes, Make our own!
秘技
上上下下左右左右BA
UUDDLRLRBA
自我介紹
• Full-time student
itsZero • Works in hypo
• http://itszero.org/
• http://twitter.com/itszero
山寨傑洛
我不會說日文也不會兩段跳...
這可以幹嘛?
Sinatra + RMagick
#!/usr/bin/ruby
require 'rubygems'
require 'sinatra'
require 'RMagick'
include Magick
 
FONTPATH = File.dirname(File.expand_path(__FILE__)) + "/
Aller/Aller_Bd.ttf"
 
get '/' do
  open('public/index.html').read
end
 
get '/gen_icon' do
  headers['Content-Type'] = 'image/png'
 
[some nasty RMagick code...]
 
  canvas.format = 'png'
  canvas.to_blob
end
 
http://makeyourcalicon.heroku.com
http://tr.im/j9DH
Another Example
Oh, Dear Mr IE6...
PHP / CodeIgniter

無法顯示中文

?
幾千行 debug 個鬼啊...
by XDite
require ‘twitter_search’
require 'rubygems'
require 'sinatra'
require 'twitter_search'
get '/' do
@client = TwitterSearch::Client.new
'politweets'
@results = @client.query :q => '@MrIE6'
erb :home
end
10 行搞定 !
db & paginate
activerecord
will_paginate
多寫了 40 行
Deployment!
Passenger

• (可以想成) Ruby 的 mod_php


• Supports Rack!
Rack
Handler Adapters
• Mongrel • Camping
• WEBrick • Sinatra
• FastCGI • Merb
• Passenger •...
•...
Sinatra on Passenger
1 require 'rubygems'
2 require 'sinatra'
3
4 Sinatra::Application.default_options.merge!(
5 :run => false,
6 :environment => :production
7 )
8
9 require 'make_your_cal_icon.rb'
10 run Sinatra::Application
11

=> config.ru
Java on GAE
JRuby + Sinatra + GAE
URLFetching
Bumble
Will_paginate
http://gae.mrie6.com
http://tr.im/j9DK

You might also like