Skip to content

Instantly share code, notes, and snippets.

@mcgrew
mcgrew / ladder.py
Created October 13, 2021 15:28
Word ladder solver exercise
#!/usr/bin/env python3
from sys import argv
from collections import deque, defaultdict
DICTFILE = "/usr/share/dict/words"
def get_words(length):
words = []
with open(DICTFILE, 'r') as dictfile:
@mcgrew
mcgrew / nesggcc.py
Created April 16, 2020 22:07
NES Game Genie code generator
#!/usr/bin/python
# This python script will generate game genie codes for NES
# Pass in the address and value, with an optional compare value
# in hexadecimal format and it will output a game genie code.
# This is quick and dirty and largely untested, so YMMV.
from sys import argv
if len(argv) < 3:
@mcgrew
mcgrew / twitch_emote_lookup.py
Created October 13, 2018 21:56
Twitch emote lookup by code
#!/usr/bin/env python3
from json import loads
from sys import argv, exit
from urllib.request import Request, urlopen
if len(argv) < 2:
print("Usage: %s <emote_name>" % argv[0])
exit(-1)
@mcgrew
mcgrew / matrix.py
Created December 22, 2016 06:04
A matrix math implementation in python
"""
matrix.py
(c) 2007,2016 Thomas McGrew
"""
VERSION = "0.3-pre"
MATRIX_VALID_TYPES = (int, float, complex)
MATRIX_VALID_TYPENAMES = ('int', 'float', 'complex')
MATRIX_VALID_INTS = (int,)
@mcgrew
mcgrew / .bashrc
Created November 8, 2016 02:06
My bashrc. Useful for command line git users.
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '
@mcgrew
mcgrew / animationsample.html
Created May 12, 2016 04:37
Playing with javascript
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var xmax = 670;
var ymax = 750;
var speed = 3;
var coords = {
pacman: { x: 336, y: 579, dx: 0, dy: 0 },
inky : { x: 0, y: 0, dx: 0, dy: 0 },
@mcgrew
mcgrew / png2tmx.go
Last active August 12, 2023 04:50
Convert a png to a TMX tile map
package main
import(
"image/png"
"image/draw"
"image"
"io"
"os"
"fmt"
"encoding/base64"
@mcgrew
mcgrew / ie8_function_bind.js
Created December 18, 2013 04:11
Replacement for missing bind method of Function in IE8
/* Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind */
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
@mcgrew
mcgrew / classical_update.sh
Created September 10, 2013 16:16
Auto-download script for Classical New England performance podcast
#!/bin/bash
RSS_URL="http://streams.wgbh.org/online/clas/clas_performance.xml"
if [ -z $(which xml 2>/dev/null) ]; then
echo "xmlstarlet does not appear to be installed."
echo "Please make sure it is installed and in your path";
exit 1;
fi
@mcgrew
mcgrew / etc_conf.d_routing
Created July 9, 2013 17:00
Systemd service to enable NAT routing.
wan_interface=ens32
lan_interface=ens33