Skip to content

Instantly share code, notes, and snippets.

View queckezz's full-sized avatar

Fabian Eichenberger queckezz

View GitHub Profile
@queckezz
queckezz / new.js
Last active December 16, 2015 11:39
instantiate a function without using the 'new' keyword
function constructor( args ) {
if( !(this instanceof constructor) ) return new constructor( args );
// ... constructor stuff
}
constructor.prototype.method() {};
constructor.method();
/*
@queckezz
queckezz / app.js
Created April 21, 2013 23:59
component-build(1) everytime a 'GET' request comes in.
var exec = require('child_process').exec;
app.all('*', function( req, res, next ) {
exec('component build --out ./public/js', next)
})
@queckezz
queckezz / contains.js
Last active December 17, 2015 04:28
Returns true or false depending on whether a string contains a char or not.
function contains( element, search ) {
return element.indexOf( search ) != -1 ? true : false;
}
@queckezz
queckezz / pick.js
Created May 26, 2013 18:31
use 'arg' and if its a falsey value, it uses 'def'
function pick( arg, def ) {
return ( typeof arg == 'undefined' ? def : arg )
}
@queckezz
queckezz / extend.js
Last active December 19, 2015 10:59
Object.extend()
Object.defineProperty(Object.prototype, 'extend', {
enumerable: false,
value: function( from ) {
Object.getOwnPropertyNames( from ).forEach(function( name ) {
if ( name in this ) {
Object.defineProperty( this, name, Object.getOwnPropertyDescriptor( from, name ));
}
});
return this;
@queckezz
queckezz / global.js
Created July 26, 2013 15:15
Outputs all self-defined variables on the window object.
for( var b in window ) {
if( window.hasOwnProperty(b) ) console.log( b );
}
@queckezz
queckezz / a.txt
Last active December 21, 2015 06:19
Dead-simple Generator implementation preventing callback hell.
file:a
@queckezz
queckezz / index.js
Last active December 23, 2015 20:09
Simple Buffer collector example
var http = require('http');
var url = process.argv[2];
http.get(url, function (res) {
//res.setEncoding('utf-8');
var bufs;
res.on('data', function (buf) {
/* For Fluid Images, Flash and HTML5 videos */
img,
embed,
object,
video {
max-width: 100%;
}
/* <3 */
@queckezz
queckezz / parse.js
Created October 5, 2013 15:35
parse 'str=value' like document.cookie to objects
var decode = decodeURIComponent;
function parse(str) {
var obj = {};
var pairs = str.split(/ *; */);
var pair;
if ('' == pairs[0]) return obj;
for (var i = 0; i < pairs.length; ++i) {
pair = pairs[i].split('=');
obj[decode(pair[0])] = decode(pair[1]);