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 / rmcache.sh
Last active July 9, 2018 02:13
Remove icon caches for macOS #macOS
#!/usr/bin/env bash
find /private/var/folders/ -name com.apple.dock.iconcache -exec trash {} \;
find /private/var/folders/ -name com.apple.iconservices -exec trash {} \;
trash /Library/Caches/com.apple.iconservices.store
@singularitti
singularitti / free.py
Last active July 9, 2018 02:13
A Python script that can show the wired, active, inactive and free memory amounts #macOS #memory
#!/usr/bin/env python3
"""
Code referenced from `Stack Exchange \
<https://apple.stackexchange.com/questions/4286/is-there-a-mac-os-x-terminal-version-of-the-free-command-in-linux-systems>`_.
**Note**: One need to use Python 3 to run this file!
"""
import re
import subprocess
@singularitti
singularitti / reset_credential.sh
Created August 17, 2018 02:39
Remove credentials from Git #Git
git config --global credential.helper store
@singularitti
singularitti / transmit_pasteurl.sh
Created October 8, 2018 05:12
Don't paste login information #Transmit
# When copying a remote item’s URL, don’t include the login information (user:password@example.com) in the URL.
defaults write com.panic.Transmit CopyURLWithoutLogin 0
@singularitti
singularitti / suck_dock.sh
Created November 26, 2018 05:57
Defines the animation which is used to show windows being minimized into the Dock #macOS #Dock
defaults write com.apple.dock mineffect -string 'suck'; killall Dock
@singularitti
singularitti / showall.jl
Last active January 25, 2019 11:42
Show all elements of a `Vector` #Julia #IO
# Referenced from
# https://stackoverflow.com/questions/49304329/how-to-show-all-elements-of-vectors-and-matrices-in-julia
function showall(io, x, limit = true)
println(io, summary(x), ":")
Base.print_matrix(IOContext(io, :limit => limit), x)
end
@singularitti
singularitti / eos_fit.py
Last active March 20, 2019 06:28
Several methods for equation of state (EoS) fitting #Python
#!/usr/bin/env python3
# Created at May 2, 2018, by Qi Zhang
from abc import abstractmethod
import numpy as np
import scipy.optimize as optimize
class EOS:
@singularitti
singularitti / deepflatten.jl
Last active April 1, 2019 00:31
Unfold a nested Julia array #Julia #array
# For a detailed explanation, please see here:
# https://discourse.julialang.org/t/how-do-you-unfold-a-nested-julia-array/2243/7?u=singularitti
function deepflatten(arr::Vector{<: Vector})
dim = [1]
function recursiveflatten(arr, dim)
if arr isa Vector{<: Vector}
recursiveflatten(collect(Iterators.flatten(arr)),
pushfirst!(dim, length(arr) / prod(dim)))
else
@singularitti
singularitti / remove duplicate pdf pages.py
Created March 6, 2019 08:39
Remove duplicate PDF pages #Python #PDF
# function: remove pause frames of a beamer PDF
from pdfrw import PdfReader, PdfWriter
def run_stage(src, out):
i = PdfReader(src)
o = PdfWriter()
sum_i = len(i.pages)
num_i = i.Root.PageLabels.Nums
for r in range(1, len(num_i) // 2):
@singularitti
singularitti / crossProduct.js
Created April 7, 2019 05:16
Compute cross product of 2 3D arrays #JavaScript #math #array
function crossProduct(arr1, arr2) {
/*
Here arr1, arr2 are both 1D arrays.
*/
let u1 = arr1[0];
let u2 = arr1[1];
let u3 = arr1[2];
let v1 = arr2[0];
let v2 = arr2[1];
let v3 = arr2[2];