Skip to content

Instantly share code, notes, and snippets.

@drewlesueur
drewlesueur / avoid_nested_callbacks.coffee
Created November 5, 2010 19:47
Javascript pattern for avoiding nested callbacks
# Drew LeSueur @drewlesueur
# An abstraction for calling multiple asynchronous
# functions at once, and calling a callback
# with the "return values" of all functions
# when they are all done.
# requires underscore.js
_.mixin # underscore.js mixin
do_these: (to_dos, callback) ->
return_values = if _.isArray(to_dos) then [] else {}
@drewlesueur
drewlesueur / sequence.html
Created October 6, 2010 04:38
sequence diagram
<!doctype html>
<html>
<head>
<script>
/*!
* jQuery JavaScript Library v1.4.2
* http://jquery.com/
*
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
@drewlesueur
drewlesueur / CRUD-nodejs-mongodb.coffee
Created October 2, 2010 09:29
Mongo db crud example
#Examples of crud operations on node.js using node-mongodb-native (in coffeescript)
mongo = require("mongodb")
host = 'localhost'
port = mongo.Connection.DEFAULT_PORT
this.ObjectID = mongo.ObjectID
this.db = new mongo.Db 'mydb', new mongo.Server(host, port, {}), {}
@drewlesueur
drewlesueur / php_automator.php
Created September 30, 2010 00:22
PHP Automater
<?php
//Use this script to automatically log into a site and grab protected info.
//code modified from
// http://www.knowledgesutra.com/forums/topic/38162-automatic-login-using-curl/
//see also
//http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
// INIT CURL
$ch = curl_init();
//needed for https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
Things that should (or maybe shouldn't be in JavaScript)
Tail recursion optimisation
Optional Dynamic scope (in addition to its lexical scope)
Method Missing es5?
method for accessing array elements.
call by name ? (maybe a bad idea)
see scope chain.
echo("""
<!doctype html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script>
(function ($) {
var initialized = false;
var initialized_started = false;
echo("""
<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
$(function(){
var canvas = $('#canvas')[0]
var ctx = canvas.getContext("2d")
@drewlesueur
drewlesueur / index.py
Created July 3, 2010 21:14
Shark.svg
# http://www.openclipart.org/people/molumen/molumen_white_shark.svg
resp.headers['Content-type'] = "image/svg+xml"
echo("""<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
@drewlesueur
drewlesueur / index.py
Created July 1, 2010 17:12
Heatmap poxy
import base64
from google.appengine.api import datastore
from google.appengine.api import datastore_errors
from google.appengine.api import datastore_types
import hashlib
(function($) {
$.fn.heatmap = function(settings) {
var config = {'radius': 25, opacity: 0.5, centerValue: 10,
gradient : [0,167772262,336396403,504430711,672727155,857605496,1025311865,1193542778,1361445755,1529480062,1714226559,1882326399,2050229378,2218264197,2386232710,2571044231,2739013001,2906982028,3075081868,3243050383,3427796369,3595765395,3763734164,3931768213,4099736983,4284614554,4284745369,4284876441,4285007513,4285138585,4285334937,4285466009,4285597081,4285728153,4285924505,4286055577,4286186649,4286317721,4286514073,4286645145,4286776217,4286907289,4287103641,4287234713,4287365785,4287496857,4287693209,4287824281,4287955353,4288086425,4288283033,4288348568,4288414103,4288545431,4288610966,4288742293,4288807829,4288938900,4289004691,4289135763,4289201554,4289332625,4289398161,4289529488,4289595024,4289726351,4289791886,4289922958,4289988749,4290119820,4290185612,4290316683,4290382218,4290513546,4290579081,4290710409,4290776198,4290841987,4290907777,4290973822,429103961