Skip to content

Instantly share code, notes, and snippets.

@ihipop
ihipop / eth-irq
Last active November 14, 2024 01:45
Ethernet IRQ RPS CPU SMP Affinity
#!/bin/bash
match=eth0 # Network interface name
num_big_cores=2 # Number of high-performance cores to select
# Retrieve cpu_capacity for each core and sort in descending order
declare -A cpu_capacities
for cpu in /sys/devices/system/cpu/cpu[0-9]*; do
capacity_file="$cpu/cpu_capacity"
if [ -f "$capacity_file" ]; then
@ihipop
ihipop / 70-logi-k380.rules
Created July 30, 2024 05:56
Udev rules for logitech k380 bluetooth keyboard to make function (fn) keys locked
ACTION=="change", SUBSYSTEM=="power_supply", DEVPATH=="*:046D:B342.*", RUN+="/bin/bash -c \"DEV_RAW=/dev/$$(echo $$(ls -1 $$(echo /sys$${DEVPATH} |sed -E 's#(.*)/power_supply/.*#\1#g')/hidraw)); [ -c $${DEV_RAW} ] && echo -ne '\x10\xff\x0b\x1e\x00\x00\x00' > $${DEV_RAW} || true\""
@ihipop
ihipop / dmesg.sh
Created June 17, 2024 02:38
DMESG with human datetime
#!/bin/bash
# from https://stackoverflow.com/a/76260286
dmesg | awk -F ] '{"cat /proc/uptime | cut -d \" \" -f 1" | getline st;a=substr( $1,2, length($1) - 1);print strftime("%F %H:%M:%S %Z",systime()-st+a)" -> "$0}'
@ihipop
ihipop / reload-plasmashell.sh
Last active April 14, 2023 02:39
use DBUS to reload KWIN or PlasmaShell
#!/bin/bash
[ "$XDG_SESSION_DESKTOP" = "KDE" ] || exit
#dbus-send --session --print-reply --dest=org.kde.kded5 \
# /kded \
# org.kde.kded5.unloadModule \
# string:"kscreen"
{
dbus-send --session --type=method_call --print-reply --dest=org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.refreshCurrentShell ||
{ killall plasmashell -u ${USER:-$(whoami)} && echo killed plasmashell ; kstart5 -- plasmashell >/dev/null 2>&1 & }
} &
@ihipop
ihipop / a_cidr_netmask.sh
Last active March 31, 2023 02:59
Shell Script to Manipulate NETMASK/CIDR
#!/bin/bash
# from https://stackoverflow.com/questions/20762575/explanation-of-convertor-of-cidr-to-netmask-in-linux-shell-netmask2cdir-and-cdir
# see also https://gist.github.com/RichardBronosky/7902f062ab36d3c99413ba21986ed0cb
mask2cdr ()
{
# Assumes there's no "255." after a non-255 byte in the mask
local x=${1##*255.}
set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) ${x%%.*}
x=${1%%$3*}
echo $(( $2 + (${#x}/4) ))
@ihipop
ihipop / GUARDER
Last active June 21, 2024 01:42
NetworkManager Connection Guarder
#!/bin/bash
# put me in the directory of "/etc/NetworkManager/dispatcher.d/",permission `u+x,g-w,o-w`
GUARDED_CONNECTION_NAMES='SSTP'
CONTROL_FILE=/tmp/NM-CONN-GUARD-DISABLED
if [ -f "$CONTROL_FILE" ] || [ -f "$CONTROL_FILE-$CONNECTION_ID" ]; then
echo -n "VPN GUARD DISABLED"
[ -f "$CONTROL_FILE-$CONNECTION_ID" ] && echo -n " FOR CONNECTION ${CONNECTION_ID}"
echo ""
@ihipop
ihipop / README.md
Last active February 8, 2022 10:22
给VirtualBox的虚拟机设置一个BIOS/主板序列号

设置

VBoxManage setextradata "Win 11" "VBoxInternal/Devices/efi/0/Config/DmiBoardSerial" "string:SN001" 
VBoxManage setextradata "Win 11" "VBoxInternal/Devices/efi/0/Config/DmiSystemSerial" "string:SN001"

如果是传统BIOS引导,把efi 换成 pcbios 即可

@ihipop
ihipop / [email protected]
Last active May 31, 2021 03:23
N1 CoreELEC mac address fix
[Unit]
Description=MAC address loader for %I From bootloader env
ConditionFileIsExecutable=/usr/sbin/fw_printenv
Wants=network-pre.target
Before=network-pre.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device
[Service]
Type=oneshot
@ihipop
ihipop / main.go
Created February 25, 2021 03:44
Fake Telnet Server
package main
import (
"fmt"
"github.com/reiver/go-oi"
"github.com/reiver/go-telnet"
)
func main() {
@ihipop
ihipop / M3C API.md
Created February 24, 2021 10:01
M3C 机顶盒API

基本格式说明

成功响应

<LIST>
	<result r="0">Success</result>
</LIST>

失败响应