Skip to content

Instantly share code, notes, and snippets.

---
# Pathline with the following settings:
# 3116 7 0.02 298 nsteps ictrl eqincr temp
schema:
delimiter: ' '
missing: '-'
fields:
- name: step
type: integer
@adigitoleo
adigitoleo / dingbats.tex
Created October 26, 2022 13:37
(Lua)LaTex pifont dingbat codes
\documentclass{minimal}
\usepackage{pifont}
\begin{document}
U+2701 \ding{"21}%[✁]
\par U+2702 \ding{"22}%[✂]
\par U+2703 \ding{"23}%[✃]
\par U+2704 \ding{"24}%[✄]
\par U+260E \ding{"25}%[☎]
\par U+2706 \ding{"26}%[✆]
\par U+2707 \ding{"27}%[✇]
@adigitoleo
adigitoleo / mineral_list_IMA.py
Created July 27, 2022 02:26
Script to parse IMA mineral list into CSV file
import re
import csv
import pdfplumber
# Create a list of minerals as classified by the IMA.
# Get PDF from http://cnmnc.main.jp/
pdf = pdfplumber.open("IMA_MineralList_202207.pdf")
@adigitoleo
adigitoleo / misc.jl
Last active December 14, 2022 09:14
Miscellaneous stuff for Julia
using Pkg
using TerminalPager
using UnicodePlots
# Reduce color space of most REPL components from 16 to 8.
# Line numbers is stacktraces are still unreadable in dark themes...
Base.text_colors[:white] = Base.text_colors[:yellow]
Base.text_colors[:light_cyan] = Base.text_colors[:cyan]
Base.text_colors[:light_red] = Base.text_colors[:red]
Base.text_colors[:light_magenta] = Base.text_colors[:magenta]
@adigitoleo
adigitoleo / Makefile
Created April 28, 2022 12:10
Makefile for LuaLaTeX documents with Biber for references
src := $(wildcard *.tex)
bib := $(wildcard *.bib)
all: $(src:%.tex=%.pdf)
%.pdf: $(src) out/%.bbl
@ 1>/dev/null lualatex --output-directory=out --interaction=batchmode --halt-on-error --file-line-error $< \
|| echo "LuaLaTeX run 2/3 failed, check log files in out/ for details"
@ lualatex --output-directory=out --halt-on-error --file-line-error $<|rg -v '/usr/share/'
@ mv out/$@ $@
@adigitoleo
adigitoleo / bigint_modinv.jl
Created March 27, 2022 11:27
Arbitrary precision modular matrix inverse in Julia
using LinearAlgebra
function inverse(a::AbstractMatrix{BigInt}, modulus)
m, n = size(a)
if m - n != 0
error("cannot find modular inverse of non-square matrix")
end
det_inv = invmod(BigInt(det(a)), modulus)
if det_inv == 0
@adigitoleo
adigitoleo / utils.jl
Created March 16, 2022 13:28
Franklin.jl utils for reference lists
using TOML
using HTTP
"""
get_ref(key)
Get HTML-formatted reference text for the given referernce key.
The key must match either a key in the `_assets/refcache.toml`
or the `_assets/doilist.toml` file. The text will be formatted with
@adigitoleo
adigitoleo / pre-commit
Created February 22, 2022 00:11
Python black pre-commit hook
#!/bin/sh
# Copy or link this script into .git/hooks/
# It runs automatically in the project root directory (parent of .git/).
# Code formatting
if black --check src/pydrex; then
exit 0
else
black src/pydrex
git add -u
from fractions import Fraction
def fspread(count, start, end=None, step=None, mode=1):
"""Generate evenly-spaced floats.
Yields a sequence of evenly-spaced numbers. Optional `mode` controls
endpoint behaviour. Requires the stdlib class `fraction.Fraction`. Source:
http://code.activestate.com/recipes/577881-equally-spaced-floats-part-2/
"""Read columns of a delimited file into a namedtuple.
Supports column type parsers, e.g.
def parser(colname, data):
if colname == "foo":
return map(float, data)
return data
"""