Skip to content

Instantly share code, notes, and snippets.

View jfsiii's full-sized avatar

John Schulz jfsiii

View GitHub Profile
function random( min, max )
{
min = min || 0;
max = max || 1;
var secs = (new Date()).getTime();
var rand = min + Math.round( Math.random( secs ) * (max - min) );
return rand;
}
@jfsiii
jfsiii / node-flot.js
Created November 20, 2010 21:22
Creating a Flot chart using node-canvas
var document = require("jsdom").jsdom(),
window = document.createWindow(),
jQuery = require('jquery').create(window),
fs = require('fs'),
script = document.createElement("script");
window.Canvas = require('canvas');
script.src = 'https://gist.github.com/raw/790339/3b0171c3e9b749bb93fff5d642eaa687f02939a5/jquery.flot.node-canvas.js';
script.onload = function ()
{
@jfsiii
jfsiii / flot node mods
Created November 20, 2010 21:25
diff of changes required to SVN version of Flot 0.6 to get it running on Node (with node-canvas)
39a40,41
> width: null,
> height: null,
701c703,709
< var c = document.createElement('canvas');
---
> var c;
> if (typeof Canvas !== "undefined"){
> c = new Canvas(width, height);
> } else {
[jfsiii@web165 node_flot]$ cat index.js
var http = require('http'), ip = "127.0.0.1", port = 41205;
http.createServer(function (req, res)
{
console.log('request received');
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('NodeJS on JSNo.de!\n');
}).listen(port);
console.log('Server running at http://'+ip+':'+port+'/');
@jfsiii
jfsiii / npm_out.txt
Created November 25, 2010 15:57
Attempted to install canvas 0.3.1
[jfsiii@web165 node_flot]$ uname -a
Linux web165.webfaction.com 2.6.18-194.17.1.el5PAE #1 SMP Wed Sep 29 13:31:51 EDT 2010 i686 i686 i386 GNU/Linux
[jfsiii@web165 node_flot]$ npm install canvas
npm info it worked if it ends with ok
npm info using npm@0.2.8-1
npm info using node@v0.2.5
npm info preinstall canvas@0.3.1
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
@jfsiii
jfsiii / node_canvas.txt
Created November 28, 2010 02:26
Cannot install 0.3.2
[jfsiii@web165 node_flot]$ uname -a
Linux web165.webfaction.com 2.6.18-194.17.1.el5PAE #1 SMP Wed Sep 29 13:31:51 EDT 2010 i686 i686 i386 GNU/Linux
[jfsiii@web165 node_flot]$ npm update canvas
npm info it worked if it ends with ok
npm info using npm@0.2.8-1
npm info using node@v0.2.5
npm info updates canvas@0.3.2
npm info preupdate canvas@0.3.2
npm info fetch http://registry.npmjs.org/canvas/-/canvas-0.3.2.tgz
npm info preinstall canvas@0.3.2
@jfsiii
jfsiii / node_flot.js
Created November 30, 2010 12:32
Need to replace text plugin with one that uses native canvas text methods, but this works as POC
console.log('flot init');
var document = require("jsdom").jsdom(),
window = document.createWindow(),
jQuery = require('jquery').create(window),
fs = require('fs'),
flot_location = 'http://jsno.de/javascripts/jquery.flot.svn.js',
text_location = 'http://jsno.de/javascripts/jquery.flot.text.js';
window.Canvas = require('canvas');
loadScript(flot_location, function (){ loadScript(text_location, onPluginLoaded); });
@jfsiii
jfsiii / app.js
Created December 23, 2010 00:33
The code for http://jsno.de./flot/
var express = require('express'),
app = module.exports = express.createServer();
app
// Configuration
.configure(function () {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyDecoder());
app.use(express.methodOverride());
/* Javascript plotting library for jQuery, v. 0.6.
*
* Released under the MIT license by IOLA, December 2007.
*
*/
// first an inline dependency, jquery.colorhelpers.js, we inline it here
// for convenience
/* Plugin for jQuery for working with colors.
@jfsiii
jfsiii / img2data.js
Created January 30, 2011 23:30
base64 encoding images in NodeJS
/*
* Based on https://gist.github.com/583836 from http://stackoverflow.com/questions/3709391/node-js-base64-encode-a-downloaded-image-for-use-in-data-uri.
* Neither that gist nor this one work for me in 0.2.x or 0.3.x.
*/
var request = require('request'),
BufferList = require('bufferlist').BufferList,
sys = require('sys'),
bl = new BufferList(),
url = 'http://nodejs.org/logo.png'
;