Skip to content

Instantly share code, notes, and snippets.

Badgeville.ready(function(){
Badgeville.Comet.bind( function( event, message ) {
console.log('site notification');
console.log( message );
event_handler(message);
});
Badgeville.bind( 'siteMessage', function( event, message ) {
console.log( message );
# On a back-end side
Comet.trigger("some_event", user, {:text => 'hello'})
#on a front-end side
Badgeville.bind('some_event', function(data) {
console.log("Event handler here");
});
@yankov
yankov / gist:1123852
Created August 3, 2011 21:41
Sending message to faye server from ruby
def notify(message)
msg = JSON.dump('channel' => "/notifications/channel", 'data' => {'text' => message})
uri = URI.parse('http://127.0.0.1:3333/faye')
Net::HTTP.post_form(uri, :message => msg)
end
@yankov
yankov / gist:1123843
Created August 3, 2011 21:38
Faye node.js server
//download the lib from http://faye.jcoglan.com/download.html
var http = require('http'),
faye = require('./faye/faye-node.js');
var bayeux = new faye.NodeAdapter({
mount: '/faye',
timeout: 45
});
//have to include http://127.0.0.1:3333/faye.js in the html file
var client = new Faye.Client('http://127.0.0.1:3333/faye', { timeout: 120 });
var subscription = client.subscribe('/notifications/channel', function(message) {
alert(message.text);
});
//or with user_id as a channel
@yankov
yankov / 0_reuse_code.js
Last active August 29, 2015 14:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@yankov
yankov / gist:f196236fe5691873901e
Last active August 29, 2015 14:22
puzzles exbm
/* Given a list of numbers 0 to 10,000, return all those whose digits sum up to 20
* Digits cannot repeat. Search space should be reduced.
*/
def get20s(): Seq[Seq[Int]] = {
val ns = for {
i <- 0 to 6
j <- 1 to 7
k <- 2 to 8
if i + j + k == 11
%matplotlib inline
import md5, struct
import seaborn as sns
import matplotlib.pyplot as plt
import mmh3
def md5hash(i):
return md5.new(str(i)).digest()[12:16]
def mm(i):
@yankov
yankov / gist:8df34f46cd73fbdeb2e8
Created August 8, 2014 17:08
postgres async connection pool
val poolConfiguration = new PoolConfiguration(
maxIdle = 1000,
maxObjects = 5,
maxQueueSize = 5,
validationInterval = 1000
)
val factory = new PostgreSQLConnectionFactory(configuration)
val pool = new SingleThreadedAsyncObjectPool[PostgreSQLConnection](factory, poolConfiguration)