Skip to content

Instantly share code, notes, and snippets.

Avatar
😆

Tyler Neylon tylerneylon

😆
View GitHub Profile
@tylerneylon
tylerneylon / .block
Last active Aug 6, 2022
Quick js code to draw math functions in an SVG element.
View .block
license: mit
@tylerneylon
tylerneylon / rwlock.py
Last active Aug 2, 2022
A simple read-write lock implementation in Python.
View rwlock.py
# -*- coding: utf-8 -*-
""" rwlock.py
A class to implement read-write locks on top of the standard threading
library.
This is implemented with two mutexes (threading.Lock instances) as per this
wikipedia pseudocode:
https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock#Using_two_mutexes
@tylerneylon
tylerneylon / copy.lua
Last active Jul 27, 2022
How to deep copy Lua values.
View copy.lua
-- copy.lua
--
-- Lua functions of varying complexity to deep copy tables.
--
-- 1. The Problem.
--
-- Here's an example to see why deep copies are useful. Let's
-- say function f receives a table parameter t, and it wants to
@tylerneylon
tylerneylon / update_sec_group.py
Last active Jul 19, 2022
A script to add your ip to an ec2 security group.
View update_sec_group.py
#!/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 / learn.lua
Last active Jul 11, 2022
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
View learn.lua
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@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 / json.lua
Last active Jun 14, 2022
Pure Lua json library.
View json.lua
--[[ json.lua
A compact pure-Lua JSON library.
The main functions are: json.stringify, json.parse.
## json.stringify:
This expects the following to be true of any tables being encoded:
* They only have string or number keys. Number keys must be represented as
strings in json; this is part of the json spec.
@tylerneylon
tylerneylon / mnist.py
Last active Apr 30, 2022
A function to load numpy arrays from the MNIST data files.
View mnist.py
""" 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 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