Skip to content

Instantly share code, notes, and snippets.

View lelandbatey's full-sized avatar

Leland Batey lelandbatey

View GitHub Profile
@lelandbatey
lelandbatey / index.html
Created March 11, 2019 23:15
A demonstration of the importance of correct RGB color interpolation
<!DOCTYPE html>
<html lang="en">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>
<body style="margin: 0;">
<div>
<canvas id='canvas1' width='800' height='200'></canvas>
</div>
<div>
@lelandbatey
lelandbatey / mexican-tomato-rice-and-beans.md
Created March 16, 2019 18:43
A recipe for spanish-style rice with tomato, rice, and beans
@lelandbatey
lelandbatey / assign_struct_field_by_tag_name.go
Last active February 28, 2025 19:53
Golang reflection; assign to struct field by tag name
package main
import (
"fmt"
"reflect"
"strings"
)
// The goal: allow assignment to a go struct field based on the name that field
// is tagged with (specifically it's json-tagged name).
@lelandbatey
lelandbatey / treeify.py
Created May 23, 2019 17:41
Turn an indented block of text into a 'tree' view with unicode lines
#!/usr/bin/env python3
'''
Treeify takes a file (on stdin or passed as the first argument) and converts
it's indentation into a 'tree' representation. As an example:
what
is
this
thing
that's
@lelandbatey
lelandbatey / json_schema_stats
Last active October 15, 2021 23:59
A tool for examining statistics about JSON object structures. A great way to examine documents in a MongoDB collection for consistency.
#! /usr/bin/env python3
# Downloaded from here: https://gist.github.com/lelandbatey/64e7c7d3d86b4a1b455a93f593562d68
from collections import Sequence
from operator import itemgetter
from codecs import escape_encode
import argparse
import json
import math
import sys
@lelandbatey
lelandbatey / sane_text_formatter.go
Created October 1, 2019 22:55
Sane text formatter. Formats text in a 'nice' way, though very basic.
package main
import (
"bufio"
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
@lelandbatey
lelandbatey / load_arena_cards.py
Created October 15, 2019 05:01
Read and process MTGA log events
import json
def arena_card_db():
carddb = dict()
with open("AllCards.json", 'r') as mtgjsonf:
carddb = json.load(mtgjsonf)
arena_cards = list()
for card_name, card in carddb.items():
@lelandbatey
lelandbatey / histogram_timestamps.py
Last active July 27, 2020 20:01
A tool for viewing streams of timestamps as histograms. Uses Matplotlib and Pandas
#!/usr/bin/env python3
'''
A tool for viewing streams of timestamps as histograms.
'''
import matplotlib.pyplot as plt
from datetime import datetime
import matplotlib.dates as mdates
import pandas as pd
import itertools
import argparse
@lelandbatey
lelandbatey / collection_access_tracker.py
Created February 5, 2020 18:59
Python class for tracking access to members of collections. Great for legacy code were we wonder "what's being accessed in this big dict and where is it being accessed?"
from __future__ import print_function
import inspect
import six
def fmt_stack(frames):
s = ""
for f in frames[::-1]:
s += "{}:{}: {}\n".format(f[1], f[2], '\\n'.join([x.replace('\n', '') for x in f[4]]))
return s
@lelandbatey
lelandbatey / held_up.py
Last active March 14, 2020 04:28
Show what cards you could be holding up in MTGA
import itertools
import json
'''
Show the cards you could be holding up in MTGA at instant speed.
TODOs:
1. Make it color sensitive
2. Account for cards with flash
3. Make a UI (like at ALL)