Skip to content

Instantly share code, notes, and snippets.

@RandomEtc
RandomEtc / modestmaps-static.js
Created August 23, 2011 06:52
Node.js server for composing map tiles using modestmaps.js
var MM = require('modestmaps'),
Canvas = require('canvas'),
Image = Canvas.Image;
get = require('get'),
express = require('express');
function renderStaticMap(provider, dimensions, zoom, location, callback) {
var canvas = new Canvas(dimensions.x, dimensions.y),
ctx = canvas.getContext('2d');
@isaacs
isaacs / streams.md
Created September 26, 2011 00:58
A spec for streams

Status of this Document

This is a proposal. It does not match the code as of writing.

This describes the minimum contract that Stream objects must adhere to in order to properly interoperate with pipes.

Stream Class

The parent class for all stream objects. Implements the pipe

@creationix
creationix / coroutine-example.js
Created November 8, 2011 22:14
Lua style coroutines in nodeJS proposal
var FS = require('fs');
var Fiber = require('./fiber'); // Not to be confused with the existing node-fibers module
// readFile is a normal non-blocking, async function, but internally it can use
// the coroutine helper fiber. These kinds of coroutines are no more dangerous
// to the caller than any other async function.
function readfile(filename, next) {
// The call to Fiber is non-blocking. It's contents are only run sync till
// the first call to wait and then it returns.
Fiber(function (resume, wait) {
@CasualSuperman
CasualSuperman / indexBy.js
Created December 22, 2011 17:58
Underscore.js indexBy mixin
/**
* Underscore function that combines _.find and _.indexOf
* Source: https://github.com/documentcloud/underscore/issues/413
*
* _.indexBy([2, 6, 4, 7, 9, 0], function(num) {
* return num % 2 === 1;
* });
* => 3
*/
@boucher
boucher / StripeTutorialPage.html
Created February 6, 2012 07:05
Stripe Tutorial Payment Form
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Stripe Getting Started Form</title>
<script type="text/javascript" src="https://js.stripe.com/v1/"></script>
<!-- jQuery is used only for this example; it isn't required to use Stripe -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
// this identifies your website in the createToken call below

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@ry
ry / fib.js
Created March 12, 2012 00:17
a proper fibonacci server in node. it will light up all your cores.
var http = require('http')
var fork = require('child_process').fork;
function fib(n) {
if (n < 2) {
return 1;
} else {
return fib(n - 2) + fib(n - 1);
}
}
@thelonecabbage
thelonecabbage / recursive.tojson for backbone
Created March 12, 2012 08:31
Recursive toJSON for Backbone.js
Data.Model = Backbone.Model.extend({
toJSON: function(){
var clone = _.clone(this.attributes);
_.each(clone, function (attr, idx) {
if(attr.toJSON){
clone[idx] = attr.toJSON();
}
});
return clone;
}
transitionViewControllers(vc1, vc2, 0.15, nil, function(){
view.frame = CGRectMake(100,100,100,100);
}, function(){
view.removeFromSuperview();
});
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"