Skip to content

Instantly share code, notes, and snippets.

View Splines's full-sized avatar
👋

Splines Splines

👋
View GitHub Profile
@Splines
Splines / increase-pdf-margins.py
Created April 16, 2024 16:42
Add white margins to a PDF. Good to have some more space to take notes, e.g. in uni lectures.
# pip install pymupdf
import fitz
src = fitz.open("QM_SS24_Skript.pdf")
doc = fitz.open()
LEFT_MARGIN = 100
RIGHT_MARGIN = 100
@Splines
Splines / theo-annoying-exercise-decision-tree.py
Last active June 16, 2023 06:17
A decision tree for a superflous task in theoretical physics II
# Written by Splines, https://github.com/splines
# Change WITH_PUTBACKS to True or False to change if we allow putbacks or not
# In order to run this, you need to install Graphviz first,
# see the installation guide here:
# https://graphviz.readthedocs.io/en/stable/#installation
from typing import List
import numpy as np
@Splines
Splines / lighten_color.py
Last active February 24, 2022 00:43 — forked from ihincks/lighten_color.py
Function to lighten any color in matplotlib
def change_brightness(color, amount=1):
"""
Changes the brightness of the given color by multiplying luminosity
by the given amount.
Input can be a matplotlib color string, hex string, or RGB tuple.
The color gets brighter when amount > 1 and darker when amount < 1.
The resulting luminosity is restricted to [0,1].
@Splines
Splines / mono-synth.py
Created February 19, 2022 21:31
A very basic mono synthesizer using PyAudio and Matplotlib
# Installation
# Run `pip install pyaudio` first
# If that throws an error, you need to install a "wheel" first (pre-packaged binary)
# Follow the instructions here: https://stackoverflow.com/a/71073645/9655481
# e.g. I use Python 3.9.6 and installed the file "PyAudio‑0.2.11‑cp39‑cp39‑win_amd64.whl"
# from here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio
import time
import matplotlib.pyplot as plt
@Splines
Splines / mnist.py
Created October 3, 2021 01:23
Parse the MNIST train set
# 🌐 MNIST Dataset
# https://deepai.org/dataset/mnist
import numpy as np
from matplotlib import pyplot as plt
with open('./mnist/train-images.idx3-ubyte', 'rb') as images_file,\
open('./mnist/train-labels.idx1-ubyte', 'rb') as labels_file:
# --- Images Header
@Splines
Splines / mnist.py
Last active October 3, 2021 00:54
Parse the MNIST images header
# --- Images Header
# 4x 32-bit big-endian integer
images_header = np.fromfile(images_file, dtype='>i4', count=4)
images_magic_number = images_header[0]
images_count = images_header[1]
row_count = images_header[2]
col_count = images_header[3]
pixel_count = row_count*col_count
@Splines
Splines / mnist.py
Last active October 3, 2021 00:21
Open the MNIST binary files
import numpy as np
from matplotlib import pyplot as plt
with open('./mnist/train-images.idx3-ubyte', 'rb') as images_file,\
open('./mnist/train-labels.idx1-ubyte', 'rb') as labels_file: