Skip to content

Instantly share code, notes, and snippets.

@coreymwamba
coreymwamba / orddate
Last active May 3, 2022 17:15
dateutils' ordinal date format doesn't doesn't work; and everyone is still writing things in Python, so... ordinal dates in Shell
#!/bin/sh
today=$(date +'%A %e %B %Y') # obviously you can modify this line
D=$(echo $today | grep -E -o "(\b(|[0-3])[0-9]\b)")
case $D in
1|21|31)
mod="st"
;;
2|22)
mod="nd"
;;
@coreymwamba
coreymwamba / arch-wiki-lite-i3-dmenu
Last active May 10, 2020 11:20
Dmenu-driven Arch Linux offine wiki search, using arch-wiki-lite.
#!/bin/bash
# This is just a barebones script -- needs dmenu,arch-wiki-lite, i3-sensible-terminal
# modify as needed
dm="-fn LiberationSans-12 -nb #404452 -sb #9899a0"
s=$(echo "" | dmenu -q $dm -p "ArchWiki")
if [ -n "$s" ]; then
wiki-search "$s" > /tmp/awms
a=$(cat /tmp/awms | awk -F' ' '{ print $2 }')
lines=$(cat /tmp/awms | wc -l)

Keybase proof

I hereby claim:

  • I am coreymwamba on github.
  • I am coreymwamba (https://keybase.io/coreymwamba) on keybase.
  • I have a public key ASDQ_FTSP4fZHGKFFvhevGzlBVbjMHEruL2-Y6V68fFTvQo

To claim this, I am signing this object:

@coreymwamba
coreymwamba / ffpmeg-jack-AV-rec
Last active April 15, 2020 02:28
Records from a camera, and takes audio from a soundcard connected in JACK. Edit variables to taste.
#! env /bin/bash
# ffpmeg-jack-AV-rec - record video from a webcam, audio from a soundcard, using FFMpeg in JACK.
# Corey Mwamba 2018
# You will need jack_autoconnect (https://github.com/kripton/jack_autoconnect)
# And FFMpeg. And JACK.
# the -thread_queue_size option for ffmpeg reduces xruns
FR=25
VC=h264
AC=aac
@coreymwamba
coreymwamba / audio-folder-convert
Last active February 20, 2019 03:16
Bash, inotify, FFMpeg script to convert audio files to a desired format by placing it in a folder. The example below is for Ogg Vorbis; change it to whatever you want. Then set the script to autostart (in DE or WM).
convert_ogg() {
ffmpeg -hide_banner -nostats -loglevel panic -i ~/audio/convert_to_ogg/$file -vn -b:a 320k ~/audio/convert_to_ogg/${file%.*}.flac &
echo "converting $file"
}
while true; do
inotifywait -m ~/audio/convert_to_ogg -e create -e moved_to | while read path action file; do
if [ ${file##*.} != "ogg" ]; then
convert_ogg
fi
@coreymwamba
coreymwamba / simple-ssb
Last active March 26, 2023 15:19
In 2014, I saw a page on Ice SSB (https://peppermintos.com/guide/ice/) which uses the user's browser to create a site-specific browser - I guess what some Android apps do to an extent, or Web Widgets. I then wondered whether it would be possible to do the same but WITHOUT installing a larger browser. Someone else would have done this in Python.
#!/bin/bash
# simple-ssb - a simple Site Specific Browser application
# 2014, 2017 Corey Mwamba
# requirements: Yad/Zenity, WebKitGTK+2, cURL, gjs
# If you need Flash then download the NPAPI Flash plugin
vcheck(){
hash gjs 2>/dev/null || { echo >&2 $(${GUICMD} --text "gjs is not installed"); exit 1; }
hash curl 2>/dev/null || { echo >&2 $(${GUICMD} --text "curl is not installed"); exit 1; }
}
join_strings() {
@coreymwamba
coreymwamba / dictaphone
Last active July 14, 2017 15:19
A quick script to record audio notes. I have this little thing bound to a keypress in JWM (opens in a terminal). Needs ffmpeg.
#!/bin/bash
today=$(date +%s)
echo "press q to stop..."
ffmpeg -f alsa -i hw:0 -v 1 ~/audio-notes/$today.flac $@
@coreymwamba
coreymwamba / start-JACK-on-USB-insert
Last active September 18, 2016 06:16
This is a simple script that brings up a Yad interface when I plug in my USB audio card. The interface then activates JACK. JACK is then killed when I remove the card. You won't be able to do this for a normal user through Udev, since it is a root process. This script is run from the autostart section of my window manager (JWM).
#!/bin/bash
#you will need to modify the device names for JACK...
choose_params() {
qy=$(yad --form --item-separator="|" --field "Purpose:CB" "CD|Live|HD")
jackparams=$(echo $qy | awk -F '|' '{print $1}')
case $jackparams in
CD)
jackd -dalsa -r44100 -p4096 -n3 -D -dhw:Device &
export JACK_SAMPLE_RATE=44100
export JACK_SETTING="REC"
@coreymwamba
coreymwamba / bash-terse-battery-check
Created January 27, 2016 19:33
Batteries. Laptops. Indicators. The eternal struggle. Conky tells you the percentage of the battery; acpi gives you a long string and an estimated time. This script, if used in Conky, will give you both.
#!/bin/bash
eval $(acpi -b | sed "s/Battery 0: //g" |sed "s/,//g"| awk 'BEGIN {FS=" "}; {print "ch="$1, "percent="$2, "countdown="substr($3,0,5)}')
case $ch in
Discharging)
sign="-"
;;
Unknown)
sign="~"
;;
Charging)