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 / 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
@singularitti
singularitti / subDollars.pl
Created October 21, 2022 05:44
Replace all $ $ by \( \) in a LaTeX file #LaTeX #Perl
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy; # to copy the original file to backup (if overwrite option set)
use Getopt::Std; # to get the switches/options/flags
# get the options
my %options=();
getopts("wos", \%options);
@singularitti
singularitti / .brew.jl
Last active April 22, 2024 04:53
Homebrew snippets
using IOCapture
export livecheck, bump_cask_pr
function livecheck(cask)
try
c = IOCapture.capture() do
run(`brew livecheck --cask $cask`)
end
str = c.output
@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 May 7, 2024 20:15
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 / nyc.md
Last active March 12, 2024 07:13
NYC 景点

NYC

以下排名不分先后。

博物馆

  1. 自然历史博物馆,不用多说,《博物馆奇妙夜》的拍摄地点
  2. 大都会博物馆,不用多说
  3. 下东城廉租公寓博物馆,个人很喜欢的小众博物馆,博物馆的两座历史悠久的廉租公寓建筑在1863年至2011年期间,曾有来自20多个国家的约15000人居住。该建筑可以作为一种时间胶囊,反映19世纪和20世纪初的生活条件以及什么是可接受的住房不断变化的概念。
  4. https://www.metmuseum.org/visit/plan-your-visit/met-cloisters 修道院博物馆是大都会美术馆的分馆,开始修建于1930年代,其外观模仿中世纪欧洲的大修道院,因此得名。
@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)))