Skip to content

Instantly share code, notes, and snippets.

@zengxinhui
zengxinhui / tshark.sh
Created April 17, 2024 04:31
group by tcp stream and output the last 10 packets captured to see how a connection ended.
tshark -r xyz.pcapng -Y "tcp.port != 445" -T fields -e tcp.stream -e frame.time_relative -e ip.src -e ip.dst -e _ws.col.info | sort -V | awk 'BEGIN {
prev = 0;
count = 0;
} {
buffer[NR % 11] = $0;
if ($1 != prev) {
for (i = NR-count; i<NR; i++)
print buffer[i % 11];
print "";
prev = $1;
@zengxinhui
zengxinhui / domain.xml
Created February 4, 2024 03:49 — forked from Informatic/domain.xml
How to use Windows 10 OEM license in libvirt VM (<smbios mode='host' /> does not work as Windows seems to verify UUID; apparmor/security configuration changes may be needed)
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<!-- ... -->
<qemu:commandline>
<qemu:arg value='-acpitable'/>
<qemu:arg value='file=/some/path/slic.bin'/>
<qemu:arg value='-acpitable'/>
<qemu:arg value='file=/some/path/msdm.bin'/>
<qemu:arg value='-smbios'/>
<qemu:arg value='file=/some/path/smbios_type_0.bin'/>
<qemu:arg value='-smbios'/>
import hashlib, os, sqlite3, sys
con = sqlite3.connect("hash.db")
cur = con.cursor()
cur.execute("delete from files")
for root, dirs, files in os.walk(sys.argv[1]):
for file in files:
filename = root + "/" + file
with open(filename, 'br') as f:
@zengxinhui
zengxinhui / finddup.clj
Last active November 2, 2023 14:55
Find Duplicate Files
#!/usr/bin/env bb
;; babashka/clojure
(import 'java.security.MessageDigest)
(def SCAN_DIRS ["."])
(def MIN_FILE_SIZE (* 1))
(def SHA256_CHUNK_SIZE (* 1024 8))
@zengxinhui
zengxinhui / convert2deb.sh
Last active October 2, 2023 05:16
Replace Oracle Cloud Linux with Debian remotely
[09/23/2023]
Refs:
1. http://mirror.cs.pitt.edu/archlinux/iso/2023.09.01/archlinux-bootstrap-2023.09.01-x86_64.tar.gz
2. https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-virt-3.18.0-x86_64.iso
3. https://wiki.alpinelinux.org/wiki/Replacing_non-Alpine_Linux_with_Alpine_remotely
4. https://www.debian.org/releases/bookworm/amd64/apds03.en.html
See also:
1. Convert to Debian https://gist.github.com/zengxinhui/ee0ad6b7c7f99e2ead6cd0d2bd6641fd
@zengxinhui
zengxinhui / CPUUsage.ps
Last active August 1, 2023 14:16
Simple CPU usage monitoring
$usageQueue = @()
while ($true) {
$currentDateTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$cpuUsage = Get-Counter '\Processor(_Total)\% Processor Time'
$cpuUsageValue = $cpuUsage.CounterSamples.CookedValue
$usageQueue += $cpuUsageValue
if ($usageQueue.Count -eq 13) {
@zengxinhui
zengxinhui / convert2arch_arm.sh
Last active March 8, 2024 23:41
Replace Oracle Cloud Linux with Arch Linux ARM remotely
[09/23/2023]
Refs:
1. http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz
2. https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/aarch64/alpine-virt-3.18.0-aarch64.iso
3. https://wiki.alpinelinux.org/wiki/Replacing_non-Alpine_Linux_with_Alpine_remotely
4. https://wiki.archlinux.org/index.php/installation_guide#Configure_the_system
5. https://archlinuxarm.org/platforms/armv8/generic
See also:
@zengxinhui
zengxinhui / OpenWrt WR741ND-V2.config
Last active December 24, 2021 13:45
Flash a `FAST FW150R V2' router with OpenWrt firmware for TPLINK WR741ND-V2. The wireless hardware is probably corrupted and causes kernel to panic. Since I'm not able to find a way to disable ath9 from uboot/bootargs, I compile from source and remove ath9 support.
CONFIG_ARCH="mips"
CONFIG_AUDIO_SUPPORT=y
CONFIG_AUTOREBUILD=y
CONFIG_BIG_ENDIAN=y
CONFIG_BINARY_FOLDER=""
CONFIG_BINUTILS_VERSION="2.29.1"
CONFIG_BINUTILS_VERSION_2_29_1=y
CONFIG_BUILD_SUFFIX=""
CONFIG_BUSYBOX_DEFAULT_ASH_ALIAS=y
CONFIG_BUSYBOX_DEFAULT_ASH_BASH_COMPAT=y
@zengxinhui
zengxinhui / convert2arch_x64.sh
Last active March 8, 2024 23:40
Replace Oracle Cloud Linux with Arch Linux remotely
[09/23/2023]
Refs:
1. http://mirror.cs.pitt.edu/archlinux/iso/2023.09.01/archlinux-bootstrap-2023.09.01-x86_64.tar.gz
2. https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-virt-3.18.0-x86_64.iso
3. https://wiki.alpinelinux.org/wiki/Replacing_non-Alpine_Linux_with_Alpine_remotely
4. https://wiki.archlinux.org/index.php/installation_guide#Configure_the_system
See also:
1. Convert to Debian https://gist.github.com/zengxinhui/ee0ad6b7c7f99e2ead6cd0d2bd6641fd
@zengxinhui
zengxinhui / aoc2020.clj
Last active December 22, 2020 17:26
Advent of Code 2020
(ns y2020.core
(:require [clojure.edn :as edn]
[clojure.string :as str]))
;; 202001
(let [input (->> (slurp "src/y2020/input202001") (re-seq #"\d+") (map edn/read-string) sort)
f (fn [sum xs]
(loop [[x & morex :as x'] xs
[y & morey :as y'] (reverse xs)]
(when (and x morex)