Skip to content

Instantly share code, notes, and snippets.

View AndreasMadsen's full-sized avatar

Andreas Madsen AndreasMadsen

View GitHub Profile
Hi David
Do you plan to attend to this event: http://meetup.mathiasbuus.eu/ ?

In order to get the piccolo framework intro a more stable state I'm refactoring major and minor parts intro standalone modules.

A major part is the node-like module system. The system should be broken down intro two modules. A client-side and a server-side module. The server-side seams necessary, since the node-core alternative is totally blocking (not ideal in dynamic server resource loading) and there might be security concerns, where a localized module system is important. The client-side is necessary since no module system exists.

The thought is to provide two modules (in result one almost-isomorfic-api-only module). They would have the following API:

var http = require('http');

var ServerModuleSystem = require('ServerModuleSystem');
var net = require('net');
var mdns = require('mdns');
var serviceKey = mdns.tcp('custom-name');
var discover = mdns.createBrowser(serviceKey);
discover.on('serviceUp', function (service) {
console.log({
port: service.port,
var net = require('net');
var mdns = require('mdns');
var serviceKey = mdns.tcp('custom-name');
var discover = mdns.createBrowser(serviceKey);
discover.on('serviceUp', function (service) {
console.log({
port: service.port,
@AndreasMadsen
AndreasMadsen / hackTheDom.js
Created October 29, 2012 13:57
size of TextNode - DOM Hack
// This is the coolest code snippet I (Mr. Mad) have every created
// It will magicly get the size of a textnode, by createing a context
// range and get the client rects of that range.
// It will then combine the rects to one rect, and thereby get the size
// of the text node.
// Note that by any standarts a TextNode has no size.
var range = document.createRange();
range.selectNode(node);
var rect = range.getBoundingClientRect();
@AndreasMadsen
AndreasMadsen / hack.js
Created October 27, 2012 18:46
Hack javascript - delete
var log = typeof print === 'undefined' ? console.log : print;
// get v8 internal DELETE
var DELETE;
delete ({}[{ toString: function x(){ DELETE = x.caller; } }]);
// try it out
var obj = {hi: true};
DELETE.call(obj, 'hi', 0); // BUG: hack.js:5: RangeError: Maximum call stack size exceeded
Andreas-Madsen-MacBook-Pro:GitHub Andreas$ unlink
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
Andreas-Madsen-MacBook-Pro:GitHub Andreas$ rm
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
Andreas-Madsen-MacBook-Pro:GitHub Andreas$
@AndreasMadsen
AndreasMadsen / toBit.js
Created October 6, 2012 11:32
to bit one liner
var toBits = function (num) { return num.toString(2).split('').map(Number).reverse(); };
toBits(1) // [1]
toBits(2) // [1, 0]
toBits(4) // [1, 0, 0]
toBits(7) // [1, 1, 1]
toBits(8) // [1, 0, 0, 0]
@AndreasMadsen
AndreasMadsen / testcase.js
Created September 22, 2012 10:07
Domain.active offset
var http = require('http');
var domain = require('domain');
var server = new http.createServer(function (req, res) {
res.end('Not implemented');
});
server.listen(9222);
@AndreasMadsen
AndreasMadsen / WhatIHaveDone.md
Last active February 13, 2022 16:15
Playing with smartos