Skip to content

Instantly share code, notes, and snippets.

View FGRibreau's full-sized avatar
✍️
writing "#NoBullshit Tech-Lead" book https://getnobullshit.com

Francois-Guillaume Ribreau FGRibreau

✍️
writing "#NoBullshit Tech-Lead" book https://getnobullshit.com
View GitHub Profile
@FGRibreau
FGRibreau / twitter-stream-api-bench.js
Created March 11, 2011 13:16
twitter stream sample api's simple benchmark
//https://github.com/jdub/node-twitter/
var twitter = require('twitter'),
sys = require('sys');
var twit = new twitter({
consumer_key: 'YOUR KEYS',
consumer_secret: 'YOUR KEYS',
access_token_key: 'YOUR KEYS',
access_token_secret: 'YOUR KEYS'
});
var myFunction = function(dataArray){
// Do something with these data (ajax ?)
console.log('Debounced arguments:', dataArray);
}
var myDebouncedFunction = $.debounceargs(5000, myDebouncedFunction);
myDebouncedFunction({model:'post', action:'save', data:[1,2,3,4]});
myDebouncedFunction({model:'comment', action:'add', data:{text:'hello world', author:'anonymous'}});
@FGRibreau
FGRibreau / most_used_url_shortener.js
Created March 31, 2011 17:28
Most used url shortener
var urls = ["http://bit.ly/",
"http://tinyurl.com/",
"http://is.gd/",
"http://tr.im/",
"http://ow.ly/",
"http://cli.gs/",
"http://u.mavrev.com/",
"http://twurl.nl/",
"http://tiny.cc/",
"http://digg.com/",
@FGRibreau
FGRibreau / LanguageDetect_Example.js
Created July 18, 2011 09:33
NodeJS - Language Detection
/*
Installation:
npm install languagedetect -g
*/
var LanguageDetect = require('languagedetect');
var lngDetector = new LanguageDetect();
/*
OR
@FGRibreau
FGRibreau / jquery.extend.js
Created August 1, 2011 20:00
jQuery extend for NodeJS / Object & Array Deep Copy for NodeJS
/*
jQuery.extend extracted from the jQuery source & optimised for NodeJS
Twitter: @FGRibreau / fgribreau.com
Usage:
var Extend = require('./Extend');
// Extend
var obj = Extend({opt1:true, opt2:true}, {opt1:false});
@FGRibreau
FGRibreau / blog_amqpdsl.coffee
Created December 15, 2011 09:45
AMQP-DSL example
require('amqp-dsl')
.login(
login: 'legen'
password: 'dary'
)
# Bind listeners to some events (available events are `close`, `error` and `ready`)
.on('close', () -> console.error "RabbitMQ connection closed")
.on('error', (err) -> console.error "RabbitMQ error", err)
.on('ready', () -> console.log "Connected to RabbitMQ")
@FGRibreau
FGRibreau / gist:1678749
Created January 25, 2012 21:12 — forked from loginx/gist:810311
Underscore.js mixin to emulate ruby's Array#each_slice method.
/**
* Underscore.js mixin to emulate Ruby's Enumerable#each_slice method.
* http://www.ruby-doc.org/core/classes/Enumerable.html#M001514
*
*/
_.mixin({
// _.each_slice(obj, slice_size, [iterator], [context])
each_slice: function(obj, slice_size, iterator, context) {
var collection = obj.map(function(item) { return item; }), o = [], t = null, it = iterator || function(){};
@FGRibreau
FGRibreau / times.js
Created February 5, 2012 22:45
Ruby .times & .upto & .downto methods in JavaScript
// Ruby = 5.times { |i| puts i }
// JS = (1).times(function(i){console.log(i);})
Number.prototype.times = function(cb) {
var i = -1;
while (++i < this) {
cb(i);
}
return +this;
@FGRibreau
FGRibreau / redis.coffee
Created February 7, 2012 21:08
Node-redis - auto-reconnect
redis = require("redis")
cli = null
# 1/ Helpers
RedisOnConnected = (err, redis) ->
# Update the global reference to the redis client
cli = redis
RedisDoConnect = (cbConnected) ->
client = require("redis").createClient()
@FGRibreau
FGRibreau / pid.js
Created February 16, 2012 18:41
Simple snippet for cross-platform .pid management in NodeJS. I use it for managing NodeJS apps with supervisord and monit
//
// Usage: require('./pid')("myapp");
//
var fs = require('fs');
module.exports = function(appname){
process.title = appname;
var PID_FILE = "/usr/local/var/run/"+process.title+".pid";