Compare commits

...

3 Commits

Author SHA1 Message Date
Simon Bruder e39b3dac30
Use pre-commit hook from pre-commit-hooks.nix 2020-10-02 17:20:30 +02:00
Simon Bruder f8cf89b532
latexpic: Use nix-shell 2020-10-02 17:18:41 +02:00
Simon Bruder 7791a46986
Add quizlet2anki 2020-09-14 20:58:57 +02:00
6 changed files with 46 additions and 14 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
wordclock_credentials.py
/.pre-commit-config.yaml
__pycache__
wordclock_credentials.py

View File

@ -1,6 +0,0 @@
repos:
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3

11
default.nix Normal file
View File

@ -0,0 +1,11 @@
let
nix-pre-commit-hooks = import (builtins.fetchTarball "https://github.com/cachix/pre-commit-hooks.nix/tarball/master");
in
{
pre-commit-check = nix-pre-commit-hooks.run {
src = ./.;
hooks = {
black.enable = true;
};
};
}

View File

@ -1,4 +1,10 @@
#!/usr/bin/env bash
# shellception since nix-shell and shebang does not work with combining texlive
if ! command -v xelatex >> /dev/null; then
nix-shell -p 'texlive.combine { inherit (pkgs.texlive) scheme-small chemfig simplekv siunitx standalone varwidth; }' --run "$0 $@"
exit $?
fi
tmpdir=$(mktemp -d)
cd $tmpdir
@ -19,7 +25,7 @@ $(cat $OLDPWD/$1)
\end{document}
EOF
lualatex doc.tex
xelatex doc.tex
mutool draw -o doc.svg doc.pdf
inkscape -D -A doc.pdf doc.svg
mutool draw -r 600 -o $OLDPWD/${1}.png doc.pdf

24
quizlet2anki.py Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p python3
# I want to use Anki instead of Quizlet. However, Quizlet only provides a very
# limited “export” functionality, that exports something like csv, but does nut
# support quoting. So it will fail if your separation character is either your
# column or row separator (e.g. if you have multiple lines in one field).
# This script takes unquoted data with uncommon separators (|||||| for columns,
# \n------\n for rows) and exports it as a more usable csv (quoted, cols
# separated by \t, rows separated by \n)
import sys
outfile = sys.argv[1]
quizlet_output = sys.stdin.read()
maybe_tsv = (
'"' + quizlet_output.replace("||||||", '"\t"').replace("\n------\n", '"\n"') + '"'
)
maybe_tsv = maybe_tsv[:-2]
with open(outfile, "w") as f:
f.write(maybe_tsv)

View File

@ -2,13 +2,9 @@
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
gitAndTools.pre-commit
(python3.withPackages(ps: [ ps.virtualenv ]))
nixpkgs-fmt
];
shellHook = ''
# blacks pre-commit hook builds a wheel (zip file) for black and fails
# when the timestamp is lower than 1980 (due to zip limitations)
export SOURCE_DATE_EPOCH=315532800
pre-commit install -f >/dev/null
${(import ./default.nix).pre-commit-check.shellHook}
'';
}