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 / http-client-request-observe.js
Last active January 17, 2021 09:27
node request and response life cycle
var https = require('https');
var querystring = require('querystring');
var events = ['socket', 'connection', 'response', 'data', 'end', 'close', 'finish'];
var postData = querystring.stringify({
'msg' : 'Hello World!'
});
var options = {
@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 / peer-star-app.md
Last active June 27, 2018 14:50
peer-star-app
  • Released on June 27th 2018
  • Expires on July 31st 2018

peer-star-app for peer-star app developers

Hello peer-star app developer! 👋

In an effor to make PeerPad scale better for many users editing the same pad, over the last few weeks I've been focused on implementing the topology and protocol described here. This is materializing in the form of a package named peer-star-app.

Recipe for customizing a SmartoOS image and cloning it

1. Create base image

1.1. Download and install the base image:

[root@00-0c-29-aa-24-ba ~]# imgadm list
UUID                                  NAME             VERSION  OS       PUBLISHED
9eac5c0c-a941-11e2-a7dc-57a6b041988f  base64           13.1.0   smartos  2013-04-26T15:17:57Z
@pgte
pgte / Keybase.md
Created February 6, 2018 15:16
Keybase

Keybase proof

I hereby claim:

  • I am pgte on github.
  • I am pgte (https://keybase.io/pgte) on keybase.
  • I have a public key ASBfSphgzAav1T3NDE4lHUnF6XEjThKMBaMHdr0XUsH-nwo

To claim this, I am signing this object:

@pgte
pgte / auth.md
Last active December 31, 2015 14:49

I built this service rendered over HTTPS.

We're using the Hawk protocol to authenticate message producers, but since the service will use HTTPS, Hawk is an overkill in my opinion.

Some of the drawbacks of using Hawk in my opinion:

  1. Signs whole message: overkill when you're using TLS
  2. Tries to be stateless on the server-side and implements a sort of message non-repeatability by including a timestamp inside the message. The timestamp has to be equal to the server-side time take or give 1 minute. This imposes time synchronizatin between client and server, which is hard to enforce.
@pgte
pgte / results.json
Created July 21, 2013 18:20
level-writestream benchmark results
{"max":100000,"chunkSize":500,"highWaterMark":500,"maxConcurrentBatches":4,"timeoutBetweenChunks":0,"valueSize":10,"wrap":false,"ellapsed":3403}
{"max":100000,"chunkSize":500,"highWaterMark":500,"maxConcurrentBatches":4,"timeoutBetweenChunks":0,"valueSize":10,"wrap":true,"ellapsed":2656}
{"max":100000,"chunkSize":500,"highWaterMark":500,"maxConcurrentBatches":4,"timeoutBetweenChunks":0,"valueSize":100,"wrap":false,"ellapsed":3437}
{"max":100000,"chunkSize":500,"highWaterMark":500,"maxConcurrentBatches":4,"timeoutBetweenChunks":0,"valueSize":100,"wrap":true,"ellapsed":2662}
{"max":100000,"chunkSize":500,"highWaterMark":500,"maxConcurrentBatches":4,"timeoutBetweenChunks":0,"valueSize":1000,"wrap":false,"ellapsed":4186}
{"max":100000,"chunkSize":500,"highWaterMark":500,"maxConcurrentBatches":4,"timeoutBetweenChunks":0,"valueSize":1000,"wrap":true,"ellapsed":2549}
{"max":100000,"chunkSize":500,"highWaterMark":500,"maxConcurrentBatches":4,"timeoutBetweenChunks":10,"valueSize":10,"wrap":false,"ellapsed":3353}
{"max
→ 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
> kinect@0.1.7 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
@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;
function someFn(req, res) {
// do stuff...
}
route('/someRoute', someFn);