Skip to content

Instantly share code, notes, and snippets.

@koduki
Created February 28, 2009 18:46
Show Gist options
  • Save koduki/72050 to your computer and use it in GitHub Desktop.
Save koduki/72050 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'webrick'
include WEBrick
module Termtter::Client
add_command /^serv\s*$/ do |m,t|
Thread.new do
serv = WEBrick::HTTPServer.new(:Port => 2110)
serv.mount_proc("/update") do |req, res|
call_commands req.query["text"]
res.set_redirect(HTTPStatus::MovedPermanently, '/')
end
serv.mount_proc("/") do |req, res|
statuses = public_storage[:log].reverse.map do |s|
<<EOS
<div id="#{s.id}">
<img src='#{s.user_profile_image_url}' />
#{s.user_screen_name} #{s.text} #{s.created_at}
</div>
EOS
end
res.body =<<EOS
<html>
<head><title>Termtter</title></head>
<body onLoad='setInterval(function(){location.reload(true)}, 300000)'>
<form action="/update">
What are you doing? <br/>
<input name="text" type="text" size="50"/>
<input type="submit" value="Update"/></form>
#{statuses.join}
</body>
</html>
EOS
end
trap("INT"){ server.shoutdown }
serv.start
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment