Skip to content

Instantly share code, notes, and snippets.

@mentha
mentha / statusled.c
Created January 27, 2018 13:15
RPI status led showing system load
#define _DEFAULT_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/sysinfo.h>
#define LEDCTL "/sys/class/leds/led0/brightness"
@mentha
mentha / httpd.sh
Last active March 10, 2018 03:52
Simple HTTP Server in shell command language
#!/bin/sh
# This is free and unencumbered software released into the public domain.
if (file &> /dev/null; test $? -eq 127); then
file () {
# file -Lbi file
local l_mime
case "$(echo "$2" | rev | cut -d . -f1 | rev)" in
html) l_mime=text/html;;
css) l_mime=text/css;;
@mentha
mentha / usbip-vhci_hcd_filter.patch
Created March 18, 2018 14:55
Linux usbip patch
diff -udr a/libsrc/vhci_driver.c b/libsrc/vhci_driver.c
--- a/libsrc/vhci_driver.c 2018-03-18 22:07:40.126034770 +0800
+++ b/libsrc/vhci_driver.c 2018-03-18 22:10:22.405106067 +0800
@@ -150,7 +150,12 @@
static int vhci_hcd_filter(const struct dirent *dirent)
{
- return strcmp(dirent->d_name, "vhci_hcd") >= 0;
+ size_t l = strlen(dirent->d_name);
+ if (l < 8)
@mentha
mentha / ghrget.py
Created May 3, 2022 13:27
fetch assets from github release
#!/usr/bin/env python3
import argparse
import logging
import os
import re
import requests
import shutil
import subprocess as sp
import tempfile
@mentha
mentha / aggregate.c
Created May 3, 2022 13:30
compress list of cidr
/* Compress CIDR list by aggregrating adjacent subnets. */
#define _POSIX_C_SOURCE 200809L
#include <arpa/inet.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@mentha
mentha / arp2wol.py
Created May 3, 2022 13:33
convert arp packets to wake-on-lan packets
#!/usr/bin/env python3
# Send wake-on-lan packets to targets of ARP packets
MAX_AGE = 86400 * 7
from sys import argv, stderr
from time import time
import os
import subprocess as sp
@mentha
mentha / libvirt-assign-ip.py
Created May 3, 2022 13:35
assign static ip and network filters to libvirt guests
#!/usr/bin/env python3
from pprint import pprint
from argparse import ArgumentParser
from ipaddress import IPv4Address
from tempfile import NamedTemporaryFile
import libvirt
import os
import xml.etree.ElementTree as ET
@mentha
mentha / libvirt-assign-usb-port.py
Created May 3, 2022 13:36
assign a usb port to libvirt guest
#!/usr/bin/env python3
from argparse import ArgumentParser
from traceback import print_exc
import libvirt
import os
import re
import subprocess as sp
class PortForward:
@mentha
mentha / oathupdate
Created May 3, 2022 13:39
manage pam_oath auth file
#!/usr/bin/env python3
# update OTP auth file of pam_oath
OATHFILE = '/etc/users.oath'
from base64 import b16encode, b16decode, b32encode
from sys import argv
import os
import subprocess as sp
@mentha
mentha / dnf-plugin-remove-suid.spec.rpkg
Last active June 4, 2022 06:53
dnf plugin to remove setuid bits
%global descr DNF plugin to remove suid from packages
Name: dnf-plugin-remove-suid
Version: {{{ git_dir_version }}}
Release: 1%{?dist}
Summary: %{descr}
URL: https://gist.github.com/mentha/f02780b4889a2d03fbd9380ff33428d9
License: MIT
VCS: {{{ git_dir_vcs }}}
Source: {{{ git_dir_pack }}}