Skip to content

Instantly share code, notes, and snippets.

View ivanistheone's full-sized avatar

Ivan Savov ivanistheone

View GitHub Profile
@ivanistheone
ivanistheone / fizzbuzz.tex
Created May 25, 2022 13:08
FizzBuzz of first 100 numbers written using TeX macros. TeX is a very strange programming language, but hey it works...
% Compile with pdftex, not pdflatex
\def\modulo#1#2{(#1-(#1/#2)*#2)} % a mod n = a-(a/n)*n where / is integer division
\newcount\X
\X=1
\loop
\ifnum \numexpr\modulo{\X}{15} = 0
FizzBuzz
@ivanistheone
ivanistheone / mkbirdseye.py
Last active October 2, 2022 01:31
Script that generates a very long PNG image from a PDF document (use to get an high-level overview of a paper or book section).
#!/usr/bin/env python
import argparse
import os
try:
from pdf2image import convert_from_path
from PIL import Image
except ImportError:
print("You need to run `pip install Pillow pdf2image` before this script")
import sys
sys.exit(-1)
@ivanistheone
ivanistheone / tree.py
Created February 27, 2023 17:05
Print filesystem tree, similar to command line tool `tree` in UNIX.
#!/usr/bin/env python
import argparse
import os
def tree(directory=".", indent = " "):
"""
Helper function that prints the filesystem tree.
"""
ignorables = ["__pycache__", ".gitignore", ".DS_Store", ".ipynb_checkpoints", ".git", "venv"]
for root, dirs, files in os.walk(directory):
@ivanistheone
ivanistheone / epub2pdf.sh
Created March 25, 2023 23:14
Converst an .epub file to .pdf --- because Preview is easier to use than iBooks
#!/usr/bin/env bash
set -e
# Converts an .epub file to .pdf
# Requires Calibre and ghostscript to be installed
epubfilename="$1"
namenoext="$(basename -- "$epubfilename" .epub)"
randomstr="$(basename $(mktemp))"
tmpfilename1="$namenoext-$randomstr-1.pdf"
tmpfilename2="$namenoext-$randomstr-2.pdf"