Skip to content

Instantly share code, notes, and snippets.

Leland Batey lelandbatey

Block or report user

Report or block lelandbatey

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lelandbatey
lelandbatey / json_schema_stats
Last active Jul 12, 2019
A tool for examining statistics about JSON object structures. A great way to examine documents in a MongoDB collection for consistency.
View json_schema_stats
#! /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
Turn an indented block of text into a 'tree' view with unicode lines
View treeify.py
#!/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 Apr 29, 2019
Golang reflection; assign to struct field by tag name
View assign_struct_field_by_tag_name.go
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 Mar 16, 2019
A recipe for spanish-style rice with tomato, rice, and beans
View mexican-tomato-rice-and-beans.md
@lelandbatey
lelandbatey / index.html
Created Mar 11, 2019
A demonstration of the importance of correct RGB color interpolation
View index.html
<!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/lodash@4.17.11/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 Nov 4, 2018
A recipe for stir fry peppers and onions. Taken from the New York Times, but now more accessible and not behind a paywall.
View stir-fry-peppers-and-onions.md
@lelandbatey
lelandbatey / probabilities.py
Last active Feb 9, 2017
Proto-minesweeper probability -- a kludged together POC for statistics of mines in squares
View probabilities.py
'''
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 Dec 18, 2016
Poisson disk, implemented from the paper!
View distribution.js
// 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();
@lelandbatey
lelandbatey / index.html
Last active Jan 9, 2017
Draw a fractal tree using javascript on an HTML5 canvas.
View index.html
<!DOCTYPE html>
<html lang="en">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<body style="margin: 0;">
<canvas id='canvas' width='4000' height='2000'></canvas>
</body>
<script>
// To run, download this file and serve it via some http server; I prefer
@lelandbatey
lelandbatey / tac.py
Created Mar 25, 2016
Tic tac toe bot beginnings
View tac.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
class player:
X = 'X'
O = 'O'
class Board(object):
You can’t perform that action at this time.