Skip to content

Instantly share code, notes, and snippets.

@tenbits
tenbits / eval.js
Created Dec 19, 2012
Komodo IDE Macro. Unit Testing Thing. Evaluate selected or full source code. Evaluates also code in comment: /*{test} .... */
View eval.js
var view = ko.views.manager.currentView,
scimoz = view.scimoz,
selection = scimoz.selText || scimoz.text,
service = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService),
log = function() {
var message = '';
for (var i = 0; i < arguments.length; i++) {
message += arguments[i] + ' ';
}
@tenbits
tenbits / dragger.js
Created Jan 30, 2013
element dragger - simple requestAnimationFrame example
View dragger.js
window.dragger = (function() {
var requestAnimationFrame = (function() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function(callback) {
return setTimeout(callback, 17);
}
})();
@tenbits
tenbits / inline-eval.js
Created Feb 17, 2013
komodo inline eval macro
View inline-eval.js
var view = ko.views.manager.currentView,
scimoz = view.scimoz,
selection = scimoz.selText,
result = null,
log = function() {
var message = '';
for (var i = 0; i < arguments.length; i++) {
message += arguments[i] + ' ';
}
@tenbits
tenbits / exif-date-touch.js
Last active Jul 31, 2022
nodejs script to set a file modification date from EXIF
View exif-date-touch.js
/**
* Change file modification time to the date from EXIF
*
* System Requirements:
*
* > npm install -g includejs
* > npm install -g exif
*
* Usage:
*
@tenbits
tenbits / RegExpUtil.js
Last active Dec 17, 2015
string to regexp
View RegExpUtil.js
RegExp.fromString = function(str, flags) {
return new RegExp(str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), flags);
};
@tenbits
tenbits / obj_normalize.js
Last active Dec 26, 2015
Object normalization - needs to be improved
View obj_normalize.js
var obj_normalize = (function() {
function runNormalizer(currentValue, normalizer) {
if (typeof normalizer === 'function')
return normalizer(currentValue);
// other types of normalization, like Regexp-Replace
return currentValue.replace(normalizer[0], normalizer[1]);
View Deferred
function Deferred(){}
(function(){
Deferred.prototype = {
_isAsync: true,
_done: null,
_fail: null,
_always: null,
@tenbits
tenbits / Class.Store.js
Last active Feb 4, 2016
Class Store. Same interface for XHR Transport and MongoDB driver
View Class.Store.js
// atma-class
// common node.js and browser
var Article = Class('Article', {
Base: Class.Serializable({
date: Date
}),
_id: null,
date: null,
body: '',
View gist:ec7f0155b57b2d61a6cc90ef3d5f8b49
var x = new RegExp( "/" )
console.log(x.test( "/hello" ));
var serializedRegexParser = /^\/(.+)\/(\w+)?$/
var serializedRegex = x.toString();
console.log('serializedRegex:', serializedRegex);
var matches = serializedRegexParser.exec(serializedRegex);
var [full, regexString, regexFlags] = matches;