Skip to content

Instantly share code, notes, and snippets.

View singularitti's full-sized avatar
:octocat:
WFH

Qi Zhang singularitti

:octocat:
WFH
View GitHub Profile
@singularitti
singularitti / jldoc.md
Created October 15, 2023 01:17
Julia Documenter GPT prompt #GPT #prompt

You are a documentation generator for Julia code that automatically generates documentation for any provided code using the official Julia documentation style.

  • Do not explain code.
  • Do not add Fields or Constructors, Fields should be replaced by the Arguments section.
  • Do not print my given code, just print the docs.

Here are two examples (enclosed by 4-backticks) for you to learn how to document:

  1. For code
@singularitti
singularitti / rmpdf.sh
Created September 4, 2023 22:30
Delete PDF files under a directory and its subdirectories #Shell #file
find <path> -type f -name "*.pdf" -exec trash {} \;
@singularitti
singularitti / ExifTool.sh
Created August 21, 2023 22:39
Use ExifTool #Shell #images
exiftool -overwrite_original -All= *.jp*g *.JPG *.png
@singularitti
singularitti / tlmgr.sh
Created August 21, 2023 22:38
Mange tlmgr #Shell #LaTeX
# Remove all backups
tlmgr backup --all --clean=0
# Remove LuaLaTeX caches
luaotfload-tool --cache=erase
@singularitti
singularitti / dock.sh
Created August 21, 2023 22:37
Manage macOS Dock #macOS #Shell
# Reset Dock to default layout
defaults delete com.apple.dock; killall Dock
# Dim hidden apps
defaults write com.apple.Dock showhidden -boolean yes; killall Dock
# Scroll gestures
defaults write com.apple.dock scroll-to-open -bool true && killall Dock
# Show "Quit Finder" menu item
@singularitti
singularitti / images.sh
Created August 21, 2023 22:35
Resize images #Shell
# Resize the specified image, ignoring the previous aspect ratio
sips -z <height> <width> <image>
# Resize the largest side of the specified image, preserving the aspect ratio
sips -Z <size> <image>
# Crop the specified image to the given dimensions (relative to the center of the original image)
sips -c <height> <width> <image>
@singularitti
singularitti / cask.sh
Created August 21, 2023 22:34
Manage Homebrew casks #Shell #Homebrew #macOS
Homebrew
# Install casks from local tap
export HOMEBREW_NO_INSTALL_FROM_API=1
# Generate cask token
"$(brew --repository homebrew/cask)/developer/bin/generate_cask_token" "/full/path/to/new/software.app"
# Create the cask file
brew create --cask --set-name my-new-cask download-url
@singularitti
singularitti / git_merge.sh
Last active July 31, 2023 15:14
Merging release into master with no resulting diff #Shell #Git
# See https://stackoverflow.com/a/14307477/3260253
git checkout main
git pull --strategy=ours . release
@singularitti
singularitti / communicate.jl
Last active July 13, 2023 23:28
Read from and write to subprocess simultaneously in Julia #Julia #process
# Referenced from https://tkf.github.io/julia-python-snippets/dev/miscellaneous/#Read-from-and-write-to-subprocess-simultaneously-1
function communicate(cmd::Cmd, input)
inp = Pipe()
out = Pipe()
err = Pipe()
process = run(pipeline(cmd, stdin=inp, stdout=out, stderr=err), wait=false)
close(out.in)
close(err.in)
@singularitti
singularitti / generate_id.jl
Created June 12, 2023 05:48
Generate unique random IDs #Julia
# See https://github.com/cihga39871/JobSchedulers.jl/blob/aca52de/src/jobs.jl#L6-L10
function generate_id()
time_value = (now().instant.periods.value - 63749462400000) << 16
rand_value = rand(UInt16)
time_value + rand_value
end