Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tylerneylon's full-sized avatar
😆

Tyler Neylon tylerneylon

😆
View GitHub Profile
@tylerneylon
tylerneylon / markov.py
Created January 31, 2014 00:27
Generate random real-sounding words using an input text file as a basis; uses Markov chains of 3-grams to internally build the new random words.
#!/usr/local/bin/python3
#
# markov.py
#
# Reads in a text file and produces a list of random
# words with similar 3-grams to those found in the input file.
#
# Usage: ./markov.py <text_filename>
#
@tylerneylon
tylerneylon / mem.py
Last active August 29, 2015 13:58
A Python3 script to help exercise your memory.
#!/usr/local/bin/python3
import datetime
import json
import os
import random
import time
num_words = 10
@tylerneylon
tylerneylon / glhelp.c
Created August 6, 2014 06:53
Basic tools to assist OpenGL code.
// glhelp.c
//
#include "glhelp.h"
// The following files are available from:
// https://github.com/tylerneylon/oswrap
// Please add the appropriate (win or mac) oswrap directory to your project.
#include "cbit.h"
#include "oswrap/oswrap.h"
@tylerneylon
tylerneylon / matrix.html
Last active August 29, 2015 14:05
A page to try out elementary row operations on a matrix.
<!DOCTYPE html>
<!--
# matrix.html
*An interactive tool to perform elementary row operations on a matrix.*
I built this tool so I could speed up some hand calculations I was performing
while learning linear programming algorithms.
I thought it might be helpful for others learning or working with linear
@tylerneylon
tylerneylon / all_top_sorts.lua
Created October 8, 2014 17:08
Print permutations where certain pairs must be in a given order.
-- all_top_sorts.lua
--
-- Generate all permutations - aka topological sorts - of
-- the set [1, 2, ..., n] such that the permutation has
-- certain pairs in a given order. This can also be thought
-- of as listing all linear orders consistent with a given
-- partial order.
--
-- This code is based on chapter 3 of
-- Donald Knuth's book Literate Programming.
@tylerneylon
tylerneylon / time_lock_inj.lua
Created April 9, 2015 20:12
Tool to isolate bottleneck mutex locks in C-family code.
-- time_lock_inj.lua
--
local usage_str = [[
Usage:
lua time_lock_inj.lua <list_of_input_source_files>
Injects lock timing code for all the given files.
This assumes you're locking things with calls to
--[[ Summary: Below, "entity" and "item" may be different types.
They simply implement same-name methods.
--]]
-- A bit from entities.lua:
function entities.runloop(dt)
for _, entity in pairs(all_entities) do
entity:update_and_draw(dt)
end
@tylerneylon
tylerneylon / nqueens.lua
Created December 13, 2015 08:58
A Lua-based solution to the n-queens problem.
-- Call this function as `grid = can_find_solution(N)`.
function can_find_solution(N, x0, y0, grid)
x0, y0 = x0 or 0, y0 or 1 -- Set default vals (0, 1).
if grid == nil then
grid = {}
for i = 0, N do grid[i] = {} end
end
for x = 1, x0 - 1 do
if grid[x][y0] or grid[x][y0 - x0 + x] or grid[x][y0 + x0 - x] then
return false
@tylerneylon
tylerneylon / rounded_rectangle.lua
Created March 25, 2013 08:57
This Lua function draws a rounded-corner rectangle when used in the Love game engine. Its parameters are consistent with the love.graphics conventions.
-- This is similar to love.graphics.rectangle, except that the rectangle has
-- rounded corners. r = radius of the corners, n ~ #points used in the polygon.
function rounded_rectangle(mode, x, y, w, h, r, n)
n = n or 20 -- Number of points in the polygon.
if n % 4 > 0 then n = n + 4 - (n % 4) end -- Include multiples of 90 degrees.
local pts, c, d, i = {}, {x + w / 2, y + h / 2}, {w / 2 - r, r - h / 2}, 0
while i < n do
local a = i * 2 * math.pi / n
local p = {r * math.cos(a), r * math.sin(a)}
for j = 1, 2 do
@tylerneylon
tylerneylon / perms.lua
Created December 18, 2015 13:20
A Lua iterator for all permutations over the integers {1, 2, ..., n}.
-- This is meant to be used in a for loop, as in:
-- for perm in perms(n) do <stuff> end
function perms(n)
local function iter(state, val)
if not val then
val = {}
for i = 1, n do
val[i] = i
end
return val