Skip to content

Instantly share code, notes, and snippets.

View gzxu's full-sized avatar

徐广钊 XU Guang-zhao gzxu

  • 西安交通大学 Xi'an Jiaotong University
View GitHub Profile
@gzxu
gzxu / Makefile
Created September 17, 2021 14:30
Call trampoline for GCC/Clang, similar to Microsoft C++ import libraries, permitting loading failures for shared objects without immediately aborting the program
.PHONY: clean
.DEFAULT: main
main: main.o trampoline_curl.o
gcc $^ -ldl -o $@
main.o: main.c trampoline_curl.h
gcc -c -O3 -fPIC $< -o $@
trampoline_curl.o: trampoline_curl.c trampoline_curl.h
@gzxu
gzxu / README.md
Last active May 24, 2024 19:57
Run rsync server on Android Termux

Usually we will use this command

rsync --dry-run -a --mkpath --no-o --no-g --no-p -P -c SRC/ DST/

Remove --dry-run to actually copy the files rather than merely comparing

Remove -c to make it faster by comparing mod-time and size rather than checksum

@gzxu
gzxu / sedutil-pbkdf2.sh
Last active June 26, 2024 22:30
Unlock an SED-supporting SSD with sedutil Hardware Encryption
device=sdb
serial="$(ls -la /dev/disk/by-id | grep "/$device\$" | sed 's/ /\n/g' | grep ata | sed 's/_/\n/g' | tail -n1)"
read -r -s password
hashed=$(SERIAL="$serial" PASSWORD="$password" python3 -c 'import hashlib, base64, os; print(base64.b64encode(hashlib.pbkdf2_hmac("sha1", os.environ["PASSWORD"].encode(), os.environ["SERIAL"].ljust(20, " ").encode(), 75000, 32)).decode())' | base64 -d)
sudo sedutil-cli -n --listLockingRanges "$hashed" /dev/$device
@gzxu
gzxu / init-linux.sh
Created September 18, 2020 13:09
Init a new Linux installation
# Base
cat /etc/apt/sources.list
sudo sed -i 's/archive.ubuntu.com/mirrors.xtom.com.hk/g' /etc/apt/sources.list
sudo sed -i 's/security.ubuntu.com/mirrors.xtom.com.hk/g' /etc/apt/sources.list
sudo sed -i 's|http://|https://|g' /etc/apt/sources.list
cat /etc/apt/sources.list
sudo apt update && sudo apt upgrade
# XRDP and KDE
sudo apt install xrdp xorg-
@gzxu
gzxu / QuickXorHash.rs
Last active June 15, 2022 07:41
Implementing the QuickXorHash Algorithm used by the Microsoft Graph API on OneDrive for Business
use std::env;
use std::fs;
// extern crate base64;
// From the specification
// https://docs.microsoft.com/en-us/onedrive/developer/code-snippets/quickxorhash
// According to the spec, the block is "big-endian"
type Block = [u8; 20]; // Intrinsically with Copy trait
@gzxu
gzxu / 01_siso33ss.lib
Last active June 25, 2018 16:13
3×3 SISO State Space in LTspice
.subckt siso33ss U Y
G11 0 X1 X1 0 {a11}
G12 0 X1 X2 0 {a12}
G13 0 X1 X3 0 {a13}
G21 0 X2 X1 0 {a21}
G22 0 X2 X2 0 {a22}
G23 0 X2 X3 0 {a23}
G31 0 X3 X1 0 {a31}
G32 0 X3 X2 0 {a32}
G33 0 X3 X3 0 {a33}