Skip to content

Instantly share code, notes, and snippets.

@christophercliff
christophercliff / compare.js
Created December 19, 2013 20:49
How much code did you write compared to code installed with npm?
#!/usr/bin/env node
var stdin = process.openStdin()
var data = ''
stdin
.on('data', function(chunk) {
data += chunk
})
.on('end', function(){
parse(data)
@christophercliff
christophercliff / description.md
Last active February 24, 2019 23:30
Stream email attachments to S3 with Mailgun, node.js.
@christophercliff
christophercliff / gist:6626134
Created September 19, 2013 16:38
Function.prototype.bind vs fn(callback, ctx)
this.myMethod(callback.bind(this))
// vs.
this.myMethod(callback, this)
// In the former, context is in the hands of the user. In the latter, the context is the responsibility of the owner of `myMethod`. Every method in that API that accepts a callback now requires a bunch of boilerplate, e.g.:
myMethod: function (callback, ctx) {
ctx = (ctx || null)
@christophercliff
christophercliff / browser.js
Created February 11, 2013 22:20
Upload files directly to Amazon S3 from the browser using HTTP POST. Generate policy and signature using an express.js server (node.js).
// Requires underscore.js and jquery.js
$.ajax({
type: 'GET',
url: 'http://your-server.com/signature',
success: function(response){
var data = new FormData();
_.each(response.fields, function(val, key){
data.append(key, val);
});
@christophercliff
christophercliff / background.js
Last active April 7, 2016 17:53
A Google Chrome Extensions helper class for accessing page context (DOM manipulation, etc.) from the background. Use a node.js-style callback pattern to create a custom page API.
(function(){
chrome.tabs.getSelected(null, function(tab){
var page = new Page(tab);
page.setScrollTo(100, 200, function(err, res){
console.log('You just scrolled the page!');
@christophercliff
christophercliff / Makefile
Created December 14, 2012 00:19
Makefile for deploying a Wintersmith static site to Github Pages without exposing the source (assumes you're using the default build directory).
deploy:
rm -rf ./build
wintersmith build
cd ./build && \
git init . && \
git add . && \
git commit -m "Deploy"; \
git push "git@github.com:{YOUR NAME}/{YOUR REPO}.git" master:gh-pages --force && \
rm -rf .git
@christophercliff
christophercliff / documents.js
Created December 16, 2011 00:34
Base Classes for Binding Backbone.js to the CouchDB Documents API
(function(window, undefined){
window.Document = Backbone.Model.extend({
url: function () {
var self = this,
base = '/' + self.database;
if (self.isNew())
@christophercliff
christophercliff / index.html
Created November 20, 2011 21:26
google maps polygon editor
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Polygon Arrays</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
@christophercliff
christophercliff / index.html
Created October 7, 2011 17:06
Generate Google Maps marker images on the client in a variety of colors
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
$(function(){
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js"></script>
<script type="text/javascript" src="https://raw.github.com/simplegeo/polymaps/master/polymaps.min.js"></script>
<style type="text/css">
.link { stroke: #ccc; }
.nodetext { pointer-events: none; font: 10px sans-serif; }