Skip to content

Instantly share code, notes, and snippets.

@bschne
bschne / git-todo
Created July 17, 2025 07:09
Putting this in your path gives you a git command, "git todo", that shows TODOs added between the current state of your working directory and a base branch
#!/usr/bin/env bash
set -euo pipefail
# Usage: git todo [base-branch] [--allcase] [--strict]
# Default base branch = develop.
base=${1:-develop}
shift || true
match_case=0 # 0 = case-sensitive (ignore "todos"), 1 = case-insensitive
@bschne
bschne / extract_pdf_pages.py
Created February 26, 2025 16:59
Helper function to extract a range of pages from a PDF as bytes
import PyPDF2
from io import BytesIO
def extract_pdf_pages(pdf_path, first_page, last_page):
"""
Extract specific pages from a PDF file.
Args:
pdf_path (str): Path to the input PDF file.
first_page (int): 1-based index of the first page to extract.
@bschne
bschne / ptxt.sh
Created October 14, 2024 13:09
PDF to Clipboard Text
# Extracts text from a PDF file and copies it to clipboard
# This relies on pdftotext, which you can install via "brew install poppler"
# pbcopy is available by default on macOS, but if you're on linux, this won't work
ptxt() {
if [[ -z "$1" ]]; then
echo "Usage: ptxt <path_to_pdf>"
return 1
fi
local pdf_path="$1"
@bschne
bschne / README.md
Created October 27, 2022 17:18
Sensirion CO2 Gadget BLE <-> Python

Sensirion CO2 Gadget BLE <-> Python

  • BLE Library Docs: Bleak
    • Might have to pip3 install bleak first
  • Protocol Docs from Sensirion: Link
    • I'm listening for the BLE advertisement here (see p4 for data structure)
    • Calculation of measurements from ticks see p7, "3.9 Sample 8"
  • You can get the device address from the scan.py script (doesn't always show the name for some reason) or a tool like BlueSee
  • Code to get the data is in log-data.py
@bschne
bschne / zen-twitter.css
Created March 18, 2021 14:26
Zen Twitter
/*
* Set these as userstyles for the respective domain to hide everything but
* notifications, messages, and the option to write a tweet.
*
* Originally from Beck Tench (twitter.com/@10ch)
*/
/* twitter.com */
[role="complementary"] {visibility: hidden;}
[data-testid="sidebarColumn"] {visibility: hidden;}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bschne
bschne / pagerank.ipynb
Created October 11, 2019 10:11
PageRank - What happens with and without damping
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bschne
bschne / lec4-ex3.py
Created October 8, 2019 16:21
HS2019-Inf1-Lec4 Exercise 3
#!/usr/bin/python3
def copy_file(src, dest, header):
with open(dest, "w+") as d:
d.write(header + "\r\n")
with open(src) as s:
for line in s:
d.write(line)
@bschne
bschne / lec4-ex2.py
Created October 8, 2019 16:20
HS2019-Inf1-Lec4 Exercise 2
#!/usr/bin/python3
def fibonacci(n):
if n <= 1:
return 1
return fibonacci(n-1) + fibonacci(n-2)
print([fibonacci(i) for i in range(20)])
@bschne
bschne / lec4-ex1.py
Created October 8, 2019 16:20
HS2019-Inf1-Lec4 Exercise 1
#!/usr/bin/python3
def sum_of_digits(number):
digit_sum = 0
for digit in str(number):
digit_sum += int(digit)
return digit_sum