Skip to content

Instantly share code, notes, and snippets.

View koonix's full-sized avatar
🦆
honk

koonix

🦆
honk
View GitHub Profile
@koonix
koonix / awol.sh
Created September 10, 2022 20:34
detect and show IP Address, MAC Address and OS of all computers on local network.
#!/bin/sh
# detect and show IP Address, MAC Address and OS of local network computers.
# requires nmap and ip(iproute2).
gateway=$(ip route); gateway=${gateway#*via }; gateway=${gateway%% *}
localip=$(ip route get 1); localip=${localip#*src }; localip=${localip%% *}
scan=$(sudo nmap -sT -n -O --host-timeout 1m "${gateway:?}"/24) || exit 1
printf '%s\n' "${scan:?}" | while IFS= read -r line; do case $line in 'Nmap scan report for '*)
@koonix
koonix / burn-cd-dvd.sh
Created September 10, 2022 20:38
burn a file or an iso to a cd or dvd.
#!/bin/sh
# burn a file or an iso to a dvd.
# requires the cdrtools package.
# usage: $ burn FILE [TITLE]
# config
speed=1 # leave blank for default speed
dev=/dev/sr0
tmp=~/.cache/burn
#!/bin/bash
# winetricks, but for Bottles (https://github.com/bottlesdevs/Bottles).
# config
d=~/.local/share/bottles
set -e
cd ${d:?}/bottles
b=$(printf '%s\n' * | fzf)
r=$(grep '^Runner:' $b/bottle.yml | cut -d' ' -f2)
@koonix
koonix / bashism-check.sh
Created September 10, 2022 20:57
check #!/bin/sh-shebanged scripts in /usr/bin for dash-incompatible syntax using shellcheck.
#!/bin/sh
# check #!/bin/sh-shebanged scripts in /usr/bin for
# dash-incompatible syntax using shellcheck.
# config
outdir=~/bashisms
searchdir=/usr/bin
mkdir -p "$outdir" || exit 1
@koonix
koonix / safe-rm.zsh
Created September 10, 2022 20:58
a wrapper for rm to stop it from recursively removing top-level directories.
#!/bin/zsh
# a wrapper for rm to make it safer to use.
# it stops rm from recursively removing top-level directories.
unset recursive endopt
# check arguments
for arg; do case $arg in
--) break ;;
@koonix
koonix / dwm-snippets.c
Created September 10, 2022 21:10
some potentially useful functions for dwm.
void
pushincol(const Arg *arg)
{
Client *sel = selmon->sel, *c;
if (!sel || sel->isfloating)
return;
if (arg->i > 0) {
if ((c = nextofmodeloop(sel))) {
@koonix
koonix / dwm-spawncwd-incomplete.c
Created September 10, 2022 21:12
find the cwd of the currently focused window (in order to spawn another command in that cwd) in dwm. not finished yet.
#include <stdio.h>
#include <glob.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#define LENGTH(X) (sizeof(X) / sizeof(X[0]))
void getproccwd(const unsigned int pid, char *cwd, const unsigned int size);
void getdesc(const unsigned int pid, int *desc, const unsigned int size);
@koonix
koonix / magick-convert-example.c
Created September 10, 2022 21:15
Bare minimal test of a direct call to ImageMagick library's ConvertImageCommand().
/* source: https://legacy.imagemagick.org/discourse-server/viewtopic.php?p=80803#p80803
* requires the "opencl-headers" package
* compile:
* cc ConvertExample.c -o convert $(pkg-config --libs --cflags MagickCore MagickWand) */
/*
Bare minimal test of a direct call to ConvertImageCommand()
Actually this is basically what the "convert" command does.
Compile with...
@koonix
koonix / libpulse-async-playback-example.c
Created September 10, 2022 21:17
example of using libpulse's async API for playback.
/* source: https://stackoverflow.com/questions/29977651/how-can-the-pulseaudio-asynchronous-library-be-used-to-play-raw-pcm-data#29980624
* pcm-playback: pcm-playback.c
* gcc -o pcm-playback pcm-playback.c `pkg-config --cflags --libs libpulse` */
#include <stdio.h>
#include <assert.h>
#include <pulse/pulseaudio.h>
#define FORMAT PA_SAMPLE_U8
#define RATE 44100
@koonix
koonix / split-video-by-chapters.sh
Created September 10, 2022 21:29
split the given video/audio files by chapters using ffmpeg.
#!/bin/sh -efu
# split the given video/audio files by chapters using ffmpeg.
for file; do
ffprobe -print_format csv -show_chapters -- "$file" | cut -d, -f5,7,8 |
while IFS=, read start end chapter; do
ffmpeg -hide_banner -nostdin -ss "$start" -to "$end" -i "$file" \
-c copy -map 0 -map_chapters -1 -- "${file%.*}-$chapter.${file##*.}"
done
done