Skip to content

Instantly share code, notes, and snippets.

Avatar

Kenn Ejima kenn

  • San Francisco
View GitHub Profile
View gist:100446
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
}
View simple_em_udp_client.rb
require 'eventmachine'
require 'pp'
$stdout.sync = true
class KeyboardHandler < EM::Connection
include EM::Protocols::LineText2
def post_init
print "> "
View Evolution of a Python programmer.py
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
View gist:321423
require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
class HttpHandler < EM::Connection
include EM::HttpServer
@@listeners = []
def process_http_request
View gist:338237
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']
View gist:338240
class RingBuffer < Array
def initialize(size)
@max = size
super(0)
end
def push(object)
shift if size == @max
super
end
View gist:338316
gem install thin
gem install rack
gem install sinatra
gem install em-http-request
gem install json
View gist:338320
$ 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
View gist:338329
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
View gist:338330
class RingBuffer < Array
def initialize(size)
@max = size
super(0)
end
def push(object)
shift if size == @max
super
end