Skip to content

Instantly share code, notes, and snippets.

View Sonictherocketman's full-sized avatar

Brian Schrader Sonictherocketman

View GitHub Profile
@Sonictherocketman
Sonictherocketman / todolist.sh
Last active February 1, 2024 16:15
Create a continuously updated todo list from code comments. https://brianschrader.com/archive/todolist/
#! /bin/bash
# Given the current working directory, find all of the files of the
# type given and search for TODO comments in them and return a list
# of these items.
#
# Usage: todolist <dir> '*.py'
DIR=$1
if [ -z "$DIR" ]; then
DIR="."
@Sonictherocketman
Sonictherocketman / life.py
Last active September 11, 2023 21:52
The game of life in Python.
#! /usr/bin/env python3
#
# The Game of Life in Python with no dependencies.
# by Brian Schrader
#
# The board is randomly generated each time so each play-through is unique!
#
# Usage:
# ./life.py
@Sonictherocketman
Sonictherocketman / pinboard-weekly-newsletter.sh
Created April 3, 2021 20:28
A personalized weekly Pinboard-based newsletter of pages you said you wanted to read.
set -e;
# Creates a simple email message containing links from your recent Pinboard
# bookmarks that are marked as "to read".
echo "[$(date)] Beginning pinboard weekly summary...";
CREDS="user:token"
TO="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
@Sonictherocketman
Sonictherocketman / gzip_classifier.py
Last active July 15, 2023 22:31
A basic text classifier that uses gzip.
#! /usr/bin/env python3
#
# A basic text classifier that uses gzip.
#
# Method from https://arxiv.org/pdf/2212.09410.pdf
# Data from http://groups.di.unipi.it/~gulli/AG_corpus_of_news_articles.html
#
# Get newsSpace from URL above and generate files as shown below:
# head -100 newsSpace | tail -25 > test.txt
# tail -100000 newsSpace > train.txt
@Sonictherocketman
Sonictherocketman / gas-sim.py
Created June 3, 2023 17:14
An in-dev gas diffusion simulation in Python.
#! /usr/bin/env python3
from tkinter import *
from tkinter.ttk import *
from dataclasses import dataclass
import math
from random import randint, uniform
@Sonictherocketman
Sonictherocketman / collatz.py
Created April 14, 2023 20:15
A script to visualize the Collatz Conjecture
#! /usr/bin/env python3
# Fun with the Collatz Conjecture
from argparse import ArgumentParser
import csv
import logging
import matplotlib.pyplot as plt
import sys
@Sonictherocketman
Sonictherocketman / pine-to-mastodon.py
Created March 10, 2023 03:26
A script to automatically cross-post from Pine.blog to Mastodon.
#! /usr/bin/env python3
import argparse
from bs4 import BeautifulSoup
from contextlib import contextmanager
from datetime import datetime
import markdown
import json
import httpx
import sys
import uuid
@Sonictherocketman
Sonictherocketman / rocket.py
Created March 10, 2023 08:59
A simple rocket simulation in Python.
#! /usr/bin/env python3
""" rocket.py -- Draw simulated rocket launches with turtle graphics
Sample Parameters:
via https://en.wikipedia.org/wiki/Falcon_9
$ python3.10 rocket.py -i 282 -a 90 -r 60 -p 950 -f 3500 -b 162
author: Brian Schrader
"""
@Sonictherocketman
Sonictherocketman / audiobookr.sh
Created March 1, 2023 04:12
A script to turn large text documents into audiobooks with chapters.
#! /usr/bin/env zsh
# Given a text file, split it into chapters, then make audio for each
# chapter using a set of presets. Then join the audio together
# preserving each chapter in the metadata.
# This assumes mp4.sh is in /usr/local/bin
# https://gist.github.com/djotto/fca0b0e57c8d008575eb7f3648260910
SOURCE_DIR="$(pwd)"
@Sonictherocketman
Sonictherocketman / django-unittest.py
Created February 16, 2023 22:36
ChatGPT Code Samples
from django.urls import reverse
from rest_framework.test import APITestCase
from rest_framework import status
from .models import User
class UserTests(APITestCase):
def test_create_user(self):
"""
Ensure we can create a new user object.