Skip to content

Instantly share code, notes, and snippets.

View s-zeid's full-sized avatar

S. Zeid s-zeid

View GitHub Profile
@s-zeid
s-zeid / ms_binary_test.rs
Last active August 16, 2020 04:17
Rust macros for reading types from binary streams
// Imports {{{1
use std::io;
extern crate byteorder; // 1
use byteorder::{/*ReadBytesExt,*/ LittleEndian};
extern crate num_traits; // 0.2
use num_traits::ToPrimitive;
#!/bin/sh
uid=$(id -u)
if pgrep -u $uid -x 'xterm' >/dev/null 2>&1; then
pkill -u $uid -x 'xterm'
else
xrandr_size=$(xrandr --current --prop | head -n 1 \
| grep -o 'current [0-9]\+ x [0-9]\+' \
| sed -e 's/current //g; s/ x /\n/g')
@s-zeid
s-zeid / show-script-opt.lua
Last active July 30, 2020 11:18
custom command (script message) for mpv to show a script option on the OSD
-- input.conf usage: <key> script-message show-script-opt <opt-name> <default>
-- Example: t script-message show-script-opt osc-title "${media-title}"
mp.register_script_message("show-script-opt", function(name, default)
local value = mp.get_opt(name)
if not (value == nil or value == "") then
value = mp.command_native({"expand-text", value})
else
value = default or "(unavailable)"
end
#!/bin/sh
# <https://gist.github.com/01e327e485cadee4c7c50ba191ae9e9f>
# Workaround for <https://bugs.chromium.org/p/chromium/issues/detail?id=1087937>
# Adapted from /u/ken_duda's comment:
# * <https://old.reddit.com/r/Crostini/comments/gsxx7o/userpid_namespaces_broken_in_crostini_83/fsqn1wj/>
# * <https://bugs.chromium.org/p/chromium/issues/detail?id=1087937#c6>
@s-zeid
s-zeid / opkg-pkgs-from-image
Created July 16, 2020 07:36
Get installed packages from an OpenWrt image (requires p7zip-full)
#!/bin/sh
if [ $# -ne 1 ]; then
echo "Usage: $(basename -- "$0") <image-file>" >&2
exit 2
fi
7z -so e "$1" usr/lib/opkg/status \
| grep '^Package:' | cut -d' ' -f 2 | sort
[Service]
TimeoutStopSec=5
@s-zeid
s-zeid / LICENSE.txt
Last active January 31, 2024 08:31
License for my Gists (unless otherwise specified or not eligible for copyright)
Copyright (c) S. Zeid. <https://s.zeid.me/>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
@s-zeid
s-zeid / ec2
Last active August 2, 2021 08:21
(old; moved to https://code.s.zeid.me/bin/blob/main/ec2) Convenience script for EC2 instances
#!/bin/sh
# Requires AWS CLI version 1 (`pip3 install awscli`)
if ! [ -f "$1" ]; then
printf %s "
This script should be used as the shebang line in another script that looks like
the following (assuming this script is on \$PATH):
@s-zeid
s-zeid / media
Last active June 5, 2020 05:30
raspberry pi media tmux window
#!/bin/sh
NAME=media
ACCENT_COLOR='#ab7fcc'
pane_cmd() { echo "echo '\$' $@; $@; PS1='\$ ' exec bash --posix"; }
setup_tmux() {
@s-zeid
s-zeid / silence
Last active May 16, 2020 05:55
Play silence via PulseAudio
#!/bin/sh
# no exec in order to allow checking if the script is running
paplay --raw /dev/zero >/dev/null 2>&1