Skip to content

Instantly share code, notes, and snippets.

View dantman's full-sized avatar

Daniel Friesen dantman

View GitHub Profile
<?php
function starts_with($haystack, $needle) {
return substr($haystack, 0, strlen($needle)) === $needle;
}
$domain = $_SERVER["HTTP_HOST"] ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"];
$base = "http://$domain";
$draft = starts_with($domain, "draft.");
// -*- coding: UTF-8 -*-
// Dummy module names, not final. Ignore my JS1.8isms
var {Stream} = require('stream');
var {Socket} = require('socket');
var {StreamerHelper} = require('streamer-helper'); // You can ignore this one, just one of my personal ideas
var StreamHelpers = require('stream-helpers'); // Another thing you can ignore
var {BufferStream} = require('bufferstream'); // Another user-level
function MultipartStreamParser() {
this.boundary = false;
if ( isNaN(Date.parse("2000-01-01T00:00:00.000Z")) ) {
// This browser has not implemented parsing of ISO dates
(function(NativeDate) {
var Date = function(arg) {
if ( this instanceof Date || this instanceof NativeDate ) {
var d = isString(arg) ?
new NativeDate(Date.parse(arg)) : // We explicitly pass it through parse
// We have to manually make calls depending on argument length here
arguments.length >= 7 ?
new NativeDate(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]) :
function Dummyware(app) {
return function(env) {
var r = app(env);
var istream = r.body;
var ostream = r.body = new MemoryStream();
async(function chunked() {
if ( istream.canRead )
ostream.write(istream.read(Infinity));
if ( !istream.seenEOF )
async(chunked);
function app(env) {
var ostream = new MemoryStream();
var times = 5;
setTimeout(function t() {
times--;
ostream.write((new Date).toString())
ostream.write("\n");
if ( times <= 0 )
ostream.close();