Skip to content

Instantly share code, notes, and snippets.

@silentrob
silentrob / stream_mp4
Created April 8, 2011 04:45
Connect Stream mp4 Example
require('connect').createServer(
connect.static(__dirname + '/videos', { maxAge: 0 }),
function(req, res) {
res.setHeader('Content-Type', 'text/html');
res.end('<video width="300px" src="/OLD_BOY.mp4" controls="controls" autoplay="autoplay"></video>');
}
).listen(process.env.PORT || 4000);
var templateData = this.responseText;
var data = {
person: {
name : {
first : 'Rob',
last : 'Ellis'
},
age: 30,
location : {
// Fails
main = document.getElementById("main");
var div = document.createElement('DIV');
div.innerHTML = "<body>This is BODY2</body>";
main.appendChild(div);
// Works
main = document.getElementById("main");
var div = document.createElement('DIV');
var body = document.createElement('BODY');
(ironman) ~/projects/personal $ sudo npm build apricot
npm it worked if it ends with ok
npm configfile /Users/ironman/.npmrc
npm cli [ 'build', 'apricot' ]
npm version 0.1.20
npm required jsdom->= 0.0.1
npm found jsdom@0.0.1
npm createMain ./lib/apricot
npm linkLib apricot-0.0.1
npm ! WARNING !
UC 1
<p id="test">A simple <b>test</b> string.</p>
A simple <b>test</b> string.
UC 2
<p>This is a test file</p>
This is a test file
Looping 1
<li>Item 1</li>
// Using JavaScript (node.js) to Read Variable Length Quantity
// See - http://en.wikipedia.org/wiki/Variable-length_quantity for more information
Utils = {}
Utils.arrayToHex = function(ar) {
for (var i=0;i<ar.length;i++) {
ar[i] = (ar[i].toString(16) == 0) ? "00" : ar[i].toString(16);
}
return "0x" + ar.join('');
}
system.use("info.webtoolkit.Base64");
var username = "admin";
var password = "password";
var auth = "Basic " + Base64.encode(username + ":"+ password);
checkAuth = function() {
if (!this.request.headers.hasOwnProperty('Authorization') || (this.request.headers.hasOwnProperty('Authorization') && (auth != this.request.headers['Authorization']))) {
this.response.headers['WWW-Authenticate'] = 'Basic realm="SmartAPI"';
this.response.code = 401;
this.response.body = "Not Authorized\n";
Module.prototype.load = function (filename) {
var self = this;
this.filename = filename;
function require (url) {
return loadModule(url, self);
}
var x = system.filesystem.get(this.filename);
// module.js
// This loader is derived from nodes loader. :)
// Fixme: path is always absolute ie requre('/math');
// Fixme: bug in loading order, and dependency support is weak
// Fixme: using a modified version of filesystem.get to look in the code directory.
// - SNIP From: /Applications/Smart.app/Contents/Resources/Image/lib/perl5/site_perl/5.10.0/RSP/Extension/Filesystem.pm
/**
- in
return {
'filesystem' => {
var sys = require('sys');
var posix = require('posix');
var ini = {'global':{}};
var parseINI = function(d) {
var section = 'global';
var lines = d.split('\n');