Skip to content

Instantly share code, notes, and snippets.

@yankov
yankov / gist:3038384
Created July 3, 2012 08:02
generate redis protocol
# refactored version from http://redis.io/topics/mass-insert
def gen_redis_proto(*cmd)
cmd.inject("*#{cmd.length}\r\n") {|acc, arg|
acc << "$#{arg.length}\r\n#{arg}\r\n"
}
end
@yankov
yankov / gist:3029115
Created July 1, 2012 17:55
Stop EM when all iterations are complete
# is there a good pattern for this routine?
EM.synchrony do
size = keys.count
counter = 0
# check if each iteration was completed
EM::add_periodic_timer( 2 ) do
next unless counter == size
require 'em-synchrony'
require 'redis'
require 'redis/distributed'
require 'digest'
require 'redis/connection/synchrony'
EM.synchrony do
# this one fast
redis_hosts = ["redis://localhost:6379/1", "redis://localhost:6378/1"]
@yankov
yankov / gist:3000252
Created June 26, 2012 23:51
js pattern for async calls
var future = function(d) {
var obj = {};
obj.val = 0;
setTimeout(function(){ obj.val=d;}, 5000);
return obj;
}
var result = future(4);
# do gem install web-socket-ruby first
require 'web_socket'
require 'json'
client = WebSocket.new("ws://localhost:8080/eventbus/websocket")
message = {:name => "tim", :age => 29}
envelope = {:type => "send",
:address => "some-address",
require 'vertx'
server = Vertx::HttpServer.new;
sockJSServer = Vertx::SockJSServer.new(server)
sockJSServer.bridge({'prefix' => '/eventbus'}, [] )
server.listen(8080)
<script type='text/javascript' src='http://cdn.sockjs.org/sockjs-0.1.min.js'></script>
<script type='text/javascript' src='vertxbus.js'></script>
<script type="text/javascript">
var eb = null;
window.onload = function() {
eb = new vertx.EventBus("http://localhost:8080/eventbus");
require 'redis'
require 'face'
# fb user_id of the user that needs to be find on match.com
FB_UID = '11111@facebook.com'
# show all profiles whith the given confidence of recognition
ACCURACY = 30
redis = Redis.new
require 'nokogiri'
require 'eventmachine'
require 'em-http-request'
require 'em-redis'
PAGES = 140
EM.run {
@redis = EM::Protocols::Redis.connect
require 'rubygems'
require 'open-uri'
response = open(YOUR_URL_OF_REUEST)
p response.read