Skip to content

Instantly share code, notes, and snippets.

View pgte's full-sized avatar
๐Ÿ 
Working from home

Pedro Teixeira pgte

๐Ÿ 
Working from home
View GitHub Profile
@pgte
pgte / design_doc_source.json
Created September 12, 2011 14:42
design doc source
{
"_id": "_design/CQS/test10",
"_rev": "1-b906ada82e09f7dd1f85f4f8ee0e1b7b",
"name": "test10",
"ApproximateNumberOfMessages": 0,
"ApproximateNumberOfMessagesNotVisible": 0,
"VisibilityTimeout": 30,
"CreatedTimestamp": "2011-09-12T14:37:35.981Z",
"LastModifiedTimestamp": "2011-09-12T14:37:35.981Z",
"Policy": null,
@pgte
pgte / example.js
Created August 5, 2011 13:44
example
pipeline = new Pipeline('test pipeline 2', {
load: loadFunction
, save: saveFunction
});
pipeline
.on('initial', initialHandler, {
success: 'a'
, condition: function(doc) {
conditionCalled = true;
return true;
@pgte
pgte / rand_test.rb
Created August 2, 2011 11:10
rand test
1.upto 1000 do |exp|
frequencies = {}
1.upto 5000 do |i|
number = rand(16);
frequency = (frequencies[number] || 0) + 1
frequencies[number] = frequency
end
squared_sum = (0..15).map {|number| frequencies[number] * frequencies[number] }.reduce(0) {|mem, freq| mem + freq }
var child_process = require('child_process');
function spawn() {
var child = child_process.spawn(...);
child.on('exit', spawn);
}
var net = require('net');
var connectTimes = [];
function connect() {
var socket = new net.Socket({type: 'tcp4'});
var time = Date.now();
socket.setTimeout(30000);
//socket.connect(5015, '66.228.62.138');
socket.connect(5012, 'fragola.sfarm1.com');
@pgte
pgte / async.js
Created February 27, 2011 11:36
async_function.js
function async(i, callback) {
timeout = Math.round(Math.random() * 3000);
setTimeout(function() {
console.log(i + ' is done');
callback();
}, timeout);
}
@pgte
pgte / fugue_test
Created January 27, 2011 09:33
app.js
// NOTE: Fugue *almost* works great. But it doesn't seem to responsd to the USR2 signal correctly
// Try it one more time.
var fugue = require('fugue')
var path = require("path")
var sys = require('sys')
// https://github.com/pgte/fugue
// Send kill -USR2 <PID> to hot reload! 0 downtime.
@pgte
pgte / also_wrong.js
Created January 9, 2011 23:08
asynchronous iterative patterns in Node.js
function insertCollection(collection, callback) {
for(var i = 0; i < collection.length; i++) {
(function(i) {
db.insert(collection[i], function(err) {
if (err) {
callback(err);
return;
}
if (i == (collection.length - 1)) {
callback();
@pgte
pgte / setup.js
Created January 7, 2011 16:48
setup.js
(function setup(how_many, callback) {
var successful_ones = 0;
for (var i=0; i < how_many; i++) {
db.some_call('name', 'value', function(err) {
if (err) { callback (err); return; };
successful_ones ++;
if (successful_ones == how_many) {
callback();
}
});
@pgte
pgte / alfred_example.js
Created January 6, 2011 13:41
alfred_example.js
var USERS = {
1: {name: 'Pedro', age: 35, sex: 'm'}
, 2: {name: 'John', age: 32, sex: 'm'}
, 3: {name: 'Bruno', age: 28, sex: 'm'}
, 4: {name: 'Sandra', age: 35, sex: 'f'}
, 5: {name: 'Patricia', age: 42, sex: 'f'}
, 6: {name: 'Joana', age: 29, sex: 'f'}
, 7: {name: 'Susana', age: 30, sex: 'f'}
};