public
Description: 25lines chat system with Sinatra/Tokyo Cabinet
Homepage:
Clone URL: git://github.com/tt25/tinychat.git
tinychat / index.rb
100644 26 lines (23 sloc) 0.689 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require "rubygems"
require "sinatra"
require "tokyocabinet"
 
get("/") do
  @tc=TokyoCabinet::TDB::new
  @tc.open("casket.tct",TokyoCabinet::TDB::OREADER)
  q=TokyoCabinet::TDBQRY::new(@tc)
  q.setorder("timestamp",TokyoCabinet::TDBQRY::QONUMDESC)
  q.setlimit(10,(10 * ((params["page"]||1).to_i-1)))
  @posts=q.search
  @colors=%w!#933 #393 #339 #993 #939 #399 #903 #069 #390 #039!
  def h(str) Rack::Utils.escape_html(str); end
  ret=erb :index
  @tc.close
  ret
end
 
post("/") do
  tc=TokyoCabinet::TDB::new
  tc.open("casket.tct",TokyoCabinet::TDB::OWRITER | TokyoCabinet::TDB::OCREAT)
  tc.put(Time.now.to_i,params.merge({"timestamp" => Time.now.to_i}))
  tc.close
  redirect("/")
end