Skip to content

Instantly share code, notes, and snippets.

View tdegrunt's full-sized avatar

Tom de Grunt tdegrunt

View GitHub Profile
@tdegrunt
tdegrunt / batmap.html
Created January 6, 2012 13:00
GoogleMapsView / Batman.View example with Batman
<!DOCTYPE html>
<html>
<head>
<title>BatMap</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="../lib/es5-shim.js"></script>
<script type="text/javascript" src="../lib/batman.js"></script>
<script type="text/javascript" src="../lib/batman.solo.js"></script>
@tdegrunt
tdegrunt / rest_status_codes.md
Created January 11, 2012 10:19
REST Status codes

REST Status codes

Retrieve all users:

index	GET  	/users      200 - Returns all users
							[301 - ?!?!]

Create a new user:

@tdegrunt
tdegrunt / gist:1605311
Created January 13, 2012 09:43 — forked from tvandervossen/gist:1605091
Deployment to S3 with CloudFront invalidation using s3cmd 1.1 beta
Sync local-public-dir to bucket-name on S3 and invalidate changed files on CloudFront:
$ ./bin/s3cmd-1.1.0-beta1/s3cmd -c s3.config sync local-public-dir/ s3://bucket-name/ --acl-public --cf-invalidate --rexclude '.svn' --rexclude '.DS_Store'
You can create s3.config with:
$ s3cmd --configure
I keep my s3.config on an encrypted disk image which I mount manually when needed.
@tdegrunt
tdegrunt / reg_exp_validator.coffee
Created January 14, 2012 16:08
RegExp Validator for batman.js (RegExpValidator)
class RegExpValidator extends Batman.Validator
@options 'with', 'message'
validateEach: (errors, record, key, callback) ->
value = record.get(key)
if !value? || !value.match(@options.with)
errors.add key, Batman.translate('errors.format', {attribute: key, message: @options.message})
callback()
Batman.Validators.push RegExpValidator
@tdegrunt
tdegrunt / ssdp.node.js
Created January 15, 2012 13:11 — forked from chrishulbert/ssdp.node.js
Service discovery using node.js and ssdp / universal plug n play
var dgram = require('dgram'); // dgram is UDP
// Listen for responses
function listen(port) {
var server = dgram.createSocket("udp4");
server.on("message", function (msg, rinfo) {
console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port);
});
@tdegrunt
tdegrunt / get_barcode_from_image.js
Created January 15, 2012 21:43 — forked from tbtlr/get_barcode_from_image.js
Barcode recognition with JavaScript - Demo: http://bit.ly/djvUoy
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',
@tdegrunt
tdegrunt / ping_pong_udp.js
Created January 15, 2012 22:47
PING PONG with UDP/dgram sockets
// Node 0.4.12
dgram = require('dgram');
var secret_port = 1337;
var clientPort = 0;
function clientListen(port) {
var server = dgram.createSocket("udp4");
server.on("message", function (msg, rinfo) {
@tdegrunt
tdegrunt / linux-node-joystick.js
Created January 28, 2012 23:17 — forked from creationix/linux-node-joystick.js
Basic Linux Joystick support.
var FS = require('fs');
var EventEmitter = require('events').EventEmitter;
// http://www.mjmwired.net/kernel/Documentation/input/joystick-api.txt
function parse(buffer) {
var event = {
time: buffer.readUInt32LE(0),
number: buffer[7],
value: buffer.readInt16LE(4)
}
@tdegrunt
tdegrunt / example.js
Created January 29, 2012 20:41 — forked from Gozala/example.js
Workaround for lack of "tail call optimization" in JS
// Lack of tail call optimization in JS
var sum = function(x, y) {
return y > 0 ? sum(x + 1, y - 1) :
y < 0 ? sum(x - 1, y + 1) :
x
}
sum(20, 100000) // => RangeError: Maximum call stack size exceeded
// Using workaround
events =
events: {}
bind: (topic, handler, context = this) ->
(@events[topic] ||= []).push { handler, context }
trigger: (topic, args...) ->
if @events[topic]?
event.handler.apply event.context, args for event in @events[topic]