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 / 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 May 30, 2024 19:46
VSCode Settings
[
{
"identifier": {
"id": "vscode.bat"
},
"pinned": false,
"preRelease": false,
"version": "1.0.0"
},
{