Skip to content

Instantly share code, notes, and snippets.

import pathlib
import zipfile
main_dir = r"folder_with_a_bunch_of_zips"
# extract a zip file windows
def extract_zip(zip_file):
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
@heathhenley
heathhenley / hacking_on_s63.ipynb
Last active April 24, 2024 22:32
hacking_on_S63.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@heathhenley
heathhenley / s63.ipynb
Created February 3, 2024 01:45
S63.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@heathhenley
heathhenley / example_x2_newton.py
Created January 16, 2024 19:15
example using newton's method on x2 -4
import matplotlib.pyplot as plt
import numpy as np
def get_f_df(c: list[int]) -> tuple[callable, callable]:
""" Get the function and its derivative for a given polynomial c"""
def f(z):
ans = 0
for i, c_i in enumerate(c):
@heathhenley
heathhenley / newton_fractal.py
Created January 16, 2024 19:12
simple python script to make a newton fractal
# I ran on python 3.12
# requires `pip install matplotlib numpy`
import matplotlib.pyplot as plt
import numpy as np
def get_f_df(c: list[int]) -> tuple[callable, callable]:
""" Get the function and its derivative for a given polynomial c"""
def f(z):
@heathhenley
heathhenley / tz_test.py
Last active January 16, 2024 13:44
tz_test --> demonstrates that pg and sqlite behavior might differ with datetime cols and tz aware python datetimes
import datetime as dt
from sqlalchemy import create_engine, Column, DateTime, Integer, String
from sqlalchemy.orm import declarative_base, sessionmaker
Base = declarative_base()
class TZTest(Base):
__tablename__ = 'tztest'
id = Column(Integer, primary_key=True)
timestamp_no_tz = Column(DateTime)
@heathhenley
heathhenley / timing_leak.py
Created December 27, 2023 02:34
Timing leak example
import timeit
TOKEN = b"super_secret_token"
# Which one is better?
def is_authorized_one(provided_token: bytes, expected_token: bytes) -> bool:
return provided_token == expected_token
def is_authorized_two(provided_token: bytes, expected_token: bytes) -> bool:
@heathhenley
heathhenley / set_aliases.bat
Created December 22, 2023 15:13
cl aliases windows
@echo off
doskey gsu=git status -uno
doskey gs=git status
doskey gpr=git pull -r
doskey gf=git fetch
doskey gc=git commit $*
doskey ga=git add $*
doskey gch=git checkout $*
doskey gka=gitk --all
set PATH=%PATH%;"c:\dev\ag"
@heathhenley
heathhenley / test_auto_now_example.py
Last active December 1, 2023 14:22
Tests for Django model that uses columns with auto_now
""" A way to test columns with auto_now
Columns with auto_now auto update with the current time when
the model is saved - this patches function django uses to
get the current time when the model is saved to use whatever
time you want.
Base on answers on SO: https://stackoverflow.com/questions/49874923/how-to-test-auto-now-add-in-django
"""
from contextlib import contextmanager
@heathhenley
heathhenley / investmentmc.ipynb
Created September 24, 2023 19:41
InvestmentMC.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.