Skip to content

Instantly share code, notes, and snippets.

@sspencer
sspencer / wordwheel.js
Created February 18, 2009 02:15
JavaScript wordwheel, similar to iTunes search.
function wordwheel(e, searchField, tableId)
{
var i, r, corpus, displayStyle,
kc = YE.getCharCode(e),
table = YD.get(tableId),
terms = YD.get(searchField).value.toLowerCase().split(" "),
table_len, terms_len;
if (kc === 27) {
terms = "";
@sspencer
sspencer / debug_to_file.php
Created February 18, 2009 02:28
Log to your own error file in PHP.
function dbg($str) {
error_log("$str\n", 3, "/tmp/dbg.txt");
}
# Ruby Range Check with Default Value
# if args['level'] is from (-1..9) return args['level], otherwise return -1
level = (-1..9).include?(args['level']) ? args['level'] : -1
I'm Lloyd Hilaiel from BrowserPlus. `[show the yahoo cow, moo]`
This screencast explores the question, *how do we make uploading from the Browser, better?* `[textual question
showing on screen]`
What does better mean?
* Better means *easier* for the user to select the content they wish to upload `[easier floats in lower left
portion of screen]`
* Better also means the selected content should transfer *faster*. `[faster floats in lower
I'm Lloyd Hilaiel from BrowserPlus.
[show the yahoo cow, moo]
This screencast explores the question, *how do we make uploading from the Browser, better?*
[textual question showing on screen]
What does better mean?
@sspencer
sspencer / gist:399025
Created May 12, 2010 19:22
NodeJS BrowserPlus Service Sketch
// A rough sketch of how a NodeJS service might look
// Take 2 - keep services flat.
service = require('browserplus').service;
log = require('browserplus').log;
service.name = "HelloWorld";
service.version = "1.0.1";
service.doc = "A hello world service for BrowserPlus";
@sspencer
sspencer / transparent-gif.js
Created October 31, 2010 22:27
Serve a transparent GIF from NodeJS
// Two ways to serve transparent GIF
var buf = new Buffer([
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00,
0x80, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x2c,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02,
0x02, 0x44, 0x01, 0x00, 0x3b]);
res.send(buf, { 'Content-Type': 'image/gif' }, 200);
require.extensions[".json"] = function (module, filename) {
module.exports = JSON.parse(require("fs").readFileSync(filename, "utf8"))
}
@sspencer
sspencer / count.py
Created March 21, 2011 18:28
Count items without conditional
t = ["one", "two", "one", "four", "one", "two", "three"]
hist = {}
for x in t:
hist[x] = hist.get(x, 0) + 1