Skip to content

Instantly share code, notes, and snippets.

@lamberta
lamberta / gcal
Created October 1, 2011 16:19
Display calendar agenda using the Google command line tool.
#!/usr/bin/env bash
function print_help {
echo "Display the week's agenda from Google Calendar."
echo "Usage: $(basename $0) [options]"
echo " -h Show this usage guide."
echo " -t Today's agenda."
echo " -m Month agenda."
echo " -E Only display Event calendar."
echo "[Add event]"
@lamberta
lamberta / demo.html
Created July 21, 2011 07:09
Buffalo JavaScript Club Presentation: Let's Set Up an Animation Loop, Using HTML5 and a Canvas Element
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
body {
background-color: #bbb;
}
#canvas {
@lamberta
lamberta / on-javascript-callbacks.md
Created June 14, 2011 17:53
On JavaScript callbacks, program flow control and the functional style.

One of the first things a newcomer to JavaScript will notice when confronted with the modern style is the prevalence of function objects passed as parameters to other functions, or callbacks. What is not immediately apparent is why this higher-order function style needed. In short, functional arguments give us a way to delay the execution of a block of code. This kind of program flow control means we can approximate some powerful abstraction techniques usually reserved for macros in other languages.

Here's a typical callback example you'll find on the client-side, attaching a click event handler to a DOM element:

var callback = function (evt) { console.log("Element clicked!"); };
element.addEventListener('click', callback);

Here we've created a variable to hold our callback function. Next we have our DOM element listen for click events and, when it has one, execute our function. The callback function has been taken out of the normal program flow to be run at another time, or in this case, when the

@lamberta
lamberta / path-demo.js
Created June 9, 2011 03:47
A* (a-star) Pathfinding with Node.js and Ncurses.
var nc = require('ncurses'),
ui = require('./src/ui'),
map = require('./src/path-map'),
pf = require('./src/pathfinding');
nc.colorPair(2, nc.colors.BLACK, 15);
ui.windows.root.bkgd = nc.colorPair(2);
var map = map.createMap(nc.cols, nc.lines, ui.windows.root);
@lamberta
lamberta / ti-tools.sh
Created April 14, 2011 06:48
Command line interface for creating and building Titanium Mobile Android projects.
#!/usr/bin/env bash
## Command line interface for creating and building Titanium Mobile Android projects.
TI_SRC="$HOME/local/src/titanium_mobile"
TI_SDK="$TI_SRC/dist/mobilesdk/linux/1.7.0"
TI_VERSION_TAG="1_7_0_preview"
ANDROID_HOME=${ANDROID_HOME:-"$HOME/local/lib/android-sdk"}
JAVA_HOME=${JAVA_HOME:-"/usr/lib/jvm/java-6-sun"} #sun-java6-sdk
PROJECT_HOME="$HOME/projects/ti"
@lamberta
lamberta / gist:882023
Created March 22, 2011 20:54
My wget incantation for downloading a local copy of the Mozilla JavaScript Reference.
#set DOC_ROOT, no trailing slash on url
#front page: $DOC_ROOT/javascript/en/JavaScript/Reference.html
wget -mkpE -np -nH -P "$DOC_ROOT/javascript" "https://developer.mozilla.org/en/JavaScript/Reference"
@lamberta
lamberta / chrome-keyword-nav.md
Created March 18, 2011 18:17
Using Chrome keyword navigation to alleviate keyboard-shortcut deficiencies.

The Chrome browser has some useful, but limited keybindings—most notably bookmarks. By using the custom search engine feature, we can use keyword navigation to fill in the gaps.

In Chrome, Settings > Preferences, Search > Manage Search Engines.

Add a new entry to 'Other search engines', for example: name, keyword, url Chrome Bookmarks, bm, chrome://bookmarks Chrome Settings, settings, chrome://settings/browser Chrome Keybindings, keys, http://www.google.com/support/chrome/bin/static.py?page=guide.cs&guide=25799&topic=28652

@lamberta
lamberta / procras-filter
Created March 8, 2011 01:43
Add and remove time-sink websites to /etc/hosts with a simple command.
#!/usr/bin/env bash
## Adds time consuming websites to /etc/hosts and redirects them to localhost.
## Make sure you backup /etc/hosts and set its location in the env var.
BLOCKED_SITES=("facebook.com" "login.facebook.com" "www.facebook.com" "twitter.com" "news.ycombinator.com" "www.nytimes.com")
BACKUP_HOSTS="$HOME/local/var/hosts.bak"
DEST_HOSTS="/etc/hosts"
function print_help {
echo "Usage: $(basename $0) [options]"
@lamberta
lamberta / gist:645597
Created October 25, 2010 19:47
On the fly socks5 proxy with ssh
#dynamic port forwarding, binds a socket on the local machine
ssh -D 8080 user@host
#tunnel through proxy examples
chromium-browser --proxy-server="socks5://localhost:8080"
curl --socks5 localhost:8080 url
#most apps should recognize this
export HTTP_PROXY="socks5://localhost:8080"
@lamberta
lamberta / gist:640904
Created October 22, 2010 16:34
Command-line JSON
#get
curl -H 'Content-Type: application/json' url
#post
curl -H 'Content-Type: application/json' -X POST -d "{'foo':'bar'}}" url
#pretty print
curl -s -H 'Content-Type: application/json' url | python -m json.tool
#simple script, docs: http://docs.python.org/library/json.html