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 / itetate_arguments.js
Last active December 31, 2015 20:59
A simple snippet for iterating arguments
var eachArg = function(args, fn, start_from, end_where) {
var i = start_from || 0;
while (i < args.length) {
if (end_where !== undefined && i === end_where)
return i;
if (fn !== undefined)
fn(i, args[i]);
i++;
}
return i;
@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 / 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 / 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 / require.js
Last active October 31, 2017 20:04
JavaScript require / import / include modules through namespaces
var _rmod = _rmod || {}; //require module namespace
_rmod.LOADED = false;
_rmod.on_ready_fn_stack = [];
_rmod.libpath = '';
_rmod.imported = {};
_rmod.loading = {
scripts: {},
length: 0
};
@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 / _neat.scss
Created July 6, 2018 12:27
Neat 3.0.0 in one SASS file for Shopify theme dev
@charset "UTF-8";
// Neat 3.0.0
// http://neat.bourbon.io
// Copyright 2012 thoughtbot, inc.
// MIT License
/// This variable is a sass map that overrides Neat's default grid settings.
/// Use this to define your project's grid properties including gutters and
/// total column count.
///
@stamat
stamat / slug.js
Created August 16, 2019 23:08
Wordpress like simple sanitize_title for javascript. Not checking for accents, since it is a slow process.
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}
function slug(s) {
s = s.toLowerCase().trim();
s = s.replace(/[^a-z0-9\s_-]/ig, '');
return s.replace(/[\s\uFEFF\xA0]+/ig, '-');
@stamat
stamat / waiter.js
Created December 24, 2019 21:02
Simple recursive function that waits for DOM changes, used to wait for embedded-JS generated third party code, when no hook apparent or available
function waiter(selector, callback, timeout) {
var elem = document.querySelectorAll(selector);
if (!elem.length) {
if (timeout === undefined) {
timeout = 100;
}
setTimeout(function(){
waiter(selector, callback, timeout);