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
| class String | |
| BASE62_PRIMITIVES = { | |
| "0" => 0, "1" => 1, "2" => 2, "3" => 3, "4" => 4, "5" => 5, "6" => 6, "7" => 7, "8" => 8, "9" => 9, | |
| "A" => 10, "B" => 11, "C" => 12, "D" => 13, "E" => 14, "F" => 15, "G" => 16, "H" => 17, "I" => 18, "J" => 19, | |
| "K" => 20, "L" => 21, "M" => 22, "N" => 23, "O" => 24, "P" => 25, "Q" => 26, "R" => 27, "S" => 28, "T" => 29, | |
| "U" => 30, "V" => 31, "W" => 32, "X" => 33, "Y" => 34, "Z" => 35, "a" => 36, "b" => 37, "c" => 38, "d" => 39, | |
| "e" => 40, "f" => 41, "g" => 42, "h" => 43, "i" => 44, "j" => 45, "k" => 46, "l" => 47, "m" => 48, "n" => 49, | |
| "o" => 50, "p" => 51, "q" => 52, "r" => 53, "s" => 54, "t" => 55, "u" => 56, "v" => 57, "w" => 58, "x" => 59, | |
| "y" => 60, "z" => 61 | |
| } |
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 'pp' | |
| $stdout.sync = true | |
| class KeyboardHandler < EM::Connection | |
| include EM::Protocols::LineText2 | |
| def post_init | |
| print "> " |
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
| #Newbie programmer | |
| def factorial(x): | |
| if x == 0: | |
| return 1 | |
| else: | |
| return x * factorial(x - 1) | |
| print factorial(6) | |
| #First year programmer, studied Pascal |
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 'evma_httpserver' | |
| class HttpHandler < EM::Connection | |
| include EM::HttpServer | |
| @@listeners = [] | |
| def process_http_request |
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 'sinatra' | |
| require 'em-http' | |
| require 'json' | |
| require 'lib/ring_buffer' | |
| TWEETS = RingBuffer.new(10) | |
| def handle_tweet(tweet) | |
| return unless tweet['text'] |
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
| class RingBuffer < Array | |
| def initialize(size) | |
| @max = size | |
| super(0) | |
| end | |
| def push(object) | |
| shift if size == @max | |
| super | |
| end |
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
| gem install thin | |
| gem install rack | |
| gem install sinatra | |
| gem install em-http-request | |
| gem install json |
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
| $ ruby tweets.rb | |
| == Sinatra/0.9.6 has taken the stage on 4567 for development with backup from Thin | |
| >> Thin web server (v1.2.7 codename No Hup) | |
| >> Maximum connections set to 1024 | |
| >> Listening on 0.0.0.0:4567, CTRL+C to stop |
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
| get '/tweets' do | |
| content_type 'text/html', :charset => 'utf-8' | |
| TWEETS.map {|tweet| "<p><b>#{tweet['user']['screen_name']}</b>: #{tweet['text']}</p>" }.join | |
| end |
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
| class RingBuffer < Array | |
| def initialize(size) | |
| @max = size | |
| super(0) | |
| end | |
| def push(object) | |
| shift if size == @max | |
| super | |
| end |
OlderNewer