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 / 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 / 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
@singularitti
singularitti / bubbles.py
Created March 16, 2023 08:34
Bubble Plot Generator using ChatGPT #GPT #Python #plotting
import matplotlib.pyplot as plt
import numpy as np
import random
# Generate random colors
def random_color():
return [random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1)]
# Generate coordinates for small bubbles around a big bubble with a fixed distance
def small_bubbles(x, y, radius, distance, num_bubbles, min_radius, max_radius):
@singularitti
singularitti / PacletUninstallAll.wls
Created January 13, 2023 23:49
Uninstall all paclets #Mathematica
dirs = FileNameJoin[{$HomeDirectory, $BasePacletsDirectory,
"Repository", "*"}] // FileNames
paclets = Map[StringSplit[FileNameSplit[#][[-1]], "-"][[1]] &, dirs]
Map[PacletUninstall, paclets]
@singularitti
singularitti / dif.tex
Created December 7, 2022 19:59
Set `\dif` operator #LaTeX
\newcommand{\dif}{\ensuremath{\mathop{}\!\mathrm{d}}}
@singularitti
singularitti / settran.tex
Created December 7, 2022 19:58
Create `\tran` operator globally #LaTeX
\newcommand*{\tran}{^{\mkern-1.5mu\mathsf{T}}}
@singularitti
singularitti / compresspdf.sh
Created December 7, 2022 19:56
Compress a PDF file #PDF #Shell
# Usage: compresspdf [input file] [output file] [screen*|ebook|printer|prepress]
compresspdf() {
gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dPDFSETTINGS=/${3:-"screen"} -dCompatibilityLevel=1.4 -sOutputFile="$2" "$1"
}
@singularitti
singularitti / git_prev_release.sh
Created November 30, 2022 02:32
GitFlow: How to maintain previous releases? #Git
# See https://stackoverflow.com/a/69727920/3260253
git switch main # now you should be up to date with origin/main
git merge --strategy=ours hotfix/1.1.1 # bring in commits without their changes!
@singularitti
singularitti / mapat!.jl
Created November 17, 2022 08:33
Map function `f` at specific indices of an array #Julia #array
function mapat!(f, array, indices...) # Map function `f` at specific indices of an array
area = view(array, indices...)
map!(f, area, area)
return array
end