Skip to content

Instantly share code, notes, and snippets.

@arnogues
arnogues / actions.js
Created November 22, 2019 14:25
Set actions on any project, (useful for debugging)
function queue(list, lastValue) {
var item = list[0];
if (!list.length) {
console.log("Queue debug end");
return;
}
switch (typeof item) {
case "number":
setTimeout(function() {
@arnogues
arnogues / urlJsonconverter.js
Last active October 24, 2018 16:05
Simple url to json and json to url converter
function jsToUrl(js) {
return [""]
.concat(Object.keys(js))
.reduce((accumulator, key, i) => {
return `${accumulator}&${key}=${encodeURIComponent(js[key])}`;
})
.replace(/^&/, "?");
}
function urlToJs(url) {
@arnogues
arnogues / javascript.jquery.class.template.webstorm.js
Last active July 6, 2016 05:34
Javascript Class Template for webstorm
/**
* Class Jquery Prototype ${USER} ${DATE}
*/
/* global Utils */
'use strict';
(function ($, context) {
var ${className} = context.${className} = function () {
this.init.apply(this, arguments);
@arnogues
arnogues / gist:2157a552cc8a5b520454
Created February 18, 2015 10:47
color converter
<h1>grayscale calculator</h1>
<input type="text" id="input" value="#DA0000" />
<input type="text" id="output" />
<script>
var inputField = document.getElementById('input');
var outputField = document.getElementById('output');
@arnogues
arnogues / Utils.js
Created November 13, 2014 23:35
Utils class, that need to be saved
'use strict';
/* globals window, jQuery */
(function ($) {
window.Utils = {
getOptionsFromDom: function (pluginName, element) {
element = $(element);
var pn = pluginName.toLowerCase(),
pnRe = new RegExp('^' + pn),
@arnogues
arnogues / substitute.js
Created November 7, 2014 04:43
Substitute function with deep object access
function substitute(string, object, regexp) {
return string.replace(regexp || (/\\?\{([^{}]+)\}/g), function (match, name) {
if (match.charAt(0) == '\\') return match.slice(1);
name = name.split('.');
var tmpObj = object;
while(name.length) {
tmpObj = tmpObj[name.splice(0,1)[0]];
}
return (tmpObj != null) ? tmpObj : '';
});
/**
* Class Prototype ${USER} ${DATE}
*/
/* global Utils */
'use strict';
(function ($, context) {
var ${NAME} = context.${NAME} = function () {
this.init.apply(this, arguments);
@arnogues
arnogues / queue.js
Last active August 29, 2015 13:56
queue sync or async function. You can put sleep between the functions
function queue() {
var i = 0,
arr = arguments;
(function next() {
var args = arguments;
if (i < arr.length) {
var func = arr[i++];
var funcArgs = [].concat(next, [].slice.call(args));
if (!isNaN(func)) setTimeout(function () {
arr[i++].apply(this, funcArgs)
@arnogues
arnogues / Notifier.js
Last active January 3, 2016 08:19
Simple Notifier that uses jQuery for notification
Notifier = {
register: function (evt, func) {
$(Notifier).on(evt, func);
},
remove: function (evt, func) {
$(Notifier).off(evt, func);
},
notify: function (evt, params) {
@arnogues
arnogues / Prototype.class.js
Last active October 14, 2019 16:16
Js prototype with jquery plugin integration
/**
*
*/
(function ($) {
PluginName = function () {
this.init.apply(this, arguments);
};