Add a one-sentence description of this project. and a link to the live demo.
- completed feature: What this feature does
- pending feature: What this feature does
| /** | |
| * Returns an array with arrays of the given size. | |
| * | |
| * @param myArray {Array} Array to split | |
| * @param chunkSize {Integer} Size of every group | |
| * | |
| * https://binbytes.com/blog/split-an-array-into-chunks-of-a-given-size-in-javascript | |
| */ | |
| function chunkArray(myArray, chunk_size) { | |
| let results = []; |
| function promiseMap(xs, f) { | |
| const reducer = (ysAcc$, x) => | |
| ysAcc$.then(ysAcc => f(x).then(y => ysAcc.push(y) && ysAcc)); | |
| return xs.reduce(reducer, Promise.resolve([])); | |
| } | |
| /* Example */ | |
| const axios = require('axios'); |
| var get_ie_version = function () { | |
| var sAgent = window.navigator.userAgent; | |
| var Idx = sAgent.indexOf("MSIE"); | |
| // If IE, return version number. | |
| if (Idx > 0) { | |
| return parseInt(sAgent.substring(Idx+ 5, sAgent.indexOf(".", Idx))); | |
| } | |
| // Condition Check IF IE 11 and or MS Edge | |
| else if ( !!navigator.userAgent.match(/Trident\/7\./) |
| var options={poll_time:200},localStorageShim=function(t){var e,r="__localStorageShim",n="pairs",o="localStorageShim Error: ";const a=[];try{if(localStorage.setItem("a",4),4!=localStorage.getItem("a"))throw 1;e=function(){this.setItem=function(t,e){return localStorage.setItem(t,e)},this.getItem=function(t){return localStorage.getItem(t)}}}catch(c){e=function(){var e,c,i=indexedDB.open(r,7),u={},s=function(){e=db.transaction(n).objectStore(n),e.openCursor().onsuccess=function(t){var e,r=t.target.result;r&&(e=r.value,u[e.k]=[e.v,r.key],r["continue"]())}},l=function(t,r){if(t+="",r+="",!u[t]||u[t][0]!==r){u[t]=u[t]||[],u[t][0]=r,clearInterval(c),e=db.transaction(n,"readwrite").objectStore(n);var o=[{k:t,v:r}];u[t][1]&&o.push(u[t][1]),e=e.put.apply(window,o),e.onsuccess=d}},d=function(){s(),c=setInterval(s,t.poll_time)};i.onupgradeneeded=function(t){var e,r=t.target.result;try{e=t.target.transaction.objectStore(n)}catch(o){e=r.createObjectStore(n,{autoIncrement:!0})}try{e.createIndex("k","k",{unique:!0}),e.createI |
| // Author: Renat Tuktarov (renat@sourcerer.io) | |
| const retry = function(fn, prev) { | |
| return new Promise((current, reject) => { | |
| const resolve = _ => (prev && prev()) || current(); | |
| fn(resolve, delay => { | |
| setTimeout(_ => { | |
| retry(fn, resolve); | |
| }, delay); |
| function RateLimit(fn, delay, context) { | |
| var queue = [], timer = null; | |
| function processQueue() { | |
| var item = queue.shift(); | |
| if (item) | |
| fn.apply(item.context, item.arguments); | |
| if (queue.length === 0) | |
| clearInterval(timer), timer = null; | |
| } |
| /* | |
| Sort array of objects based on another array | |
| Original function: | |
| function mapOrder (array, order, key) { | |
| array.sort( function (a, b) { | |
| var A = a[key], B = b[key]; | |
| if (order.indexOf(A) > order.indexOf(B)) { | |
| return 1; | |
| } else { |
Add a one-sentence description of this project. and a link to the live demo.
| For those unfamiliar with 'advanced' i/o redirection in bash: | |
| 1) 2>&- ("close output file descriptor 2", which is stderr) has the same result as 2> /dev/null; | |
| 2) >&2 is a shortcut for 1>&2, which you may recognize as "redirect stdout to stderr". | |
| See the Advanced Bash Scripting Guide i/o redirection page for more info. | |
| – mikewaters Dec 21 '11 at 19:48 | |
| -comment from : https://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script |
| /* Extend the Underscore object with the following methods */ | |
| // Rate limit ensures a function is never called more than every [rate]ms | |
| // Unlike underscore's _.throttle function, function calls are queued so that | |
| // requests are never lost and simply deferred until some other time | |
| // | |
| // Parameters | |
| // * func - function to rate limit | |
| // * rate - minimum time to wait between function calls | |
| // * async - if async is true, we won't wait (rate) for the function to complete before queueing the next request |