Skip to content

Instantly share code, notes, and snippets.

@scottywz
scottywz / if-up.d_addresses
Last active May 24, 2021
/etc/network/if-up.d/ script to set extra IP addresses
View if-up.d_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
@scottywz
scottywz / emoji-favicon.js
Last active Feb 22, 2021
Set a favicon from an emoji defined in an HTML attribute. Uses the Canvas API. — https://on.bnay.me/emoji-favicon/
View emoji-favicon.js
"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;
View .XCompose
# <https://gist.github.com/b6f7106e553b8c31723dc50c5aa1f1c2>
include "%L"
# Uncategorized {{{1
<Multi_key> <equal> <equal> <equal> : "≡" U2261 # IDENTICAL TO
<Multi_key> <asterisk> <asterisk> : "∗" U2217 # ASTERISK OPERATOR
<Multi_key> <bracketleft> <o> <bar> : "⎄" U2384 # COMPOSITION SYMBOL
<Multi_key> <bracketleft> <O> <bar> : "⎄" U2384 # COMPOSITION SYMBOL
<Multi_key> <c> <m> <p> : "⎄" U2384 # COMPOSITION SYMBOL
@scottywz
scottywz / selfoss.user.css
Last active Apr 23, 2021
Custom CSS for Selfoss
View selfoss.user.css
@variables {
--main-background: #ffffff;
--main-faint: #646464;
--nav-background: #f6f6f6;
--nav-background-active: #64279219;
--nav-text: #222222;
--nav-faint: #646464;
--nav-hr: #0002;
--accent-background: #64279219;
--accent-normal: #642792;
@scottywz
scottywz / ms_binary_test.rs
Last active Aug 16, 2020
Rust macros for reading types from binary streams
View ms_binary_test.rs
// Imports {{{1
use std::io;
extern crate byteorder; // 1
use byteorder::{/*ReadBytesExt,*/ LittleEndian};
extern crate num_traits; // 0.2
use num_traits::ToPrimitive;
View toggle-xterm
#!/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')
@scottywz
scottywz / show-script-opt.lua
Last active Jul 30, 2020
custom command (script message) for mpv to show a script option on the OSD
View show-script-opt.lua
-- 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
View cros83-procfs-workaround
#!/bin/sh
# 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>
for name in cpuinfo diskstats meminfo stat uptime; do
sudo umount "/proc/$name"
@scottywz
scottywz / opkg-pkgs-from-image
Created Jul 16, 2020
Get installed packages from an OpenWrt image (requires p7zip-full)
View opkg-pkgs-from-image
#!/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