Skip to content

Instantly share code, notes, and snippets.

View sifu's full-sized avatar

Siegmund Führinger sifu

View GitHub Profile
@sifu
sifu / app.js
Created February 11, 2016 12:30
make angular-new-router (v0.5.3) and gulp-ng-templates work together
function dashCase( str ) {
return str.replace( /([A-Z])/g, function( $1 ) {
return '-' + $1.toLowerCase( );
} );
}
$componentLoaderProvider.setTemplateMapping( function( name ) {
var dashName = dashCase(name);
return 'components/' + dashName + '/' + dashName + '.html';
} );
@sifu
sifu / track.js
Created December 22, 2012 11:37
a google app script UiApp, that tracks clicks on a button in a spreadsheet.
function doGet() {
var app = UiApp.createApplication();
var button = app.createButton('Click Me');
app.add(button);
var label = app.createLabel('The button was clicked.')
.setId('statusLabel')
.setVisible(false);
app.add(label);
@sifu
sifu / groupby.js
Created October 15, 2012 09:19
a group-by implementation
function groupBy( array, key ) {
var result = {};
var by, property;
var item, i=0;
var isAlreadyFunction = typeof( key ) === 'function';
if( isAlreadyFunction ) {
by = key;
} else {
by = function( item ) {
return item[ key ];
@sifu
sifu / test.js
Created August 30, 2012 14:15
proxy http -> https (cloudant)
#!/usr/bin/env node
var httpProxy = require( 'http-proxy' );
var server = httpProxy.createServer( function( req, res, proxy ) {
proxy.proxyRequest( req, res, {
host: 'sifu.cloudant.com',
port: 443,
https: true
} );
@sifu
sifu / setdefault.js
Created July 18, 2012 16:27
set a default value for a key and push to it in one line
var a = [ 'one', 'two', 'one', 'one' ];
var result = {};
a.forEach( function( key ) {
( result[ key ] || ( result[ key ] = [] ) ).push( key )
} );
console.info( result );
@sifu
sifu / utils.js
Created July 17, 2012 09:02
quick & dirty module pattern for modules to be used in the browser environment and node.js
(function(exports){
exports.someExportedFunction = function( ) { };
})(typeof(window)!=='undefined'&&(window.utils={})||exports);
#!/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 );
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'
@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>
@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 ) } );"