Skip to content

Instantly share code, notes, and snippets.

View n8jadams's full-sized avatar

Nate Adams n8jadams

View GitHub Profile
@n8jadams
n8jadams / git-prune-local.sh
Created February 3, 2021 17:03
A nice git function to clean up your local branches. Drop in your bashrc file(s).
# Deletes local branches that have been deleted on the remote
function gpl() {
# Determine the name of the trunk
trunkname=$(git symbolic-ref --short refs/remotes/origin/HEAD | sed 's@^origin/@@')
# List branches that have been removed from origin and write to file
git branch --merged $(git rev-parse $trunkname) | awk '{$1=$1};1' | egrep -v "(^\*|^\s*($trunkname)$)" > /tmp/branchesToPurge
# Open the file for editing
vim /tmp/branchesToPurge
@n8jadams
n8jadams / convert-apple-alac-to-mp3.sh
Created October 16, 2021 12:28
Convert Apple ALAC (.m4a) to .mp3
#!/bin/sh
# Find and convert all apple alac (.m4a) files to .mp3.
find . -name '*.m4a' -print0 | while read -d '' -r file; do
ffmpeg -i "$file" -n -acodec libmp3lame -ab 320k "${file%.m4a}.mp3" < /dev/null && rm "$file"
done
@n8jadams
n8jadams / testing-ie11-with-vituralbox.md
Last active October 30, 2021 12:55
Testing IE11 with VirtualBox

Testing IE11 with Virtualbox

First, follow the instructions here to get a Windows 7/8.1 IE11 virtualbox image.

Then in Virtualbox:

  1. File > Host Network Manager, click Create+
  2. Click the newly created Host Network (probably named vboxnet0) and copy the IPv4 Address. (Probably 192.168.56.1.)
  3. Import the .ova image, fill out the options (defaults are fine,) and start up the VM.
  4. In the VM's Settings menu, click Network and set Attached to: to be Host-only Adapter. The Name: field should populate with vboxnet0.
@n8jadams
n8jadams / download-object-as-json-file.js
Created March 1, 2022 19:15
A function to help downloading a javascript object as a JSON file
export async function downloadObjectAsJSONFile(object, filename) {
if(!filename.endsWith('.json')) {
filename = `${filename}.json`
}
const json = JSON.stringify(object)
const blob = new Blob([json],{ type:'application/json' })
const href = await URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = href
link.download = filename
@n8jadams
n8jadams / read-inputs-cli.js
Last active February 9, 2023 18:20
Read in non-hidden and hidden inputs in a cli
const readline = require("readline");
const question = (query) =>
new Promise((resolve) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question(`${query}\n`, (value) => {
rl.close();
@n8jadams
n8jadams / copy-to-clipboard.js
Last active August 19, 2022 20:56
Copy some text to the clipboard
// Newer and preferred way
function copyToClipboard(text) {
navigator.clipboard.writeText(text)
}
// Support on old browsers
function copyToClipboard(text) {
const tmpInput = document.createElement('input')
tmpInput.value = text
tmpInput.type = 'text'
@n8jadams
n8jadams / csv-string-to-arr-of-objs.js
Created April 29, 2022 21:47
Convert a CSV string to an array of objects
function csvStringToArrOfObjs(csvString) {
const rowsWithColumNames = csvString.split('\n')
const columnNames = rowsWithColumNames[0].split(',').map(columnName => columnName.replace('\r', ''))
const rows = rowsWithColumNames.slice(1)
return rows.map(row => {
const obj = {}
const parts = row.split(',').map(columnName => columnName.replace('\r', ''))
columnNames.forEach((columnName, index) => {
obj[columnName] = parts[index]
})
@n8jadams
n8jadams / not-function.js
Created April 29, 2022 21:59
not(someFunction(someArgs))
const not = fn => (...args) => !fn.apply(null, args)
@n8jadams
n8jadams / parse-query-string.js
Created April 30, 2022 01:53
Parse query string. (Just use URLSearchParams instead of this)
function parseQueryString(query) {
query = query.substring(query.indexOf('?') + 1);
let re = /([^&=]+)=?([^&]*)/g;
let decodeRE = /\+/g;
let decode = function(str) {
return decodeURIComponent(str.replace(decodeRE, ' '));
};
@n8jadams
n8jadams / remove-all-css-from-page.js
Created April 30, 2022 01:55
A quick script to remove all styling from a website
document.querySelectorAll('style, link[rel="stylesheet"]').forEach(el => el.parentNode.removeChild(el))
document.querySelectorAll('[style]').forEach(el => el.style = null)