Skip to content

Instantly share code, notes, and snippets.

View etoxin's full-sized avatar

Adam Lusted etoxin

View GitHub Profile
@etoxin
etoxin / service.js
Created November 19, 2018 04:09
Nice small clean Service
/**
* API Service
* @async
* @returns {Promise<Object>}
*/
async function Service() {
let response = await fetch('/api.json');
if (response.ok) return await response.json();
throw new Error(response.statusText);
}
@etoxin
etoxin / Render.js
Last active October 25, 2018 02:50
Recursive react render for dom or cms
RenderModal(settings) {
const { modalIsOpen, targetDomNode } = settings;
const closeModal = () => {
this.RenderModal(
Object.assign(settings, {
modalIsOpen: false
})
);
};
@etoxin
etoxin / Map.js
Last active October 8, 2018 03:33
Map and Set basics
let members = new Map([["Sam", 56], ["Sandy", 86]]);
let youngestMemberAge = Math.min(...members.values()) // 86
let Over60s = new Map(
[...members].filter(([name, age]) => 60 < age)
);
let Over60sUserNames = new Map(
[...members].map(([name, age]) => {
@etoxin
etoxin / preventDefaultDebugger.md
Last active September 17, 2018 00:28
event.preventDefault debugger

How to use

preventDefaultDebugger.js

Add this to your devtools console.

var oldEPD = Event.prototype.preventDefault;
Event.prototype.preventDefault = function() {
 debugger;
@etoxin
etoxin / assert.js
Created June 28, 2018 07:26
Assert
/**
* @param {boolean} condition
* @param {string} msg
*/
export function assert (condition, msg) {
if (!condition) throw new Error(`[assert error] ${msg}`)
}
@etoxin
etoxin / Functional_Programming_Cheat_Sheet.md
Last active January 7, 2021 13:58
Functional Programming Cheat Sheet

Functional Programming Cheat Sheet

Arrow Functions (Fat Arrows)

Arrow functions create a concise expression that encapsulates a small piece of functionality. Additionally, arrows retain the scope of the caller inside the function eliminating the need of self = this.

Example

// const multiply = function(x,y) {

@etoxin
etoxin / Parallelism.js
Created February 8, 2018 00:23
Parallelism
// Will take 1000ms total!
async function series() {
await wait(500);
await wait(500);
return "done!";
}
// Would take only 500ms total!
async function parallel() {
const wait1 = wait(500);
@etoxin
etoxin / README.md
Created January 30, 2018 04:38
Sample Readme.md
console[console.info ? 'info' : 'log'] ("Hello world")