Skip to content

Instantly share code, notes, and snippets.

View ivanistheone's full-sized avatar

Ivan Savov ivanistheone

View GitHub Profile
@ivanistheone
ivanistheone / epub2pdf.sh
Created March 25, 2023 23:14
Converst an .epub file to .pdf --- because Preview is easier to use than iBooks
View epub2pdf.sh
#!/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"
@ivanistheone
ivanistheone / tree.py
Created February 27, 2023 17:05
Print filesystem tree, similar to command line tool `tree` in UNIX.
View tree.py
#!/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 / 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).
View mkbirdseye.py
#!/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 / 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...
View fizzbuzz.tex
% 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 / mdnblinks.py
Last active November 21, 2021 19:01
This script generates links to mybinder and colab online Python environments you can use for any jupyter notebook hosted on in a GitHub repo.
View mdnblinks.py
@ivanistheone
ivanistheone / txt2mp3.sh
Last active January 5, 2023 14:55
This script converts a plain text file, e.g. article.txt into a mp3 audiobook using the MacOS text-to-speech accessibility command-line tool `say`. Adjust the `VOICE` and `RATE` parameters to customize to your liking. Note this requires running on MacOS.
View txt2mp3.sh
#!/usr/bin/env bash
set -e
# This script converts any text file into a mp3 audiobook using the MacOS
# text-to-speech accessibility command-line tool `say`.
# Adjust the `VOICE` and `RATE` parameters to customize to your liking:
VOICE="Alex"
RATE="295" # pretty fast
if [ $# -eq 0 ]; then
View kolibridb.py
#!/usr/bin/env python
"""
Helpers for downloding Kolibri databases and printing topic trees:
./kolibridb.py --channel_id=95a52b386f2c485cb97dd60901674a98
or to get the same result as HTML (assuming you have `pandoc` installed):
./kolibridb.py --channel_id=95a52b386f2c485cb97dd60901674a98 --htmlexport
View excerpt from ck-12 sraper.py
def retrieve_flex_book_lesson(item):
html_url = "/flx/get/perma/modality/lesson/{lesson_id}/{domain_id}?format=html".format(
lesson_id=item["handle"],
domain_id=item["domain"]["encodedID"],
)
dst = tempfile.mkdtemp()
try:
@ivanistheone
ivanistheone / samizdat-shell-help.bash
Last active December 17, 2020 22:23 — forked from kovetskiy/samizdat-shell-help.bash
help text for bas script based on ### comment + awk command
View samizdat-shell-help.bash
#!/bin/bash
###
### my-script — does one thing well
###
### Usage:
### my-script <input> <output>
###
### Options:
### <input> Input file to read.
### <output> Output file to write. Use '-' for stdout.
@ivanistheone
ivanistheone / simple_chef_with_logging.py
Created April 2, 2020 14:08
Demo of common use of config.LOGGER in ricecooker for testing new colorlogs
View simple_chef_with_logging.py
#!/usr/bin/env python
from ricecooker.chefs import SushiChef
from ricecooker.classes.nodes import ChannelNode, TopicNode, DocumentNode
from ricecooker.classes.files import DocumentFile
from ricecooker.classes.licenses import get_license
from ricecooker.config import LOGGER