Skip to content

Instantly share code, notes, and snippets.

View sifu's full-sized avatar

Siegmund Führinger sifu

View GitHub Profile
diff --git a/mustache.js b/mustache.js
index 58e6460..1fba949 100644
--- a/mustache.js
+++ b/mustache.js
@@ -118,6 +118,8 @@ var Mustache = function() {
return that.render(content, that.merge(context,
that.create_context(row)), partials, true);
}).join("");
+ } else if(that.is_object(value)) { // Object, Use it as subcontext!
+ return that.render(content, that.merge(context, that.create_context(value)), partials, true);
{{#a_object}}
<h1>{{title}}</h1>
<p>{{description}}</p>
<ul>
{{#a_list}}
<li>{{label}}</li>
{{/a_list}}
</ul>
{{/a_object}}
function template( targetNode, templateNode_ ) {
var self = {};
var templateNode = templateNode_ || targetNode;
var templateString = $( templateNode ).innerHTML.replace( /^\s*<!--/, '' ).replace( /-->\s*$/, '' );
targetNode.innerHTML = '';
self.render = function( data ) {
targetNode.innerHTML = Mustache.to_html( templateString, data );
return data;
};
return self;
var http = require( 'http' ),
parse = require( 'querystring' ).parse;
http.createServer( function( request, response ) {
var body = '';
request.on( 'data', function( chunk ) {
body += chunk.toString( );
} );
request.on( 'end', function( ) {
console.info( parse( body ) );
@sifu
sifu / gist:632177
Created October 18, 2010 13:04
consume whole http body
function HttpBodyServer( callback ) {
return http.createServer( function( request, response ) {
var body = '';
request.on( 'data', function( chunk ) {
body += chunk.toString( );
} );
request.on( 'end', function( ) {
callback( request, response, body );
} );
} );
@sifu
sifu / README.txt
Created October 19, 2010 13:49
autoreload a server
depends on http://github.com/mikeal/watch
@sifu
sifu / USAGE.txt
Created November 3, 2010 14:27
jsoneval
eg. to print the ids of all documents within a couchdb database:
curl "http://127.0.0.1:5984/somedb/_all_docs" | jsoneval.js "body.rows.forEach( function( r ){ console.info( r.id ) } );"
@sifu
sifu / vimrc
Created November 11, 2010 10:20
save file; focus last chrome window; reload the current page;
nmap <F10> :wall<Cr>:silent execute "!xdotool search Chrome windowfocus --sync key --clearmodifiers ctrl+r" <Cr> <C-l>
diff --git a/lib/http-console.js b/lib/http-console.js
index 322a8d1..f763bf3 100644
--- a/lib/http-console.js
+++ b/lib/http-console.js
@@ -50,7 +50,7 @@ this.Console.prototype = new(function () {
if (this.options.json) { this.headers['Content-Type'] = 'application/json' }
if (this.options.auth) {
this.headers['Authorization'] = "Basic " +
- new(Buffer)(this.options.auth.user + ':' + this.options.auth.password).toString('base64');
+ new(Buffer)(this.options.auth.username + ':' + this.options.auth.password).toString('base64'
#!/usr/bin/env node
var input = '011101010110111001100011011000110110110000100000011011110111000101101110>
var i=0, message='', input;
while( charCodeAsBinary = input.substr( i, 8 ) ) {
message += String.fromCharCode( parseInt( charCodeAsBinary, 2 ) );
i+=8;
}
console.info( message );