Skip to content

Instantly share code, notes, and snippets.

View jfsiii's full-sized avatar

John Schulz jfsiii

View GitHub Profile
@jfsiii
jfsiii / img2data.js
Created January 31, 2011 15:54
base64 encoding images in NodeJS
/*
* Complete reworking of JS from https://gist.github.com/803410
* Removes external `request` dependency
* Caveats:
* * No error checking
* * Largely a POC. `data` URI is accurate, but this code cannot simply be inserted into an `express` app
*/
var URL = require('url'),
sURL = 'http://nodejs.org/logo.png',
oURL = URL.parse(sURL),
@jfsiii
jfsiii / gist:814784
Created February 7, 2011 17:33 — forked from paulirish/gist:601751
get and set objects in localStorage and sessionStorage
// Forked from paul irish's https://gist.github.com/601751
// desire: localStorage and sessionStorage should accept objects
// in fact they do according to spec.
// http://code.google.com/p/chromium/issues/detail?id=43666
// but so far that part isnt implemented anywhere.
// so we duckpunch set/getItem() to stringify/parse on the way in/out
// this seems to work in chrome
B.plugin = (function(){
var val = 42;
return {
some: function(){ console.log('some', val); },
method: function(){ console.log('method', val); }
};
})();
require("jsdom").env({
html: "<html><body></body></html>",
scripts: [
'http://code.jquery.com/jquery-1.5.min.js',
'http://jsno.de/javascripts/jquery.flot.svn.js', // please don't hotlink
'http://jsno.de/javascripts/jquery.flot.text.js' // please don't hotlink
],
done: function (errors, window)
{
var i, d1 = [], d2 = [], d3 = [];
@jfsiii
jfsiii / preloadFlot.js
Created May 2, 2011 17:11
Function I run when Express starts up
function preloadFlot()
{
var jsdom = require("jsdom"),
document = jsdom.jsdom(),
window = document.createWindow(),
flot_location = 'http://jsno.de/javascripts/jquery.flot.svn.js',
text_location = 'http://jsno.de/javascripts/jquery.flot.text.js',
jquery_location = 'http://code.jquery.com/jquery-1.5.min.js',
loadScript = function ( location, callback )
{
@jfsiii
jfsiii / Flot_0_7.diff
Created May 4, 2011 22:56
diff of changes to Flot 0.7 to support being run on node (with node-canvas)
137c137,139
< hooks: {}
---
> hooks: {},
> width: null,
> height: null
687c689,694
< var c = document.createElement('canvas');
---
> var c;
@jfsiii
jfsiii / dual.js
Created May 13, 2011 03:01 — forked from unscriptable/another-way.js
AMD-compatible CommonJS Module/1.1 that can also be loaded in a script tag
(function (define) {
define(function (exports) {
function Color(){}
return Color;
});
}(
// provide define if it's not available
this.define || (function (global, moduleId) {
@jfsiii
jfsiii / dual.js
Created May 13, 2011 03:22 — forked from unscriptable/another-way.js
AMD-compatible CommonJS Module/1.1 that can also be loaded in a script tag
(function () {
/*!
* expose.js
*
* @author Oleg Slobodskoi
* @website https://github.com/kof/expose.js
* @licence Dual licensed under the MIT or GPL Version 2 licenses.
*/
function expose(namespace, api) {
var env = {};
(function(){
function Klass(id){ this._id = id; }
Klass.prototype.id = function(){ console.log(this._id); }
var freeExports = typeof exports == 'object' && exports;
if (freeExports) {
for (var prop in Klass) freeExports[prop] = Klass[prop];
} else if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
define(function() { return Klass; });
(function(){
function Klass(id){ this._id = id; }
Klass.prototype.id = function(){ console.log(this._id); }
expose('Klass', Klass);
/*!
* expose.js
*
* @author Oleg Slobodskoi