This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getObjectProperty = (object, properties) => { | |
return properties.length === 0 ? object : getObjectProperty(object[properties[0]], properties.slice(1)) | |
} | |
const setObjectProperty = (object, properties, value) => { | |
if (properties.length === 1) { | |
object[properties[0]] = value | |
} | |
getObjectProperty(object, properties.slice(0, properties.length - 1))[properties[properties.length - 1]] = value | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; My first linux assembly program (runs on 64 bit linux) | |
; Compile with `nasm -felf64 hello.asm && ld hello.o -o hello` | |
global _start | |
section .text | |
_start: | |
; Call 'write' system call | |
mov rax, 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns a number that will have up to `max` decimal places. | |
*/ | |
function maxToFixed (num, max) { | |
return parseFloat(num.toFixed(max)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Displays in error in the first matched CSS selector given. | |
* This relies on having a hidden attribute set on element at start state. | |
* @param error: string The error message | |
* @param selector: string A CSS selector that matches the element displaying the error | |
*/ | |
function displayError (error, selector) { | |
const errorElement = document.querySelector(selector) | |
errorElement.innerHTML = error | |
errorElement.removeAttribute('hidden') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function post (url, data) { | |
let request = { | |
body: JSON.stringify(data), | |
method: 'post', | |
headers: { 'Content-Type': 'application/json' } | |
} | |
return fetch(url, request) | |
.then(async (response) => { | |
return response.json() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param a First array | |
* @param b Second array | |
* @returns boolean; true if a and b are equal, false otherwise | |
*/ | |
function arraysEqual (a, b) { | |
if (a.length !== b.length) { | |
return false | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @param variable The variable you want to get the type of | |
* @returns 'string', 'number', 'array', 'function', or 'object' | |
*/ | |
function type (variable) { | |
return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param object json | |
* @param string[] properties | |
* @returns boolean | |
*/ | |
function jsonHasProperties (json, properties) { | |
return properties.every(prop => json.hasOwnProperty(prop)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HelloWorld extends HTMLElement { | |
createdCallback () { | |
console.log('RUNNING -- createdCallback') | |
const templates = document.getElementById('templates').import | |
const template = templates.getElementById('hello-world-template') | |
this.attachShadow({ mode: 'open' }) | |
.appendChild(template.content.cloneNode(true)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSiblings (target) { | |
return [ | |
...getUntilNull(target, 'previousElementSibling'), | |
...getUntilNull(target, 'nextElementSibling') | |
] | |
} | |
/** | |
* Collects HtmlElements until null is return from the provided property on target | |
* |