Skip to content

Instantly share code, notes, and snippets.

View stamat's full-sized avatar
💥

Nikola Stamatović stamat

💥
View GitHub Profile
@stamat
stamat / Events.js
Created December 17, 2013 17:41
Supreme Events class from IVARTECH library
/**
* @file IVARTECH Events Class | Mediator pattern
* @author Nikola Stamatovic Stamat <stamat@ivartech.com>
* @copyright IVARTECH http://ivartech.com
* @version 20130313
*
* @namespace ivar.patt
*/
//TODO: write support for ['foo','baz','baz']
@stamat
stamat / chain.js
Last active December 31, 2015 10:59
Chain chain chain! Array function chain prototype. Chain the functions in a simple and readable thus elegant way!
Array.prototype.chain = function() {
var res = undefined;
var args = [];
var i = 0;
while (arguments.hasOwnProperty(i)) {
args.push(arguments[i]);
i++;
}
@stamat
stamat / sortProperties.js
Last active December 19, 2015 08:09
Object property sorting
//SORT WITH STRINGIFICATION
sortProperties = function(o, fn) {
var res = {};
var props = keys(o);
props = fn ? props.sort(fn): props.sort();
for(var i = 0; i < props.length; i++) {
res[props[i]] = o[props[i]];
}
@stamat
stamat / orderedStringify.js
Last active December 19, 2015 08:09
Object ordered stringify
//SORT WITH STRINGIFICATION
var orderedStringify = function(o, fn) {
var props = [];
var res = '{';
for(var i in o) {
props.push(i);
}
props = props.sort(fn);
@stamat
stamat / HashCache.js
Last active February 19, 2016 00:19
A hash table value value storage for quick seek in large lists of big objects/arrays/strings. It uses CRC32 algorithm to convert supplied values into integer hashes and produce more elegant solution escaping data redundancy and heavy memory loads but also leaning on native hash map implementation for seek speed and optimization.
/**
* A hash table value value storage for quick seek in large lists of big objects/arrays/strings.
* It uses CRC32 algorithm to convert supplied values into integer hashes and produce more elegant solution escaping data redundancy and heavy memory loads but also leaning on native hash map implementation for seek speed and optimization.
*
* @author Nikola Stamatovic Stamat < stamat@ivartech.com >
* @copyright ivartech < http://ivartech.com >
* @version 1.0
* @date 2013-07-02
* @namespace ivar.data
*/
@stamat
stamat / dictUpdate.py
Last active December 19, 2015 05:19
Dictionary deep merge
#Complete dictionary merge
def update(d1, d2):
for k,v in d2.items():
if k in d1 and type(d1[k]) is dict and type(v) is dict:
update(d1[k], v)
else:
d1[k] = v
return d1
#Deep merges two dictionaries to a given level, after that level it only overwrites the values
@stamat
stamat / importFromUri.py
Last active November 15, 2017 12:32
Dynamically imports python modules by given module URI
import os
import imp
def importFromURI(self, uri, absl=False):
if not absl:
uri = os.path.normpath(os.path.join(os.path.dirname(__file__), uri))
path, fname = os.path.split(uri)
mname, ext = os.path.splitext(fname)
no_ext = os.path.join(path, mname)
@stamat
stamat / Map.js
Last active October 10, 2016 22:08
Java like Map class for JavaScript, a wrapper arround JavaScript's native key value hash tree storage inside objects.
/**
* @file IVARTECH Map data class
* @author Nikola Stamatovic Stamat <stamat@ivartech.com>
* @copyright IVARTECH http://ivartech.com
* @version 20130313
*
* @namespace ivar.data
*/
/**
@stamat
stamat / equal.js
Last active August 19, 2016 15:29
Compare objects and arrays...
//Returns the object's class, Array, Date, RegExp, Object are of interest to us
var getClass = function(val) {
return Object.prototype.toString.call(val)
.match(/^\[object\s(.*)\]$/)[1];
};
//Defines the type of the value, extended typeof
var whatis = function(val) {
if (val === undefined)
@stamat
stamat / fancytime.js
Created May 3, 2013 20:52
Twitter-like fancy time
function fancyDate(then, now, suffix) {
if(now === undefined)
now = new Date();
if(suffix === undefined)
suffix = 'ago';
var thenMs = null;
typeof then === 'number' ? thenMs = then : thenMs = then.getTime();
var nowMs = null;