Skip to content

Instantly share code, notes, and snippets.

Avatar
🌋
Working from home

Reno singularitti

🌋
Working from home
View GitHub Profile
@singularitti
singularitti / Big Sur Modern Dark.alfredappearance
Last active Jun 16, 2021
Alfred Big Sur Modern Dark theme
View Big Sur Modern Dark.alfredappearance
{
"alfredtheme" : {
"result" : {
"textSpacing" : 5,
"subtext" : {
"size" : 12,
"colorSelected" : "#BCBCBC65",
"font" : "System",
"color" : "#BCBCBC65"
},
View compare.jl
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)
@singularitti
singularitti / brew_live_check.jl
Last active May 4, 2021
Brew live check #Julia
View brew_live_check.jl
using IOCapture
c = IOCapture.capture() do
run(`git byme`)
end
map(split(c.output, "\n", keepempty = false)) do line
try
run(`brew lc $(line[7:end-3])`)
catch e
@singularitti
singularitti / spglib_get_kmesh.py
Last active Apr 19, 2021
Spglib get k-mesh #Python #crystallography
View spglib_get_kmesh.py
import collections
def irrmesh(mapping, grid, shift = [0, 0, 0]):
shift = np.array(list(map(lambda x: 0.5 if x == 1 else 0, shift)))
count = collections.Counter(mapping)
result = []
for ir_gp_id, gp in zip(np.unique(mapping), grid[np.unique(mapping)]):
result.append(np.append((gp.astype(float) + shift) / mesh, count[ir_gp_id]).tolist())
return np.array(result)
@singularitti
singularitti / struct_equal.jl
Created Jan 15, 2021
Compare equality of 2 `struct`s #Julia
View struct_equal.jl
# See https://github.com/JuliaLang/julia/issues/4648#issuecomment-761030051
# ASSUMTION: `e1` and `e2` have the same run-time type
@generated structEqual(e1, e2) = begin
if fieldcount(e1) == 0
return :(true)
end
mkEq = fldName -> :(e1.$fldName == e2.$fldName)
# generate individual equality checks
eqExprs = map(mkEq, fieldnames(e1))
# construct &&-expression for chaining all checks
@singularitti
singularitti / mercury_trail.jl
Created Dec 29, 2020
Mercury trail #Julia #physics
View mercury_trail.jl
using Plots
# https://www.zhihu.com/question/22477205/answer/21521946
earth(t) = (cos(2pi * t), sin(2pi * t))
mercury(t) = 0.387 .* (cos(26.1t), sin(26.1t)) .- earth(t)
mercury2(t) = (
(0.387cos(26.1t) - cos(2t * pi)) * cos(730t * pi) -
(0.387sin(26.1t) - sin(2t * pi)) * sin(730t * pi),
@singularitti
singularitti / merge_graph.jl
Created Oct 15, 2020
Merge 2 Julia graphs
View merge_graph.jl
function merge(g, b)
a = copy(g)
add_vertices!(a, nv(b))
for e in edges(h)
add_edge!(a, src(e) + nv(g), dst(e) + nv(g))
end
return a
end
@singularitti
singularitti / Remedy.json
Last active Sep 3, 2021
Remedy iTerm profile
View Remedy.json
{
"ASCII Anti Aliased": true,
"ASCII Ligatures": false,
"AWDS Pane Directory": "",
"AWDS Pane Option": "Recycle",
"AWDS Tab Directory": "",
"AWDS Tab Option": "Recycle",
"AWDS Window Directory": "",
"AWDS Window Option": "No",
"Ambiguous Double Width": false,
@singularitti
singularitti / execute.jl
Created Sep 5, 2020
Execute shell commands in Julia wrapper #Julia
View execute.jl
# From https://discourse.julialang.org/t/better-support-for-running-external-commands/44933/26
function execute(cmd::Cmd)
out = Pipe()
err = Pipe()
process = run(pipeline(ignorestatus(cmd), stdout = out, stderr = err))
close(out.in)
close(err.in)
stdout = @async String(read(out))
@singularitti
singularitti / Arthur.json
Last active Oct 12, 2020
Arthur iTerm profile
View Arthur.json
{
"Working Directory" : "\/Users\/qz",
"Prompt Before Closing 2" : 2,
"Selected Text Color" : {
"Green Component" : 1,
"Blue Component" : 1,
"Red Component" : 1
},
"Rows" : 50,
"Ansi 11 Color" : {