This file contains 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 'sinatra' | |
require 'redis' | |
require 'json' | |
require 'date' | |
class String | |
def &(str) | |
result = '' | |
result.force_encoding("BINARY") |
This file contains 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 'grim' | |
require 'thread' | |
class ThreadPool | |
def initialize(size = 5) | |
@jobs = Queue.new | |
@size = size | |
@pool = Array.new(@size) do |i| | |
Thread.new do | |
Thread.current[:id] = i |
This file contains 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 'securerandom' | |
require 'eventmachine' | |
require 'happening' | |
EM.run do | |
count = 10 | |
pending = count | |
count.times do |index| | |
on_error = Proc.new do |http| |
This file contains 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
a = 10 | |
def test(): | |
print a # 10 |
This file contains 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 'benchmark' | |
class A | |
def method_missing name, *argv | |
super unless name =~ /^test$/ | |
"hello world" | |
end | |
end | |
class B |
This file contains 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 'benchmark' | |
Benchmark.bm do |x| | |
names = ["matz", "rossum", "ryal", "ritchie", "brendan"] | |
n = 50000 | |
x.report "method missing" do | |
class Array | |
def method_missing name, *argv | |
super unless name =~ /^sort_by_(\w+)_(asc|desc)$/ |
This file contains 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 FiboUsingArray | |
include Singleton | |
def initialize | |
@fib = [1, 1] | |
end | |
def [](n) | |
if n < @fib.size then | |
@fib[n] |
This file contains 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 FiboUsingDictionary | |
include Singleton | |
def initialize | |
@fib = { 0 => 1, 1 => 1 } | |
end | |
def [](n) | |
return @fib[n] if @fib.include? n | |
@fib[n] = self[n -1] + self[n - 2] |
This file contains 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
package objsets | |
// real tweet data, collected on Oct 1 | |
object TweetData { | |
val gizmodo = """[ | |
{ "user": "gizmodo", "text": "Kindle Paperwhite Review: Forget Everything Else, This Is the E-Reader You Want http://t.co/737W6aNC", "retweets": 51.0 }, | |
{ "user": "gizmodo", "text": "These new Apple patents give a sneak peek at what future iPhone cameras might have in store. http://t.co/0YT9rjxp", "retweets": 49.0 }, | |
{ "user": "gizmodo", "text": "Ever wonder why the sky is dark at night? Here's your answer. http://t.co/eTKxkcaE", "retweets": 86.0 }, | |
{ "user": "gizmodo", "text": "The head of Homeland Security stays secure by just not using email, at all. http://t.co/W6KAFEUu", "retweets": 37.0 }, | |
{ "user": "gizmodo", "text": "This is how graphene will grow the flexible semiconductors of the future: http://t.co/IoEvuxp4", "retweets": 43.0 }, |
This file contains 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
package patmat | |
import common._ | |
/** | |
* Assignment 4: Huffman coding | |
* | |
*/ | |
object Huffman { |
OlderNewer