Skip to content

Instantly share code, notes, and snippets.

View Tivoli's full-sized avatar

Jonathan Rainey Tivoli

View GitHub Profile
@HenrikJoreteg
HenrikJoreteg / JS Util solution using underscore.js
Created October 22, 2010 21:20
Rather than creating some other util global, just extend underscore.js with any additional methods you want.
// If you don't use underscore.js, use it (http://documentcloud.github.com/underscore/)
// Then, use underscore's mixin method to extend it with all your other utility methods
// like so:
_.mixin({
escapeHtml: function () {
return this.replace(/&/g,'&')
.replace(/>/g,'>')
.replace(/</g,'&lt;')
.replace(/"/g,'&quot;')
.replace(/'/g,'&#39;');
@pelf
pelf / snow.html
Created November 26, 2010 02:51
html5 canvas snow flakes (as seen on http://goplanapp.com/home/blackfriday)
<!DOCTYPE html>
<head>
<title>Snow</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script src="snow.js" type="text/javascript"/></script>
</head>
<body onload="init();">
<canvas id="bgcanvas" width="410" height="316" style="position:absolute;z-index:2"></canvas>
<img src="globe_layers_2.png" style="position:absolute;z-index:3">
<canvas id="fgcanvas" width="410" height="316" style="position:absolute;z-index:4"></canvas>
getMousePos = function( e ) {
return ( e.pageX || e.pageY ) ? {
x: e.pageX,
y: e.pageY
} : ( e.clientX || e.clientY ) ? {
x: e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
y: e.clientY + document.body.scrollTop + document.documentElement.scrollTop
} : null;
},
@erichocean
erichocean / gist:799195
Created January 27, 2011 20:32 — forked from bxjx/gist:583836
how to create data-uris for images in node.js
var express = require('express'),
request = require('request'),
BufferList = require('bufferlist').BufferList,
sys = require('sys');
var app = express.createServer(
express.logger(),
express.bodyDecoder()
);
@aelaguiz
aelaguiz / gist:864454
Created March 10, 2011 16:58
node.js function to create full directory path (like mkdir -p)
exports.createFullPath = function createFullPath(fullPath, callback) {
var parts = path.dirname(path.normalize(fullPath)).split("/"),
working = '/',
pathList = [];
for(var i = 0, max = parts.length; i < max; i++) {
working = path.join(working, parts[i]);
pathList.push(working);
}
@jankuca
jankuca / index.js
Created March 17, 2011 09:48
Simple Facebook Graph API Node.js Client
var HTTPS = require('https');
var QueryString = require('querystring');
/**
* Facebook API Wrapper
* @constructor
* @param {Object} info Info about the Facebook application
*/
var Client = function (info) {
if (!info.id) {
@jsermeno
jsermeno / config-haproxy.sh
Created June 20, 2011 08:51
Node.js server and Web Sockets on Amazon EC2 with Express.js and Socket.IO - http://catchvar.com/nodejs-server-and-web-sockets-on-amazon-ec2-w
# HAProxy config
mkdir /etc/haproxy
cat > /etc/haproxy/haproxy.cfg << EOF
global
maxconn 4096
defaults
mode http
@powmedia
powmedia / gist:1081802
Created July 14, 2011 01:58
Backbone.sync for Titanium
//Customise Backbone.sync to work with Titanium rather than jQuery
Backbone.sync = (function() {
var methodMap = {
'create': 'POST',
'read' : 'GET',
'update': 'PUT',
'delete': 'DELETE'
};
var xhr = Ti.Network.createHTTPClient({ timeout: 5000 });
@jpantuso
jpantuso / osx_lion_rail_setup.md
Created July 27, 2011 19:51
Setup OS X 10.7 w/ homebrew, oh-my-zsh, rvm, rails, and MySQL
@mikeyk
mikeyk / gist:1329319
Created October 31, 2011 22:56
Testing storage of millions of keys in Redis
#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])