Skip to content

Instantly share code, notes, and snippets.

Avatar
😆

Tyler Neylon tylerneylon

😆
View GitHub Profile
@tylerneylon
tylerneylon / trees.js
Created Jul 6, 2022
A js function for a chromatic spanning tree: a spanning tree that preserves the connection of same-color subgraphs.
View trees.js
/* 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 Jun 30, 2022
A shell / imagemagick script to create nice transparent images from b&w ones.
View make_transparent.sh
#!/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 Apr 25, 2022
Relatively simple Python to decode a PEM private key file (traditional file format).
View read_keyfile.py
#!/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 Apr 2, 2022
A short Python module to convert to and from 7date strings. See http://tylerneylon.com/a/7date_spec/
View 7date.py
# -*- 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 Oct 9, 2021
A short Python script to print out anagrams.
View anagrams.py
#!/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.
"""
View some_random_words.py
#!/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
Demonstrate one way to render text-based line-drawings in Python with curses.
View box_drawing.py
""" 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'}
@tylerneylon
tylerneylon / cryptogram.py
Last active Sep 12, 2021
A simple tool to help you solve your cryptograms.
View cryptogram.py
#!/usr/bin/env python3
""" cryptogram.py
A small tool to help you solve your cryptogram for Python 3.
Usage:
./cryptogram.py <cryptogram_text>
From there you'll get a prompt until you've solved the puzzle at hand
@tylerneylon
tylerneylon / prec_95_example.ipynb
Created May 30, 2019
Example of visualizing and extracting classifier cutoff values to meet certain precision-recall objectives.
View prec_95_example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View prec_recall.py
# Have 1d array-likes y_true and y_pred.
# y_true is expected to be 0/1,
# and y_pred is expected to have floats in [0, 1].
#
# I learned how to do this from here:
# https://scikit-learn.org/stable/auto_examples/model_selection/plot_precision_recall.html
from sklearn.metrics import average_precision_score
from sklearn.metrics import precision_recall_curve