Skip to content

Instantly share code, notes, and snippets.

View kenn's full-sized avatar

Kenn Ejima kenn

View GitHub Profile
TWEETS = RingBuffer.new(10)
STREAMING_URL = 'http://stream.twitter.com/1/statuses/sample.json'
def handle_tweet(tweet)
return unless tweet['text']
TWEETS.push(tweet)
end
EM.schedule do
http = EM::HttpRequest.new(STREAMING_URL).get :head => { 'Authorization' => [ 'USERNAME', 'PASSWORD' ] }
require 'rubygems'
require 'sinatra'
require 'em-http'
require 'json'
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
require 'tweets'
run Sinatra::Application
class Comet < Sinatra::Base
register Sinatra::Async
@@pool = []
aget '/observe' do
@@pool.push self
end
aget '/notify' do
# Patching MySQL:
#
require 'mysql'
class Mysql::Result
def encode(value, encoding = "utf-8")
String === value ? value.force_encoding(encoding) : value
end
def each_utf8(&block)
#!/usr/bin/env ruby
require 'rubygems'
require 'appscript'
require 'yaml'
include Appscript
class TermInit
def initialize(project=nil)
> require 'socket'
> s=TCPSocket.new('localhost',27017)
=> #<TCPSocket:fd 3>
> require 'net/ping'
> s=TCPSocket.new('localhost',27017)
Errno::ECONNREFUSED: Connection refused - connect(2)
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run_excluding :online unless Net::Ping::TCP.new('www.google.com',80,1).ping?
end
#!/usr/bin/env ruby
def report
output = `ktremotemgr report -host 127.0.0.1`
{}.tap{|h| output.split("\n").map{|i| i.split(': ') }.each{|i| h[i[0]] = i[1] } }
end
hash = report
last_get, last_set, last_remove = hash['cnt_get'].to_i, hash['cnt_set'].to_i, hash['cnt_remove'].to_i
def to_hash(options={})
@to_hash ||= {
:id => self.id,
:created_at => self.created_at.iso8601
}.tap do |h|
if options[:details]
h.update(:user => self.user.to_hash(options.update(:owner => true)),
) if options[:details]
end
end