Skip to content

Instantly share code, notes, and snippets.

View jankuca's full-sized avatar

Jan Kuča jankuca

  • Prague, Czech Republic
  • 08:08 (UTC +02:00)
View GitHub Profile
@jankuca
jankuca / utils.js
Created March 16, 2011 00:09
JavaScript Kit
(function () {
if (!Object.defineProperty) return;
Object.defineProperty(Function.prototype, 'initializing', {
value: false,
writable: true
});
Object.defineProperty(Function.prototype, '$super', {
value: function () {
@jankuca
jankuca / index.js
Created March 17, 2011 09:48
Simple Facebook Graph API Node.js Client
var HTTPS = require('https');
var QueryString = require('querystring');
/**
* Facebook API Wrapper
* @constructor
* @param {Object} info Info about the Facebook application
*/
var Client = function (info) {
if (!info.id) {
@jankuca
jankuca / object-events.coffee
Created June 5, 2011 16:37
Object Events - JavaScript event abstraction layer
###
! Object Events
! ==
! A little abstraction layer that connects all Object instances
! to the native event engine and adds custom event support.
! --
! Author: Jan Kuča <jan@jankuca.com>, http://jankuca.com
! Version: 1.0
! Last revision: 05 Jun 2011
###
@jankuca
jankuca / examples.coffee
Created June 21, 2011 09:35
Asynchronous JS Iterator
# == Synchronous loop ==
# It does the same as forEach.
input = ['a', 'b', 'c']
output = {}
iter = new Iterator input, (item, next, i) ->
output[item] = item
console.log 'Finished iteration ' + i
do next
iter.run ->
@jankuca
jankuca / index.js
Created July 14, 2011 18:43
Node.js ARGV parser
function parseInput() {
var input = {
modes: [],
args: [],
params: {},
};
var param_key = null;
var parts = process.argv.slice(2);
parts.forEach(function (part) {
@jankuca
jankuca / deferred.js
Created August 4, 2011 09:12
JavaScript Deferred
goog.provide('Deferred');
/**
* Handles deferred calls
* @constructor
*/
var Deferred = function () {
this.pending_ = [];
this.completed = false;
this.status = null;
@jankuca
jankuca / index.js
Created August 5, 2011 14:46
Colored console for node.js
var stdout = process.stdout;
var info = console.info;
var warn = console.warn;
var error = console.error;
var DEFAULT = "\033[m";
var BLUE = "\033[1;34m";
var YELLOW = "\033[1;33m";
var RED = "\033[1;31m";
@jankuca
jankuca / example.js
Created November 12, 2011 16:40
gzip for native node.js http.Server
var http = require('http');
var gzip = require('http-gzip');
var server = http.createServer(function (req, res) {
gzip(req, res);
res.writeHead(200, {
'content-type': 'text/plain'
});
res.write('I am gonna be gzip encoded, dude!');
@jankuca
jankuca / utils.js
Created March 25, 2012 18:19
JS Kit (node.js)
Object.defineProperty(Function.prototype, 'initializing', {
value: false,
writable: true,
});
Object.defineProperty(Function.prototype, '$super', {
value: function () {
throw new Error('The $super method is not available.');
},
writable: true,
});
@jankuca
jankuca / injector.js
Created May 14, 2012 23:05
Injector.js
/**
* @constructor
*/
function Injector() {
/**
* @type {!Object.<string, function(Injector=): !Object>}
*/
this.factories = {};