First add your twitter username and password. Then server.rb and once it's started open websocket.html in your browser. You should see some tweets appear. If not take a look at the javascript console.
  
    
      This file contains hidden or 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 'rubygems' | |
| require 'net/http' | |
| require 'uri' | |
| require 'json' | |
| class GoogleClosure | |
| class Error < RuntimeError; end | |
| HOST = URI.parse('http://closure-compiler.appspot.com/compile') | 
  
    
      This file contains hidden or 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 'rubygems' | |
| require 'eventmachine' | |
| require 'em-websocket' | |
| class CustomWSConnection < EventMachine::WebSocket::Connection | |
| def trigger_on_message(msg) | |
| send "Pong: #{msg}" | |
| end | |
| def trigger_on_open | |
| send "Hello Client!" | 
  
    
      This file contains hidden or 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 'rubygems' | |
| require 'benchmark' | |
| require 'stringio' | |
| Benchmark.bm do |x| | |
| n = 1000000 | |
| x.report('string') do | |
| string = '' | |
| appended = 'b' * 100 | |
  
    
      This file contains hidden or 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 EventMachine | |
| module WebSocket | |
| class MaskedString < String | |
| def read_mask | |
| raise "Too short" if bytesize < 4 # TODO - change | |
| @masking_key = String.new(self[0..3]) | |
| end | |
| def slice_mask | |
| slice!(0, 4) | 
  
    
      This file contains hidden or 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 'em-hiredis' | |
| EM.run { | |
| redis = EM::Hiredis.connect | |
| redis.set('foo', 'value') | |
| redis.watch('foo') { | |
| puts "Watching - try changing key foo within 1s" | |
| EM.add_timer(1) { | 
  
    
      This file contains hidden or 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 'em-hiredis' | |
| EM.run { | |
| require 'em-hiredis' | |
| redis = EM::Hiredis.connect | |
| # If you pass a block to subscribe it will be called whenever a message | |
| # is received on this channel | |
| redis.pubsub.subscribe('foo') { |msg| | |
| p [:received_foo, msg] | 
  
    
      This file contains hidden or 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
    
  
  
    
  | source :rubygems | |
| gem 'em-websocket' | |
| gem 'sinatra' | 
  
    
      This file contains hidden or 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 'eventmachine' | |
| require 'em-hiredis' | |
| require 'fiber' | |
| class Cache | |
| include EM::Deferrable | |
| def initialize(key) | |
| $redis.get(key) { |v| | |
| @value = v | 
  
    
      This file contains hidden or 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 'em-hiredis' | |
| class EM::Hiredis::Client | |
| class Transaction | |
| include EM::Deferrable | |
| def initialize(redis) | |
| @redis = redis | |
| end | |