Skip to content

Instantly share code, notes, and snippets.

@ze-
ze- / 0-DOC
Last active February 27, 2017 15:56
bastard alarm
In general, please pre-test and adjust before reliance. In particular, note
potential sensitivity to the more restrictive $PATH cron often has over your
standard login shell, as well as the config variables (especially mpopts) at
the beginning of bastard_alarm.sh. I personally call it indirectly through
a helper script that sets a suitable PATH for it and other things, as well
as turns on my monitor and keeps it on until a nap script shuts it off, with
'xset dpms force on -dpms s reset', stops soothing background sounds started
by a nap script, etc...
bastard_alarm.sh:
@ze-
ze- / minustime.sh
Created September 18, 2014 00:28
Shows the duration between 2 dates/times.
#!/usr/bin/env bash
[[ $# -lt 2 ]] && printf "$(basename $0) <startdate> <enddate>\n" >/dev/stderr && exit 1
shopt -s extglob
gfs=$(($(date -d "$2" +%s)-$(date -d "$1" +%s)))
duration=" $(($gfs/3600/24/365))y $(printf "%3id %2ih %2im %2is" $(($gfs/3600/24%365)) $(($gfs/3600%24)) $(($gfs/60%60)) $(($gfs%60)))"
printf "${duration/+(+( )0[ydhm])}\n"
@ze-
ze- / napwhen.sh
Last active August 29, 2015 14:06
Shows remaining duration til the next nap and its wakeup. Depends on minustime.sh: https://gist.github.com/ze-/0ad16f27c769da01fec7
#!/bin/bash
wha="$(basename "${0%when*}")" # name/symlink me as napwhen.sh, buddywhen.sh, etc <any>[when][.sh]
if [[ -s ~/.${wha}whenrc ]];then source ~/.${wha}whenrc;else printf "configure me in ~/.${wha}whenrc\n" >/dev/stderr;exit 1;fi
for s in ${sleeps[@]};do sleepdates+=($(date -d "$(date +"%m/%d $s")" +%s));done
for s in ${sleeps[@]};do sleepdates+=($(date -d "$(date -d @$(($(date +%s)+(24*60*60))) +%m/%d) $s" +%s));done
for s in ${wakes[@]};do wakedates+=($(date -d "$(date +"%m/%d $s")" +%s));done
for s in ${wakes[@]};do wakedates+=($(date -d "$(date -d @$(($(date +%s)+(24*60*60))) +%m/%d) $s" +%s));done
count=0;until [[ $(date +%s) -le ${wakedates[$count]} ]];do ((count++));done
printf "sleep in $(minustime.sh "$(date)" "@${sleepdates[$count]}")\n wake in $(minustime.sh "$(date)" "@${wakedates[$count]}")\n"
@ze-
ze- / setrender.sh
Last active June 30, 2017 01:53
POV-Ray render assistant script to streamline scene development.
#!/usr/bin/env bash
count=0
cont=1
[[ -z "$COLUMNS" ]] && [[ -n "${TERM}" ]] && COLUMNS=$(tput cols)
[[ -e "qtargets" ]] && source qtargets # you can copy the next 2 lines to a ./qtargets file and edit them as you like
[[ -z "${qtarget[0]}" ]] && qtarget[0]="+W640 +H480 +Q5 +A0.3 +AM2 +J3.3 +R3" # this results in the override priority:
[[ -z "${qtarget[1]}" ]] && qtarget[1]="+W640 +H480 +Q9 +A0.3 +AM2 +J3.3 +R3" # environment > qtargets file > defaults
if ls session-* >/dev/null 2>&1;then
session="$(($(echo session-* | sed -e 's/-[0]*\([0-9]\)/-\1/g' -e 's/.*-//')+1))" # add 1 to the last session number
else