#Thread-safe JRuby on Rails HOW-TO
###With the help of Warbler, Apache Tomcat and JNDI Connection Pool
###Read those posts before anything else otherwise you'll find yourself in a very lonely place:
| # Simple bijective function | |
| # Basically encodes any integer into a base(n) string, | |
| # where n is ALPHABET.length. | |
| # Based on pseudocode from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047#742047 | |
| ALPHABET = | |
| "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//) | |
| # make your own alphabet using: | |
| # (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle.join |
| # simple HTTPServer: | |
| # useful to test your pages/api calls! | |
| class HTTPServer | |
| def initialize(port, body) | |
| require 'socket' | |
| @server = Thread.new do | |
| server = TCPServer.open port | |
| loop do |
| # Author: Pieter Noordhuis | |
| # Description: Simple demo to showcase Redis PubSub with EventMachine | |
| # | |
| # Update 7 Oct 2010: | |
| # - This example does *not* appear to work with Chrome >=6.0. Apparently, | |
| # the WebSocket protocol implementation in the cramp gem does not work | |
| # well with Chrome's (newer) WebSocket implementation. | |
| # | |
| # Requirements: | |
| # - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby |
#Thread-safe JRuby on Rails HOW-TO
###With the help of Warbler, Apache Tomcat and JNDI Connection Pool
###Read those posts before anything else otherwise you'll find yourself in a very lonely place: