Skip to content

Instantly share code, notes, and snippets.

View jankuca's full-sized avatar

Jan Kuča jankuca

  • Prague, Czech Republic
  • 09:45 (UTC +01:00)
View GitHub Profile
@jankuca
jankuca / examples.js
Created January 1, 2011 13:49
JS library for converting MongoDB-like selectors to SQL
// Basic usage
mongo2sql({ 'a': 'b', 'c': 'd' });
"[a] = 'b' AND [c] = 'd'"
mongo2sql({ 'a': { $gt: 123 }, 'c': 'd' });
"[a] > 123 AND [c] = 'd'"
mongo2sql({ $or: [{ 'a': 'b'}, { 'c': 'd' }] });
"( ( [a] = 'b' ) OR ( [c] = 'd' ) )"
@jankuca
jankuca / require.js
Created January 17, 2011 12:33
require.js for front-end
(function(doc) {
var head = doc.documentElement,
isHeadReady,
isDomReady,
domWaiters = [],
queue = [], // waiters for the "head ready" event
handlers = {}, // user functions waiting for events
scripts = {}, // loadable scripts in different states
isAsync = doc.createElement("script").async === true || "MozAppearance" in doc.documentElement.style || window.opera;
@jankuca
jankuca / wysihat.js
Created January 17, 2011 14:05
Modified WysiHat v0.2.1; not forked the original repository because rake is required
/* WysiHat - WYSIWYG JavaScript framework, version 0.2.1
* (c) 2008-2010 Joshua Peek
*
* WysiHat is freely distributable under the terms of an MIT-style license.
*--------------------------------------------------------------------------*/
(function (window) {
var WysiHat = {};
@jankuca
jankuca / prototype.js
Created January 17, 2011 14:10
Modified and JSLint-complaint Prototype.JS; not forked because of rake
/* Prototype JavaScript framework, version 1.6.1
* (c) 2005-2009 Sam Stephenson
*
* Prototype is freely distributable under the terms of an MIT-style license.
* For details, see the Prototype web site: http://www.prototypejs.org/
*
*--------------------------------------------------------------------------*/
window.Prototype = {
Version: '1.6.1',
@jankuca
jankuca / base64.js
Created January 20, 2011 15:39
Base64 Node.js module
exports.Base64 = {
'_keyStr': "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
'encode': function (input) {
var output = '';
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = this._utf8_encode(input);
@jankuca
jankuca / ejs.js
Created January 20, 2011 15:54
EJS Node.js module; checkout the branch "client" for a client-side version
var rsplit = function (string, regex) {
var result = regex.exec(string),
retArr = [],
first_idx,
last_idx,
first_bit;
while (result !== null) {
first_idx = result.index;
last_idx = regex.lastIndex;
if (first_idx !== 0) {
@jankuca
jankuca / index.js
Created January 20, 2011 16:21
RelativeDate Node.js module
exports.parse = function (string, format) {
var match = string.match(/^(\+|-)\s*(\d+)\s*([a-z]{3})/i);
var add;
if (!match) {
add = 0;
} else {
add = parseInt(match[2], 10);
switch (match[3]) {
case 'min':
add *= 60;
@jankuca
jankuca / uuid.js
Created January 21, 2011 08:20
UUID JavaScript library; based on the current timestamp, the user's browser, the current URL and a random number
goog.provide('uuid');
var uuid = function () {
var parts = new Array(4);
// a - unix timestamp
var time = Math.round(new Date().getTime() / 1000);
parts[0] = time.toString(16).substring(0, 8);
@jankuca
jankuca / shortcut.js
Created February 3, 2011 19:12
Shortcut JavaScript library
/**
* Shortcut Library
* --
* @version 2.01.B
* @author Binny V A
* @modifier Jan Kuča <[email protected]>
* @license BSD
*/
(function (window) {
var document = window.document;
@jankuca
jankuca / examples.js
Created February 28, 2011 22:31
Advanced JavaScript (ECMAScript 5) Inheritance
var A = Function.inherit(function () {
console.log('construct A');
}, {
'aa': function () {
console.log('aa A');
},
});
var B = A.inherit(function () {
console.log('construct B');