Skip to content

Instantly share code, notes, and snippets.

View tylerneylon's full-sized avatar
😆

Tyler Neylon tylerneylon

😆
View GitHub Profile
@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 / json_leaf_caller.py
Created September 28, 2022 20:55
A little function to help analyze / debug / understand a json object.
def call_on_leaves(json_obj, fn, path=None):
path = path or []
if type(json_obj) is dict:
for k, v in json_obj.items():
if not call_on_leaves(v, fn, path + [k]):
return False
elif type(json_obj) is list:
for i, v in enumerate(json_obj):
if not call_on_leaves(v, fn, path + [i]):
return False
@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 / 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.
"""
#!/usr/bin/env python3
""" some_random_words.py
Usage:
./some_random_words.py [letters_start_w_key_letter]
Prints out a bunch of random words that use these letters,
and which include the key letter.
"""
@tylerneylon
tylerneylon / box_drawing.py
Created May 17, 2020 05:07
Demonstrate one way to render text-based line-drawings in Python with curses.
""" box_drawing.py
The main function here is add_box_char(), which provides a user-friendly
interface to render line-drawings, often referred to as "box-drawing," in a
terminal.
Here are the box-drawing characters used, along with their direction sets;
the direction set is the key input to add_box_char():
─ 0x2500 {'right', 'left'}