Skip to content

Instantly share code, notes, and snippets.

View lelandbatey's full-sized avatar

Leland Batey lelandbatey

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / stir-fry-peppers-and-onions.md
Created November 4, 2018 01:55
A recipe for stir fry peppers and onions. Taken from the New York Times, but now more accessible and not behind a paywall.
@lelandbatey
lelandbatey / probabilities.py
Last active December 31, 2022 01:29
Proto-minesweeper probability -- a kludged together POC for statistics of mines in squares
'''
A toy example to calculate the probability of a mine existing on any particular square.
Runs slowly and is organized like spaghetti, but it does currently work!
Note that for this to work, it depends on a slightly modified defusedivision;
inside defuse_division the _create_foothold function in game.py has to be
modified to be public, instead of private like in the public version.
@lelandbatey
lelandbatey / distribution.js
Last active December 18, 2016 03:41
Poisson disk, implemented from the paper!
// I implemented poisson disk selection from this paper: http://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf
// This was very fun, I highly recommend it to anybody!
function create_draw(ctx) {
return {
line: (start, end) => {
let [sx, sy] = start;
let [ex, ey] = end;
ctx.beginPath();