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 / .brew.jl
Last active October 4, 2025 11:27
Homebrew snippets #macOS #Homebrew
using IOCapture
function livecheck(cask)
try
c = IOCapture.capture() do
run(`brew livecheck --cask $cask`)
end
str = c.output
regex = Regex(cask * ":[ ]+([^=]+)[ ]+==>[ ]+([^\n]+)")
m = match(regex, str)
@singularitti
singularitti / .startup.py
Created September 23, 2022 21:09
Python startup config #Python #startup #config
#!/usr/bin/env python
try:
from IPython import get_ipython
IPYTHON = get_ipython()
IPYTHON.run_line_magic('load_ext', 'autoreload')
IPYTHON.run_line_magic('autoreload', '2')
except ModuleNotFoundError:
pass
try:
@singularitti
singularitti / startup.jl
Last active September 10, 2025 05:17
Julia startup config #Julia #startup #config
#=-------------------------------------------------------------------------------------+
| _____ __ __ _ __ |
| / ___// /_____ ______/ /___ ______ (_) / |
| \__ \/ __/ __ `/ ___/ __/ / / / __ \ / / / |
| ___/ / /_/ /_/ / / / /_/ /_/ / /_/ / / / / |
| /____/\__/\__,_/_/ \__/\__,_/ .___(_)_/ /_/ |
| /_/ /___/ |
+-------------------------------------------------------------------------------------=#
#=======================================================================================
@singularitti
singularitti / toggle.jl
Created September 12, 2022 22:48
Toggle constant in Julia #Julia #toggle
module ToggleableAsserts
export @toggled_assert, toggle
assert_toggle() = true
macro toggled_assert(cond, text=nothing)
if text==nothing
assert_stmt = esc(:(@assert $cond))
else
@singularitti
singularitti / tmutil.jl
Created August 10, 2022 21:36
Delete local time machine backups #macOS #backup
using IOCapture
c = IOCapture.capture() do
run(`tmutil listlocalsnapshots /`)
end
const REGEX = r"com\.apple\.TimeMachine\.(\d+-\d+-\d+-\d+)\.local"
map(split(c.output, "\n", keepempty=false)) do line
m = match(REGEX, line)
if m !== nothing
version = m[1]
@singularitti
singularitti / grep.jl
Created July 8, 2022 05:55
Generate static file for qha
using Crystallography
using QuantumESPRESSO.Inputs.PWscf
using QuantumESPRESSO.Outputs.PWscf
press = [-10 -5 0 10 20 40 60 70 80 90]
e = map(sort(press |> vec)) do p
str = read(joinpath("p=$p.0", "SelfConsistentField.out"), String)
parse_electrons_energies(str, :converged).ε |> only
end |> vec
v = map(sort(press |> vec)) do p
@singularitti
singularitti / interleave.jl
Last active June 17, 2022 13:45
Interlace (interleave) two arrays in Julia / Combine two arrays with alternating elements
https://discourse.julialang.org/t/combining-two-arrays-with-alternating-elements/15498/3
# Interleave 2 vectors `a` & `b` to get a new vector
collect(Iterators.flatten(zip(a, b)))
@singularitti
singularitti / extensions.json
Last active September 12, 2025 12:07
VSCode Settings
[
{
"id": "3dy3day.visual-markdown-table-editor",
"name": "visual-markdown-table-editor",
"publisher": "3dy3day",
"version": "1.0.2"
},
{
"id": "adam-bender.commit-message-editor",
"name": "commit-message-editor",
@singularitti
singularitti / seam_carving.jl
Last active July 8, 2022 05:54 — forked from ricebunnyNL/seam_carving.jl
Optimized seam carving for Julia
function find_min_energy_map2(energy)
energy = transpose(energy)
row, col = size(energy)
dir_arr = [-1, 0, 1]
energy_map = zeros(row, col)
energy_map[:, end] = energy[:, end]
dirs = zeros(Int, row, col)
@inbounds for c = col-1:-1:1
@singularitti
singularitti / compare.jl
Last active May 25, 2021 09:33
Spglib helper
function compare_with_qe(result, qe_result, alat)
result = map(result * alat) do vec
map(v -> round(v; digits = 7), vec)
end
f(result) = sortperm(DataFrame(hcat(result...)', [:x, :y, :z]), [:x, :y, :z])
g(result) = result[sortperm(DataFrame(hcat(result...)', [:x, :y, :z]), [:x, :y, :z])]
# result_df = sortperm(DataFrame(hcat(result...)', [:x, :y, :z]), [:x, :y, :z])
# qe_df = sortperm(DataFrame(hcat(qe_result...)', [:x, :y, :z]), [:x, :y, :z])
# result_df, qe_df
symdiff(result, qe_result)