Skip to content

Instantly share code, notes, and snippets.

<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");
# 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",
@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);
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: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
@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
function A(name) {
this.name = name;
}
A.prototype.b = function(lastName) {
this.lastName = lastName;
console.log(this.name + " " + this.lastName);
}
a1 = new A("Howard");
a = new A();
b = new a.B();
// how in 'b' have a refference to 'a'?
@yankov
yankov / gist:4230948
Last active October 13, 2015 17:28
Creating new Scala project with sbt
mkdir project1
cd project1
sbt
set name := "project1"
set version := "1.0"
set scalaVersion := "2.9.3"
session save
exit
@yankov
yankov / gist:5538283
Created May 8, 2013 04:56
Water pouring problem solution from Odersky's course
package week7
class Pouring(capacity: Vector[Int]) {
// States
type State = Vector[Int]
val initialState = capacity map (x => 0)
// Moves