Skip to content

Instantly share code, notes, and snippets.

View hns's full-sized avatar

Hannes Wallnoefer hns

View GitHub Profile
@hns
hns / gist:663932
Created November 5, 2010 10:24
subclassing arrays in ES5 - working or not?
// The following attempts to extend arrays *kind* of work with ES5
// except you get Objects masquerading as Arrays. Seems like an
// oversight in ES5 Object.create() (15.2.3.5) to me.
// simple approach where you don't need a constructor:
arr1 = Object.create(Array.prototype, {x: {value: 1}});
// use a proper constructor
function SubArray() {}
SubArray.prototype = new Array();
@hns
hns / app.js
Created November 3, 2010 15:07
browser modules - decoupling dependency declaration and loading from module definition
// load modules passed in first argument, call function argument when loaded.
// note that modules are loaded and defined, but not yet executed (the module function is not called)
load(["single", "multi", "package"], function(require) {
// modules listed above are available via synchronous require() here.
// note that any of the modules may itself invoke load(), causing invocation of
// this function to be further delayed if the modules haven't been loaded yet
load("baz", function(require) {
@hns
hns / jquery.hiccup.js
Created October 30, 2010 18:44
Tentative hiccup.js JQuery plugin
// if running in a CommonJS environment use exports object,
// otherwise set up as hiccup.html()
if (typeof exports === "undefined" || !exports) {
var hiccup = {};
}
(function(exports) {
var html = exports.html = function() {
var buffer = [];
// this is just a JSGI application like it used to be
var app = exports.app = new Application();
// delegate requests to other apps/modules exporting their own JSGI app
app.route({vhost: ["foo.com", "*.foo.com"]}, "foo/config");
app.route("/admin/", "admin");
app.route("/", "actions");
// method-specific mapping of requests to controller/action functions
app.get("/", function() {});
@hns
hns / hiccup-examples.js
Created October 29, 2010 19:29
Simple hiccup implementation in JavaScript
// First argument (or array element for nested arrays) is tag name.
// Second can optionally be an object, in which case it is used to
// supply attributes. All others are added to the tag's body.
html("p", {"class": "foo"}, "hello world", "!")
'<p class="foo">hello world!</p>'
// Shortcuts for denoting id and class attributes
html("p#foo.bar.baz", "hello world!")
'<p id="foo" class="bar baz">hello world!</p>'
@hns
hns / ringoproxy.js
Created October 28, 2010 00:39
A minimal RingoJS HTTP proxy
var httpclient = require("ringo/httpclient");
var {Headers} = require("ringo/webapp/util");
var {startsWith} = require("ringo/utils/strings");
var base = "http://localhost:8080";
var sites = {
"frau.helma.at": "/frauhelma",
"pool.helma.at": "/pool",
"henso.com": "/henso",
diff --git a/lib/ringo/storage/sql/mapping.js b/lib/ringo/storage/sql/mapping.js
index 21399db..3a3bccb 100644
--- a/lib/ringo/storage/sql/mapping.js
+++ b/lib/ringo/storage/sql/mapping.js
@@ -73,6 +73,9 @@ var Mapping = function(type, definition) {
for (var propName in definition.properties) {
var propDefinition = definition.properties[propName];
var propMapping = null;
+ if (typeof propDefinition === "string") {
+ propDefinition = {"type": propDefinition};
var http = require('http');
var Buffer = require('buffer').Buffer;
http.createServer(function (req, res) {
var n = 1024, b;
for (var i = 1; i <= 30; i++)
b = new Buffer(n);
res.writeHead(200, {"Content-Type": "text/plain"});
res.end(b);
}).listen(8000);
var {AsyncResponse} = require("ringo/webapp/response");
var {setTimeout} = require("ringo/scheduler");
exports.app = function(req) {
var res = AsyncResponse(req, 30000, true);
setTimeout(function() {
res.start(200, {"Content-Type": "text/html; charset=utf-8"});
res.write("Hallo Welt");
}, 1000);
setTimeout(function() {
/*
* A simple ringo websocket extension. Add the following code to your webapp's
* config.js file to enable it:
*
* exports.extensions = ["websocket-extension"];
*/
var websocket = require("ringo/webapp/websocket");
exports.serverStarted = function(server) {