Skip to content

Instantly share code, notes, and snippets.

View singularitti's full-sized avatar
🎯
Focusing

Qi Zhang singularitti

🎯
Focusing
View GitHub Profile
@singularitti
singularitti / fonts.sh
Created August 21, 2025 09:23
Generate sorted font list with quotes #OS #file #font #Shell
# This command finds all `.otf` font files in the current directory and subdirectories,
# sorts them alphabetically by path, and outputs each as: `font "Folder/File.otf"`
#
# Step by step:
# 1. `find . -type f -name "*.otf"` → locate all `.otf` files
# 2. `sort` → order results alphabetically
# 3. `sed 's|^\./|font "|; s|$|"|'` → remove leading "./", add 'font "' prefix, and closing '"'
find . -type f -name "*.otf" \
| sort \
| sed 's|^\./|font "|; s|$|"|'
@singularitti
singularitti / link.sh
Created August 20, 2025 05:38
Symlink all immediate subfolders from one directory into another #Shell #OS #symlink
@singularitti
singularitti / metavideo.sh
Last active July 5, 2025 04:00
Remove video metadata #Shell #metadata
# See https://exiftool.org/forum/index.php?topic=11977.0
strip_video_metadata() {
local infile="$1" # First argument: input filename
local outfile="${2:-$infile}" # Second argument: output filename (defaults to input if not given)
local ext="${infile##*.}" # Extract file extension from input (everything after last '.')
local tmpfile # Will hold the temporary filename
if [[ "$outfile" == "$infile" ]]; then # If output is same as input (in-place operation)...
tmpfile="${infile}.tmp.${ext}" # ...use a temp file with proper extension
ffmpeg -i "$infile" -vcodec copy -acodec copy "$tmpfile" -y -loglevel error
@singularitti
singularitti / ncu_report_csv.sh
Created June 25, 2025 21:52
Import NVIDIA Nsight Compute report and export it to a CSV file
ncu --import <input.ncu-rep> --export <output.csv> --csv --page details --quiet
@singularitti
singularitti / groupx.sh
Created June 21, 2025 07:03
Add Group Execute Permission to Immediate and Nested Subdirectories (Only) #Shell
find . -type d -exec chmod g+x {} +
@singularitti
singularitti / dscl.sh
Created June 20, 2025 05:40
macOS create user #macOS #Shell
USERNAME=newadmin
REALNAME="New Admin"
PASSWORD=yourpassword
UNIQUEID=501 # Must be unique and >500
dscl . -create /Users/$USERNAME
dscl . -create /Users/$USERNAME UserShell /bin/zsh
dscl . -create /Users/$USERNAME RealName "$REALNAME"
dscl . -create /Users/$USERNAME UniqueID $UNIQUEID
dscl . -create /Users/$USERNAME PrimaryGroupID 80
@singularitti
singularitti / nsys_julia.sh
Created February 25, 2025 04:31
Nsight Systems trace Julia
nsys launch --trace=cuda,cudnn,cublas,mpi,nvtx julia --color=yes --banner=no --depwarn=yes
@singularitti
singularitti / offdiag.jl
Last active April 12, 2025 18:14
Get off-diagonal elements of a matrix #Julia #linear-algebra
# From https://discourse.julialang.org/t/41169/7
offdiag(A::AbstractMatrix) = [A[ι] for ι in CartesianIndices(A) if ι[1] ι[2]]
@singularitti
singularitti / Slurm.sh
Created August 7, 2024 06:31
Slurm commands #Shell #Slurm #HPC
# https://docs.e3sm.org/polaris/main/users_guide/machines/chicoma.html
sacctmgr list user $USER # Which is my default account?
# https://hpc-unibe-ch.github.io/slurm/partitions.html
# Within these partitions, QoS are used to distinguish different job limits. In each partition there is a default QoS. Each QoS has specific limits that can be viewed directly on the cluster:
sacctmgr show qos format=name%20,maxwall,maxsubmitpu,maxtrespu%80
# Note, that you might not have access to all of the QoS shown in the output. To see for which QoS your account has valid associations you can use:
sacctmgr show assoc where user=$USER format=account,partition,qos%80
@singularitti
singularitti / pagecolor.tex
Last active April 30, 2024 09:32
LaTeX PDF document with custom Tan background #LaTeX #PDF
\usepackage{xcolor}
\definecolor{tancolor}{RGB}{251, 240, 217}
\pagecolor{tancolor} % Set the background to Tan