Skip to content

Instantly share code, notes, and snippets.

View ritch's full-sized avatar

Ritchie Martori ritch

  • Fremont, California
View GitHub Profile
@ritch
ritch / gist:1525799
Created December 28, 2011 02:00
Ring
// start node.js processes on a distributed network
// makes sure the process is always available, even if
// it has to restart the process on another server
// essentially a distributed version of forever
// no client/server relationship, all ring nodes are peers
var ring = require('ring').join('network guid')
, opts = {
distribution: {
@ritch
ritch / crypto
Created February 9, 2012 17:34
Playing around with ciphers
#!/usr/bin/env node
var operation = process.argv[process.argv.length - 1];
var allowed = '--decipher --cipher'
if(allowed.indexOf(operation) === -1) {
operation = '--cipher';
}
// let us type a string
@ritch
ritch / gist:2568271
Created May 1, 2012 14:23
dpd client api
// get all widgets
dpd.widgets.get(function (err, widgets) {
if(err) return alert(err);
console.log(widgets); // [Object, Object, Object, ...]
})
// get one widget
dpd.widgets.first(function (err, widget) {
if(err) return alert(err);
console.log(widget);
var data = [];
describe('fast array', function(){
it('setup', function() {
var max = 9 * (1000 * 1000);
while(data.length < max) {
if(data.length === max / 2) data.push(['random', 'random value']);
else data.push(['key', 'value']);
}
@ritch
ritch / async.html
Created July 27, 2012 02:53
Lightweight, Fast, Pluggable 2 way data binding proposal
<!doctype html>
<html>
<body data-controller="list">
<ul>
<li data-repeat="item in items">
{{ item.text }}
</li>
</ul>
@ritch
ritch / gist:3227103
Created August 1, 2012 14:03
Simple file transfer in node
var http = require('http')
, request = require('request')
, fs = require('fs');
var server = http.createServer(function (req, res) {
req.pipe(fs.createWriteStream('my-file.jpg'));
})
.listen(3000)
.on('listening', function () {
fs.createReadStream('my-file.jpg').pipe(request.post('http://localhost:3000'));
@ritch
ritch / app.js
Created August 9, 2012 02:09
Extending http.Server with connect
var connect = require('connect')
, http = require('http');
var server = http.createServer(function () {
console.log('foo'); // this is logged
});
var app = connect(server);
app.use(function (req, res, next) {
@ritch
ritch / readme.md
Created August 9, 2012 22:15
dpd-templates

dpd-templates

A dpd resource for rendering templates on the server as well as exposing them for use in the browser.

Template Files

Templates live in the root of their resource instance folder (eg. /my-project/resources/templates) and in a partials sub folder.

Server Rendering

@ritch
ritch / origin.js
Created August 26, 2012 18:38
dpd custom resource for cross origin support
// this must be in your project's node_modules folder to be available from the dashboard
var Resource = require('deployd/lib/resource')
, util = require('util');
function CrossOrigin() {
Resource.apply(this, arguments);
// match all urls when routing
this.path = '/*';
}
@ritch
ritch / .DS_Store
Created August 28, 2012 07:09
Dpd Recursive Fail
fail