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 / 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 / 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 / mem_usage.js
Created October 23, 2011 09:00
Memory usage of constructor techniques:
Client:
console.log('BEFORE:', process.memoryUsage());
var Rectangle = require('./rectangle');
var rectangles = [];
for(var i = 0; i < 100000; i++) {
rectangles.push(new Rectangle(1,2,3,4));
}
@pgte
pgte / expect.js
Created November 25, 2011 17:55
expect.js
(function() {
function _deepEqual(actual, expected) {
// 7.1. All identical values are equivalent, as determined by ===.
if (actual === expected) {
return true;
} else if (actual instanceof Date && expected instanceof Date) {
return actual.getTime() === expected.getTime();
// 7.3. Other pairs that do not both pass typeof value == "object",
pedroteixeira:test pedroteixeira$ node test.js
uncaught exception [Error: abc1]
uncaught exception [Error: def]
uncaught exception [Error: abc2]
uncaught exception [Error: def]
var BufferedStream = require('bufferedstream')
, inherits = require('util').inherits
;
function Transformation(callback) {
BufferedStream.apply(this)
this.callback = callback
}
inherits(Transformation, BufferedStream)
module.exports = function(conf) {
return function(a, b) {
return a + b;
};
};
@pgte
pgte / prophet.js
Last active December 14, 2015 14:08
var previousDistance = Number.MAX_VALE;
var dir = 0;
function tick(distance) {
console.log('distance:', distance);
var randomTurn = 2 - Math.round(Math.random() * 4);
console.log(randomTurn);
if (distance >= previousDistance) dir += randomTurn;
var directions = ['up', 'down', 'left', 'right'];
var direction = directions[dir % directions.length];
previousDistance = distance;
→ cd projects/test
pedroteixeira@Pedros-MacBook-Pro:~/projects/test (master)
→ npm install kinect
npm http GET https://registry.npmjs.org/kinect
npm http 200 https://registry.npmjs.org/kinect
> [email protected] install /Users/pedroteixeira/projects/test/node_modules/kinect
> node-gyp rebuild
gyp http GET http://nodejs.org/dist/v0.8.21/node-v0.8.21.tar.gz