Skip to content

Instantly share code, notes, and snippets.

View RandomEtc's full-sized avatar
🦕

Tom Carden RandomEtc

🦕
View GitHub Profile
@RandomEtc
RandomEtc / update.js
Created July 12, 2012 19:43
SQL builder sketches for node.js and node-postgres
/*jshint node:true globalstrict:true*/
"use strict";
var assert = require('assert');
//
// Convenience function for building a simple UPDATE/SET/WHERE/RETURNING statement.
//
// e.g.
//
@RandomEtc
RandomEtc / app-broken.js
Created May 16, 2012 21:58
Minimal node.js server to pass Twitter API responses through JSON parse and stringify
var http = require('http')
https = require('https'),
url = require('url');
// proxy json requests to Twitter API, round-trip through JSON.parse/stringify:
http.createServer(function (req, res) {
if (req.url.indexOf('.json') == req.url.length - '.json'.length) {
var options = { host: 'api.twitter.com', path: req.url }
https.get(options, function(got) {
@RandomEtc
RandomEtc / Makefile
Created May 16, 2012 21:56
Minimal Objective-C HTTP client for testing UTF8 decoding issues
CC = clang
MAIN = main
SRCS = main.o
default: $(MAIN)
$(MAIN): $(SRCS)
$(CC) -O0 -Wall -o $(MAIN) $(SRCS) -framework Foundation
@RandomEtc
RandomEtc / escaped-json.js
Created May 11, 2012 05:18
Extra escapey JSON encoding for node.js
// preserve Twitter's style of JSON string encoding...
// escape higher value unicode (lowercase hex)
// escape < and > (uppercase hex)
// escape / in strings (\/)
// hugs! https://gist.github.com/1306986
// http://stackoverflow.com/questions/4901133/json-and-escaping-characters
function escapedStringify(s, emit_unicode) {
var json = JSON.stringify(s);
return emit_unicode ? json : json.replace(/\//g,
function(c) {
@RandomEtc
RandomEtc / resizeable.pde
Created March 28, 2012 04:29
resizeable sketch in Processing (with notification of new size)
void setup() {
size(640,480);
frame.setResizable(true);
}
void draw() {
background(frameCount);
}
web: node app.js
@RandomEtc
RandomEtc / surrogate.js
Created February 20, 2012 20:36
fussing with UTF-16 surrogate encoding in Javascript
// see http://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B0000_to_U.2BD7FF_and_U.2BE000_to_U.2BFFFF
function escapeBMP(n) {
return '\\u'+('0000'+n.toString(16)).slice(-4);
}
// see http://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B10000_to_U.2B10FFFF
function makeSurrogate(n) {
var a = n - 0x10000;
var highBits = a >> 10;
var lowBits = a & 0x3FF;
@RandomEtc
RandomEtc / csv2html.js
Created February 11, 2012 19:06
Quick node.js script to convert a CSV file to HTML
// first of all make sure we have enough arguments (exit if not)
if (process.argv.length != 5)
{
console.error("Usage: node csv2html.js input.csv template.ejs output.html")
console.error();
console.error("Outputs the given template for each row in the given input.")
console.error("Uses the first row of the CSV as column names in the template.")
process.exit(1);
}
@RandomEtc
RandomEtc / Makefile
Created December 7, 2011 23:17
Using Boost Signals2 to pass messages, return true to cancel propagation
# don't hate me for this Makefile, at least I provided one
BOOST_PATH = /Users/tom/Documents/Code/Cinder/Cinder/boost
main: main.o
g++ -o main main.o
main.o: main.cpp
g++ -c -I$(BOOST_PATH) -o main.o main.cpp
@RandomEtc
RandomEtc / README.md
Created September 28, 2011 19:06
How to enforce provider limits on interaction and tile loading in Modest Maps JS

See issue 57 for discussion and planned improvements.