Skip to content

Instantly share code, notes, and snippets.

View floydnoel's full-sized avatar
👨‍💻

Floyd Noel floydnoel

👨‍💻
View GitHub Profile
@floydnoel
floydnoel / parse-node-args.js
Created September 26, 2023 00:20
Code snippet to parse Node.js arguments (with an equal sign) into a dictionary
const args = process.argv
.filter((arg) => arg.includes("="))
.reduce((acc, cur) => {
let split = cur.split("=");
acc[split[0]] = split[1];
return acc;
}, {});
console.log(args);
// run command: node parse-node-args.js foo=bar baz=qux
@floydnoel
floydnoel / updateHeadTag.js
Created September 25, 2023 21:25
Updates HTML Head tags, such as meta tags
// update a head tag
function updateHeadTag({ tag = "meta", ...attrs }) {
// input check
const attrKeys = Object.keys(attrs);
if (attrKeys.length < 1) {
return console.error(
`updateHeadTag() received no attributes to set for ${tag} tag`
);
}
@floydnoel
floydnoel / addMetaTag.js
Last active September 2, 2023 18:25
HTML page meta tag setter
// update head meta tags
function addMetaTag({ name, property, value }) {
// console.log({ name, property, value });
// input checks
if (value === null || value === undefined) {
return console.error(
`addMetaTag received no value to set for tag: ${name ?? property}`
);
}
@floydnoel
floydnoel / NoteField.swift
Created July 11, 2021 14:15
A TextEditor component with a placeholder
//
// NoteField.swift
//
// Created by Floyd Noel on 7/11/21.
//
import SwiftUI
struct NoteField: View {
var label: String
const getSearchParams = () =>
window.location.search
.substring(1)
.split('&')
.reduce((acc, searchParam) => {
const [name, value] = searchParam.split('=');
return { ...acc, [name]: value };
}, {});
@floydnoel
floydnoel / forgetAboutCors.js
Last active April 30, 2018 18:14
CORS problem? forget about it!
// takes a string URL, and returns a string URL which allows the request to proceed without CORS blocking
const forgetAboutCors = u => `https://cors-anywhere.herokuapp.com/${u}`
// example usage: forgetAboutCors(`https://clinicaltrials.gov/ct2/show/${'NCT03512561'}?displayxml=true`)
const scriptAlreadyLoaded = urlString => Array.prototype.slice.call(document.scripts).filter(s => s.src).map(s => s.src).contains(urlString)
@floydnoel
floydnoel / git-ignore-cleaner.sh
Last active October 27, 2024 02:45
Remove all files from a Git repo based on the .gitignore file
#!/bin/bash
echo "Cleaning up any git ignored files..."
# copy and paste the line below to get the same results as running this script
git rm --cached `git ls-files -ic --exclude-from=.gitignore`
echo "Finished clean up."
# source: https://stackoverflow.com/questions/13541615/how-to-remove-files-that-are-listed-in-the-gitignore-but-still-on-the-repositor/13541721