Skip to content

Instantly share code, notes, and snippets.

View n8henrie's full-sized avatar

Nathan Henrie n8henrie

View GitHub Profile
@n8henrie
n8henrie / Make AppleTV Screensaver.applescript.js
Last active December 3, 2021 19:44
Apple JXA script to create and populate an album with a random sample of favorite photos
#!/usr/bin/osascript -l JavaScript
// Apple JXA script to create and populate an album with a random sample of favorite photos
// Author: @n8henrie
// Rename from .applescript.js to .applescript (.js for GitHub syntax highlighting)
// https://stackoverflow.com/a/11935263/1588795
function getRandomSubarray(arr, size) {
var shuffled = arr.slice(0), i = arr.length, temp, index;
while (i--) {
index = Math.floor((i + 1) * Math.random());
#!/usr/bin/env python3
import argparse
import sys
import typing as t
__author__ = "Benjamin Kane"
__version__ = "0.1.0"
__doc__ = f"""
Pretty-print simple Bash command from one line of stdin
@n8henrie
n8henrie / congress.ipynb
Last active December 20, 2019 04:26
A quick look at congress bills in recent history by unified or divided congress
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python3
"""Send files to MacOS trash bin via applescript."""
import os
from pathlib import Path
import sys
import subprocess
from typing import Iterable, Union
def trash(paths: Iterable[Union[str, Path]]) -> int:
@n8henrie
n8henrie / mount-image.sh
Created May 6, 2019 22:04
Script to mount all partitions from an image file into a temporary directory
#!/bin/bash
set -Eeuf -o pipefail
if [ ! "$(whoami)" = root ]; then
echo "Please run as root"
exit 1
fi
TMP="$(mktemp -d)"
@n8henrie
n8henrie / repair.sh
Last active July 7, 2021 00:16
Fix time machine backup
#!/usr/bin/env bash
# http://tonylawrence.com/post/unix/fixing-corrupted-time-machine-backups/
set -euf -o pipefail
set -x
if [[ $(whoami) != 'root' ]]; then
echo "Please run as root" > /dev/stderr
exit 1
fi
@n8henrie
n8henrie / setup_linux.sh
Last active November 10, 2017 23:43
Set up basic Linux preferences and settings
#! /bin/bash
echo '# Begin n8henrie settings' >> "${HOME}"/.inputrc
echo '" Begin n8henrie settings' >> "${HOME}"/.vimrc
echo '# Begin n8henrie settings' >> "${HOME}"/.bash_aliases
echo '# Begin n8henrie settings' >> "${HOME}"/.bashrc
curl 'https://gist.githubusercontent.com/n8henrie/c69de3e3c9d99668965473d1d315c855/raw' >> "${HOME}"/.inputrc
curl 'https://gist.githubusercontent.com/n8henrie/3e251bfe9ac9d5ce7421/raw' >> "${HOME}"/.vimrc
curl 'https://gist.githubusercontent.com/n8henrie/6cf7785d0ae025e706522e6e64c3fba2/raw' >> "${HOME}"/.bash_aliases
@n8henrie
n8henrie / .bashrc
Last active October 31, 2019 12:41
My basic .bashrc for Linux systems
# ~/.bashrc: executed by bash(1) for non-login shells.
# Reset path (or else it gets longer each time this is sourced)
export PATH=$(getconf PATH)
# http://unix.stackexchange.com/questions/40678/can-i-make-there-are-stopped-jobs-harder-to-kill
prompt_command() {
job_count=$(jobs | wc -l | tr -d ' ')
if [ $job_count -gt 0 ] ; then
prompt_job="[$job_count]"
@n8henrie
n8henrie / .bash_aliases
Created November 6, 2017 00:17
My basic bash_aliases for a Linux system
aur_download() {
aur_url="https://aur.archlinux.org$(curl -s "https://aur.archlinux.org/packages/$1" | ack -o "(?<=href=\").*?tar.gz(?=\">)")"
echo "$aur_url"
read -p "Download the above url? [yn] " response
case $response in
[Yy])
wget "$aur_url"
echo "You still need to do the usual: tar -xvf; cd; makepkg -s; pacman -U;"
;;
*)
@n8henrie
n8henrie / get_opencv3.sh
Last active June 19, 2018 02:53
Download, build, and install opencv on Raspberry Pi 3
#! /bin/bash
set -euf -o pipefail
function cleanup {
for pid in "${opencv_download_pid:-''}" "${contrib_download_pid:-''}" "${pip_install_pid:-''}"; do
if [ -z "${pid}" ]; then
kill "${pid}"
fi
done