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 / 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 / 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 / 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 / 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>
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 / 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);
@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: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 / rml.md
Created October 14, 2011 02:58
Scriptable Markup

I'm getting tired of writing documents to then parse and rebuild in JavaScript. HTML is not a markup language for complex interactive applications. rml is. Chekk-it.

// html
<img src="http://google.com/logo.png" />

Same thing in simple rml.

// rml
img('http://google.com/logo.png');
@ritch
ritch / parallel.js
Created September 13, 2011 06:32
Async via EventEmitter
// parallel
// 3 requests happen in parallel
var urls = ['google.com', 'yahoo.com']
, emitter = new EventEmitter()
, done = []
;
function increment(res) {
done.push(res);
if(done.length === urls.length) {