Skip to content

Instantly share code, notes, and snippets.

View atomize's full-sized avatar
🎹
♩♩

Berti atomize

🎹
♩♩
View GitHub Profile
@atomize
atomize / isEmpty.js
Created October 8, 2018 17:00
ES6 null-undefined-''-[]-{} type check
const isEmpty = value => {
if (typeof value === 'number') return false
else if (typeof value === 'string') return value.trim().length === 0
else if (Array.isArray(value)) return value.length === 0
else if (typeof value === 'object') return value == null || Object.keys(value).length === 0
else if (typeof value === 'boolean') return false
else return !value
}
@atomize
atomize / index.html
Last active October 5, 2018 18:37
Old School lazy load
<img src="blank.gif" data-src="my_image.png" width="600" height="400" class="lazy">
<img src="blank.gif" data-src="my_image.png" width="600" height="400" class="lazy">
<img src="blank.gif" data-src="my_image.png" width="600" height="400" class="lazy">
<img src="blank.gif" data-src="my_image.png" width="600" height="400" class="lazy">
@atomize
atomize / fillSelectMenu.js
Created October 1, 2018 18:53
Dynamically fill select options with a large list using document.createDocumentFragment() - much more efficient that document.createElement()
const fillMenu = (list, selector) => {
let subsSelect = document.getElementById(selector);
subsSelect.innerHTML = "";
let fragment = document.createDocumentFragment();
list.sort()
list.unshift("Select...")
list.forEach(function (element) {
let opt = document.createElement("option");
opt.value = element;
opt.innerHTML = element;
@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 = {
@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 / 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 / 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 / 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 / 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 / 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 = [];