Skip to content

Instantly share code, notes, and snippets.

@mlconnor
mlconnor / imgToDataURL.js
Created June 17, 2013 15:20
Convert image in a web page to base64 dataURL
function imgToDataUrl(imgEl) {
var canvas = document.createElement("canvas");
canvas.width = imgEl.width;
canvas.height = imgEl.height;
// Copy the image contents to the canvas
var ctx = canvas.getContext("2d");
ctx.drawImage(imgEl, 0, 0, imgEl.width, imgEl.height);
// Get the data-URL formatted image
@mlconnor
mlconnor / node_state_machine.js
Created July 9, 2013 20:31
Node JS finite state machine
var U = require('underscore');
var sites = [
{"name" : "a", "time":4 },
{"name" : "b", "time":5 },
{"name" : "c", "time":6 },
{"name" : "d", "time":7 },
{"name" : "e", "time":8 },
{"name" : "f", "time":9 }
];
@mlconnor
mlconnor / README
Created August 15, 2013 16:14 — forked from mattbaker/README
This example expects to have d3.min.js and d3.layout.min.js in the same directory as pie.js and pie_serv.js.
Run with node pie_serv.js
@mlconnor
mlconnor / gist:6981173
Created October 14, 2013 19:53
A mongodb helper for handlebars
/* MongoDB queries - http://mongodb.github.io/node-mongodb-native/markdown-docs/queries.html */
hbs.registerAsyncHelper('mongo', function(options, opt2) {
console.log('args', arguments); // hash, inverse, fn, data
// console.log('name', name, "context", context);
// cb("async!!!!!");
var queryOptions = {};
if ( U.has(options.hash, "limit") && options.hash.limit.match(/^\d+$/) ) {
queryOptions.limit = parseInt(options.hash.limit);
}
@mlconnor
mlconnor / open_social_model.js
Created October 15, 2013 20:42
Start of a Mongoose Schema for Open Social and Portable Contacts User
var UserSchema = new Schema({
'emails' : {
'value' : 'String',
'type' : 'String' /* home, work, etc */
},
'photos' : {[
'value' : 'String'
]},
'name' : {
@mlconnor
mlconnor / jsonml_example.js
Created October 17, 2013 14:42
JSONML example
var U = require('./underscore-min.js');
var sanitize = require('validator').sanitize;
var doc =
["form", {"class":"form-horizontal span6"},
["fieldset",{},
["legend","Payment"],
["div", {"class":"control-group"},
["label", {"class":"control-label"}, "Card Holder's Name"],
["div", {"class":"controls"},
@mlconnor
mlconnor / middleware.js
Last active December 25, 2015 19:59
Small middleware concept
var U = require('./underscore-min.js');
var sanitize = require('validator').sanitize;
var doc =
["form", {"class":"form-horizontal span6"},
["fieldset",{},
["legend","Payment"],
["div", {"class":"control-group"},
["label", {"class":"control-label"}, "Card Holder's Name"],
["div", {"class":"controls"},
@mlconnor
mlconnor / s3_notes.txt
Last active December 26, 2015 05:49
Setting up a bucket for static hosting in S3.
1. Go into the Amazon Web Console and create a new bucket.
2. Go into the console and enable "static hosting" for the bucket.
3. Setup am index doc and an error doc for the bucket.
4. Set the config file for the bucket. This is an example and you would need to modify this stuff.
#here is an example config file for the bucket
<RoutingRules>
@mlconnor
mlconnor / gist:7256549
Created October 31, 2013 20:28
Async example calling exec
for ( var i = 0; i < total_tiles; i++ ) {
var filename = "tiles_" + i + ".png"; // current filename
var target = "map_" + column + "_" + row + ".png" // new filename
var cmd = "file " + i + " cmd> cp -f gen/" + filename + " mappy/" + target;
console.log(cmd);
//taskList.push(async.apply(child_process.exec, cmd));
taskList.push(function(command) {
@mlconnor
mlconnor / Mosaic.java
Last active October 6, 2017 12:07
Java Image Mosaic
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;