Skip to content

Instantly share code, notes, and snippets.

View KyleMit's full-sized avatar

Kyle Mitofsky KyleMit

View GitHub Profile
@KyleMit
KyleMit / filePathReplace.js
Created September 20, 2020 13:44
How do I change file extension with javascript?
// https://stackoverflow.com/a/47949440/1366033
function changeExt(fileName, newExt) {
var pos = fileName.includes(".") ? fileName.lastIndexOf(".") : fileName.length
var fileRoot = fileName.substr(0, pos)
var output = `${fileRoot}.${newExt}`
return output
}
console.log(changeExt("img.jpeg", "jpg")) // img.jpg
@KyleMit
KyleMit / report.json
Last active September 16, 2020 00:33
github directory lightouse
{
"requestedUrl": "https://github.directory/",
"finalUrl": "https://github.directory/",
"lighthouseVersion": "6.3.0",
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/84.0.4147.140 Safari/537.36",
"fetchTime": "2020-09-16T00:32:46.173Z",
"environment": {
"networkUserAgent": "Mozilla/5.0 (Linux; Android 7.0; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4143.7 Mobile Safari/537.36 Chrome-Lighthouse",
"hostUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/84.0.4147.140 Safari/537.36",
"benchmarkIndex": 926.5
@KyleMit
KyleMit / auto-mapper.js
Created June 29, 2020 22:00
NBS Porting - Auto Mapper
// ==UserScript==
// @name NBS Porting - Auto Mapper
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Automatically map answers in the from and to answer fields when porting pages in NBS
// @author KyleMit
// @match https://ahs-nbs-dev.ahs.state.vt.us/nbs/PortPage.do
// @grant none
// ==/UserScript==
@KyleMit
KyleMit / index.js
Created June 28, 2020 17:58
parse-rgb w/ unit tests
module.exports = parseRGB
function parseRGB(string) {
return {
r: 255,
g: 255,
b: 255
}
@KyleMit
KyleMit / equals.js
Created June 27, 2020 03:59
JavaScript Reference vs Value Equality
var personOne = {name: "Kyle", age: 22}
var personTwo = {name: "Kyle", age: 22}
// referential equality
let refEqual = personOne == personTwo
let isValueEqual = (obj1, obj2) => {
return Object.keys(obj1).every(key => obj1[key] == obj2[key])
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@KyleMit
KyleMit / .eleventy.js
Created May 8, 2020 19:40
11ty / Nunjucks Shortcode
module.exports = function(eleventyConfig) {
eleventyConfig.addShortcode("year", () => new Date().getFullYear());
}
@KyleMit
KyleMit / Remove Capitalization Changes.md
Last active April 24, 2020 20:25
Remove Capitalization Changes

Here's an example of two strings to run through a diffing processes

let oldText = "start case old Text"
let newText = "start Case next Text"

These get tokenized by each word (separated by a space) and passed into difflib which produces the following result:

@KyleMit
KyleMit / 12-days.js
Last active February 18, 2020 14:19
12 Days Challenge
let gifts = ["partridge in a pear tree", "turtle doves", "French hens", "calling birds", "gold rings", "geese a-laying", "swans a-swimming", "maids a-milking", "ladies dancing", "lords a-leaping", "pipers piping", "drummers drumming"]
let numLookup = [
{ cardinal: "a", ordinal: "first" },
{ cardinal: "two", ordinal: "second" },
{ cardinal: "three", ordinal: "third" },
{ cardinal: "four", ordinal: "fourth" },
{ cardinal: "five", ordinal: "fifth" },
{ cardinal: "six", ordinal: "sixth" },
{ cardinal: "seven", ordinal: "seventh" },
@KyleMit
KyleMit / IterateObject.md
Created September 3, 2019 00:58
Looping through an object in JavaScript

There's a pretty standard way to manipulate an array and return the slightly transformed contents using .map(), but there's a lot of options when it comes to objects, opening the door to potential confusion. Here's an approach to looping through an object in JS

Let's start with the following object:

let authors = {
    "Kyle": {"description": "Likes Cats"},
    "Brian": {"description": "Automation champion"},
    "Sandra": {"description": "Swiss army knife"}
}