Skip to content

Instantly share code, notes, and snippets.

View tylerneylon's full-sized avatar
😆

Tyler Neylon tylerneylon

😆
View GitHub Profile
@tylerneylon
tylerneylon / add_docstrings.py
Created December 17, 2022 22:40
A simple prototype Python script that uses GPT-3.5 to add docstrings to functions in any given Python file.
#!/usr/bin/env python3
"""
add_docstrings.py
Usage:
add_docstrings.py <my_code.py>
NOTE: This requires Python 3.9+ (this is openai's library requirement).
This app is a work in progress.
@tylerneylon
tylerneylon / term_print.py
Created November 14, 2022 00:03
A handy function to assist in printing in color or doing other fun things in the terminal
import curses
import sys
# NOTE: It's up to YOU, dear coder, to call curses.setupterm() first.
# I believe in you. (If this called setupterm(), then we'd call it more than needed.)
def term_print(strs, *args, flush=True):
''' This expects `strs` to be a list of strings and tuples. Each
string is printed, while each tuple is interpreted as a tput command
with any needed parameters supplied. For example, the tuple ('smul',)
@tylerneylon
tylerneylon / pre-commit
Last active October 12, 2022 08:25
git pre-commit hook to help support github-based code reviews of Jupyter notebooks in Python.
#!/bin/bash
#
# Convert all new Jupyter notebooks to straight Python files for easier code
# reviews.
#
for file in $(git diff --cached --name-only); do
if [[ $file == *.ipynb ]]; then
jupyter nbconvert --to script $file
git add ${file%.*}.py
@tylerneylon
tylerneylon / update_sec_group.py
Last active July 19, 2022 21:05
A script to add your ip to an ec2 security group.
#!/usr/bin/env python3
""" update_sec_group.py
Usage:
./update_sec_group.py [-v] SEC_GROUP_ID
./update_sec_group.py -a ACCESS_KEY -s SECRET_KEY [-v] SEC_GROUP_ID
The -v option provides more verbose output.
@tylerneylon
tylerneylon / trees.js
Created July 6, 2022 11:27
A js function for a chromatic spanning tree: a spanning tree that preserves the connection of same-color subgraphs.
/* trees.js
*
* A couple spanning-tree algorithms.
*
* The most interesting function is the chromatic spanning tree,
* which is intuitively simple yet (for me at least) was not obvious
* in terms of finding a simple js implementation.
*
*/
@tylerneylon
tylerneylon / make_transparent.sh
Created June 30, 2022 20:12
A shell / imagemagick script to create nice transparent images from b&w ones.
#!/bin/bash
#
# Usage:
# ./make_transparent.sh bw_image.png
#
# This converts a black-and-white image to an image that is transparent
# where the input image is white and is opaque where the input image is
# black. The advantage of this script is that it avoids awkward previous-color
# or poorly-antialiased halos around opaque sections. The default opaque color
# is white; this can be changed by editing the #ffffff string, which is a hex
@tylerneylon
tylerneylon / mnist.py
Last active April 30, 2022 06:48
A function to load numpy arrays from the MNIST data files.
""" A function that can read MNIST's idx file format into numpy arrays.
The MNIST data files can be downloaded from here:
http://yann.lecun.com/exdb/mnist/
This relies on the fact that the MNIST dataset consistently uses
unsigned char types with their data segments.
"""
@tylerneylon
tylerneylon / read_keyfile.py
Created April 25, 2022 05:02
Relatively simple Python to decode a PEM private key file (traditional file format).
#!/usr/bin/env python3
# coding: utf-8
"""
read_keyfile.py
Usage:
read_keyfile.py <key_file>
This file can read private PEM key files generated in the traditional file
@tylerneylon
tylerneylon / 7date.py
Created April 2, 2022 19:30
A short Python module to convert to and from 7date strings. See http://tylerneylon.com/a/7date_spec/
# -*- coding: utf-8 -*-
"""
7date.py
A small module to convert a datetime into a 7date string, or to convert a
7date string into a datetime.
The purpose of this file is to make it easier for you to integrate 7date
support into a program that already uses Gregorian dates.
@tylerneylon
tylerneylon / anagrams.py
Created October 9, 2021 18:43
A short Python script to print out anagrams.
#!/usr/bin/env python3
""" anagrams.py
Usage:
./anagrams.py myword
Prints out a list of anagrams of myword.
This uses the file /usr/share/dict/words to get a dictionary.
"""