Skip to content

Instantly share code, notes, and snippets.

@s-zeid
s-zeid / ora
Last active August 2, 2021 08:22
(old; moved to https://gitlab.com/scottywz/bin/blob/main/ora) not-abomination clock
#!/usr/bin/env python3
# vim: set fdm=marker:
import argparse
import atexit
import base64
import configparser
import datetime
import decimal
import os
@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):
#!/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 / if-up.d_addresses
Last active May 24, 2021 11:17
/etc/network/if-up.d/ script to set extra IP addresses
#!/bin/sh
ADDRESSES='
eth0=2001:db8::2 eth0=2001:db8:2::1
eth0=192.0.2.2 eth0=198.51.100.2 eth0=203.0.113.2 eth0=233.252.0.2
'
################################################################################
set -e
@s-zeid
s-zeid / emoji-favicon.js
Last active February 22, 2021 12:26
Set a favicon from an emoji defined in an HTML attribute. Uses the Canvas API. — https://on.bnay.me/emoji-favicon/
"use strict";
//export default
class EmojiFavicon {
static DEFAULT_ATTRIBUTE_NAME() { return "data-emoji-favicon"; }
static set(emoji, shadowColor, size) {
shadowColor = (typeof shadowColor === "string") ? shadowColor : null;
@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;
MBTN_LEFT set pause no
MBTN_RIGHT cycle fullscreen
MBTN_RIGHT_DBL cycle fullscreen
WHEEL_UP add volume 2
WHEEL_DOWN add volume -2
WHEEL_LEFT ignore
WHEEL_RIGHT ignore
- add volume -2
= add volume 2
+ add volume 2
@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
@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