Skip to content

Instantly share code, notes, and snippets.

@snown
snown / gist:1251355
Created September 29, 2011 17:32
TextExpander AppleScript Snippet for next or previous X day of the week
(*
AppleScript for use in a TextExpander snippet to print out the date of the next Monday (or whatever day of the week you define) in the format of "Monday 13 April 2011"
Maintained at https://gist.github.com/1251355
*)
(* Set Weekday and Month names in your language of choice here (for example, French) *)
set day_names to {"dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"}
set month_names to {"janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"}
@snown
snown / Bashful.sh
Last active December 24, 2020 05:16
One Off Shell Script Dependencies
#!/usr/bin/env bash
function bashful {
(
local bashful_path="$(find /tmp/ -name "jmcantrell-bashful-*" -print -quit 2>/dev/null)"
if [[ -z ${bashful_path:+x} ]]; then
curl -fsSL https://github.com/jmcantrell/bashful/tarball/master | tar xz -C /tmp/
bashful_path="$(find /tmp/ -name "jmcantrell-bashful-*" -print -quit 2>/dev/null)"
fi
if [[ -z ${bashful_path:+x} ]]; then
@snown
snown / NSColor+HexString.swift
Created September 25, 2020 17:54
an NSColor extension to convert CSS style hex string into a color and back
extension NSColor {
convenience init?(hexString: String) {
var hexString: String = hexString.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
if hexString.hasPrefix("#") {
let startIndex = hexString.index(hexString.startIndex, offsetBy: 1)
hexString = String(hexString[startIndex...])
}
if hexString.count == 3 || hexString.count == 4 {
hexString = hexString.reduce(into: "") { (paddedHex, hexCharacter) in
@snown
snown / here_printf.sh
Created May 6, 2020 16:01
Wrapper around printf to take in a heredoc
#!/usr/bin/env bash
function here_printf {
local format=${1:-"%b\n"}
local text
read -r -d '' text
printf "${format}" "${text}"
}
@snown
snown / script_bashful.sh
Created May 5, 2020 16:24
Dynamic Bashful
#!/usr/bin/env bash
function bashful {
(
local bashful_path="$(find /tmp/ -name "jmcantrell-bashful-*" -print -quit 2>/dev/null)"
if [[ -z ${bashful_path:+x} ]]; then
curl -fsSL https://github.com/jmcantrell/bashful/tarball/master | tar xz -C /tmp/
bashful_path="$(find /tmp/ -name "jmcantrell-bashful-*" -print -quit 2>/dev/null)"
fi
if [[ -z ${bashful_path:+x} ]]; then
@snown
snown / random.sh
Created May 2, 2020 16:03
Return a random number between two limits
# Return a random number between two limits
#-------------------------------------------------------------------------------
function random {
#default to numbers between 1-10
local _min="${1:-1}"
local _max="${2:-10}"
local diff=$((${_max}-${_min}+1))
echo -n "$(($((${RANDOM}%${diff}))+${_min}))"
}
@snown
snown / get_script_path.sh
Created May 2, 2020 06:10
Find the path to the bash script file currently being executed
get_script_path () {
printf '%s' "$(realpath "${BASH_SOURCE[0]}")"
}
@snown
snown / Get Frame.md
Last active April 28, 2020 19:09
Grab a frame of a video file (Specifically for Mac)

Installing the script

sudo mkdir -p /usr/local/bin &>/dev/null ; sudo curl -fsSL -o /usr/local/bin/getframe "https://gist.githubusercontent.com/snown/a818afd18c9e2087731bdf7ce0a85195/raw/getframe.sh" && sudo chmod a+x /usr/local/bin/getframe

Install the folder action

getframe install-folder-action

@snown
snown / uniqueElements.sh
Created March 26, 2020 22:12
Get unique elements in Bash
function uniqueElements {
local input_array=( "$@" )
local IFS=$'\n'
local RESULT=( $(printf '%s\n' ${input_array[@]} | awk '!seen[$0]++') )
# Uncomment if you want the result to come back in a format that can easily be passed to `declare -a`
#echo $(declare -p RESULT | sed "s/^[^(]*// ; s/'$//")
echo "${RESULT[@]}"
}
@snown
snown / roll.sh
Last active February 5, 2018 20:11
bash script for rolling nerdy dice
#!/usr/bin/env bash
# Only supports one die, and the most basic notation right now
# would like to complete support for dice notation as specified here:
# https://en.wikipedia.org/wiki/Dice_notation
_basename() { #portable basename
[ -z "${1}" ] && return 1 || _basename__name="${1%%/}"
[ -z "${2}" ] || _basename__suffix="${2}"
case "${_basename__name}" in
/*|*/*) _basename__name="$(expr "${_basename__name}" : '.*/\([^/]*\)')" ;;