This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This script checks whether the vc-relax output gives correct result, | |
# by examining if there is "End final coordinates" in the output. | |
# Helpful guides: https://github.com/koalaman/shellcheck/wiki/SC2045, | |
# http://jafrog.com/2013/11/23/colors-in-terminal.html, | |
# and https://github.com/koalaman/shellcheck/wiki/SC2068 | |
folders=() | |
for folder in "$@"; do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Helpful guides: https://github.com/koalaman/shellcheck/wiki/SC1065 | |
# and: https://superuser.com/questions/748724/pass-a-large-string-to-grep-instead-of-a-file-name | |
folders=() | |
if [ -f finalcell ]; then | |
rm finalcell | |
else | |
touch finalcell | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clear["Global`*"] | |
Rx[\[Phi]_] := MatrixExp[-I \[Phi] {{0, 0, 0}, {0, 0, -I}, {0, I, 0}}] | |
Ry[\[Phi]_] := MatrixExp[-I \[Phi] {{0, 0, I}, {0, 0, 0}, {-I, 0, 0}}] | |
Rz[\[Phi]_] := MatrixExp[-I \[Phi] {{0, -I, 0}, {I, 0, 0}, {0, 0, 0}}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flatten(arr) { | |
return arr.reduce(function (flat, toFlatten) { | |
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten); | |
}, []); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function meshgrid(xArray, yArray) { | |
/* | |
Here xArray, yArray should all be 1d arrays. | |
Then it returns 2 fortran-style 2D arrays, that is, | |
they are all column-major order: | |
http://www.wikiwand.com/en/Row-_and_column-major_order. | |
The returned xMesh and yMesh are all of shape [xNum, yNum]. | |
*/ | |
let xNum = xArray.size; | |
let yNum = yArray.size; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function meshgrid(xArray, yArray, zArray) { | |
/* | |
Here xArray, yArray, zArray should all be 1d arrays. | |
Then it returns 3 fortran-style 3D arrays, that is, | |
they are all column-major order: | |
http://www.wikiwand.com/en/Row-_and_column-major_order. | |
The returned xMesh, yMesh, and zMesh are all of shape | |
[zNum, xNum, yNum]. | |
*/ | |
let xNum = xArray.size; |