Skip to content

Instantly share code, notes, and snippets.

View atomize's full-sized avatar
🎹
♩♩

Berti atomize

🎹
♩♩
View GitHub Profile
@atomize
atomize / localStorageShim.min.js
Created July 11, 2018 20:29
houd1ni/localStorage-by-IndexedDB-shim - Helps MS Edge be a real browser. [https://github.com/houd1ni/localStorage-by-IndexedDB-shim]
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
@atomize
atomize / msBrowserAgentDetect.js
Created July 11, 2018 20:31
Check browser for Microsoft Edge/IE
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\./)
@atomize
atomize / promise_map.js
Created August 17, 2018 21:30 — forked from tokland/promise_map.js
Execute an array of promises sequentially and collect the result
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');
@atomize
atomize / chunk_array.js
Created August 24, 2018 10:21
Returns an array with arrays of the given size.
/**
* 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 = [];
@atomize
atomize / webpack.config.js
Created August 24, 2018 20:00
Advanced proxy setup for webpack development server
// https://raw.githubusercontent.com/webpack/webpack-dev-server/master/examples/general/proxy-advanced/webpack.config.js
'use strict';
// our setup function adds behind-the-scenes bits to the config that all of our
// examples need
const { setup } = require('../../util');
module.exports = setup({
context: __dirname,
entry: './app.js',
@atomize
atomize / MapOfArray-in-JS.js
Created August 28, 2018 20:50
The Map object holds key-value pairs. Any value (both objects and primitive values) may be used as either a key or a value. This is the relation of Map() with Array objects
var kvArray = [['key1', 'value1'], ['key2', 'value2']];
// Use the regular Map constructor to transform a 2D key-value Array into a map
var myMap = new Map(kvArray);
myMap.get('key1'); // returns "value1"
// Use the Array.from function to transform a map into a 2D key-value Array
console.log(Array.from(myMap)); // Will show you exactly the same Array as kvArray
@atomize
atomize / groupAlphaArray.example.txt
Last active September 12, 2018 16:59
Groups an array of items alphabetically, putting items that start with numbers in a '0-9' group.
let arrayToGroup = ['Alpha','Alpha2','Centaur','Dudeman', 'Ladygirl', '888','999','&^%$'];
groupAlphaArray(arrayToGroup)
/****OUPUT****/
[
{
"group":"A",
"children":["Alpha","Alpha2"]
},
{
@atomize
atomize / tradeStreamer.js
Created September 12, 2018 17:59
CCC Study
function tradeStreamer(fsym) {
var dataUrl = "https://min-api.cryptocompare.com/data/subs?fsym=" + fsym;
return fetch(dataUrl, {
"credentials": "omit",
"headers": {},
"referrer": "https://cryptoqween.github.io/streamer/trade/",
"referrerPolicy": "no-referrer-when-downgrade",
"body": null,
"method": "GET",
"mode": "cors"
@atomize
atomize / dirtyFlatten.js
Created September 17, 2018 06:28
Dirty flattener.
async function dirtyFlatten(res) {
let vals = Object.values(res)
vals = vals.map((x) => {
return Object.values(x).reduce((a, c) => {
if (typeof c === 'object' || typeof c === 'array') {
c.map(entry => a.push(entry))
} else {
a.push(c)
}
return a;
@atomize
atomize / ccc.js
Last active October 5, 2018 16:35
WIP CryptoCompare API+WebSockets example ES6
let imageUrls;
let globalmenu = {};
const appInfo = {
aggSubs: [],
allSubs: [],
actualSubs: new Set(),
pair: ["???", "???"]
};
const params = {