Skip to content

Instantly share code, notes, and snippets.

View johnloy's full-sized avatar

John Loy johnloy

View GitHub Profile
@johnloy
johnloy / transformObj.js
Created October 18, 2021 16:45 — forked from juliarose/transformObj.js
Recursively transform key/values in object, including array values
/**
* Recursively transform key/values in object, including array values
*
* Also can act as a basic deep clone method
* @param {Object} obj - Object to transform
* @param {Object} [transforms={}] - Object containing transformation functions
* @param {Function} [transform.keys] - Function for transforming keys from 'obj'
* @param {Function} [transform.values] - Function for transforming values from 'obj'
* @param {Number} [level=0] - Level of recursion, passed as the 2nd argument to a transform function
* @returns {Object} Transformed object
function getRandomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
{
"basics": {
"name": "John Loy",
"label": "Web Engineer",
"image": "",
"email": "loy.john@gmail.com",
"phone": "(434) 981-7529",
"url": "https://johnloy.me",
"summary": "I’ve done most things “web”, for over 20 years, beginning my career as a graphic designer, evolving into a Web Engineer. At various points in my career I’ve called myself a webmaster, web UX designer, back-end engineer, and front-end engineer. These days I might call myself a front-end-leaning full-stack engineer, but I prefer to just call myself flexible. Also, I’m a developer who “gets” design!",
"location": {
find /home/example -iname "*.txt" -exec grep -Li "mystring" {} \+
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Next: Chrome",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
},
/**
* This is a better alternative to using 'forwards'
* fill mode, as it allows you to update inline styles
* after the animation has completed. Contrast with:
*
* element.animate({
* { opacity: '0.2' },
* {
* duration: 500,
* easing: 'ease-in-out',
@johnloy
johnloy / bundle.js
Created May 6, 2021 20:49
Webpack runtime example
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/******/ "use strict";
rollup -c ; cat my-element.bundled.js | gzip -9 | wc -c ; rm my-element.bundled.js
// tzName is one of the tz database names at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
// Example: 'Pacific/Honolulu' (UTC-10)
function getUTCOffset(tzName, date) {
date = new Date(date || Date.now());
date.setMilliseconds(0);
// 1) Get the local UTC offset
// ---------------------------
// Convert date UTC offset to true hours offset.
// Date.prototype.getTimezoneOffset() confusingly returns positive