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
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' ] } |
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' | |
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
require 'tweets' | |
run Sinatra::Application |
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 Comet < Sinatra::Base | |
register Sinatra::Async | |
@@pool = [] | |
aget '/observe' do | |
@@pool.push self | |
end | |
aget '/notify' do |
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
# 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) |
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'appscript' | |
require 'yaml' | |
include Appscript | |
class TermInit | |
def initialize(project=nil) |
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 'socket' | |
> s=TCPSocket.new('localhost',27017) | |
=> #<TCPSocket:fd 3> | |
> require 'net/ping' | |
> s=TCPSocket.new('localhost',27017) | |
Errno::ECONNREFUSED: Connection refused - connect(2) |
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
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 |
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
#!/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 |
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
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 |