Skip to content

Instantly share code, notes, and snippets.

View tylerneylon's full-sized avatar
😆

Tyler Neylon tylerneylon

😆
View GitHub Profile
@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 / learn.lua
Last active May 16, 2024 05:47
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@tylerneylon
tylerneylon / 7date.c
Created July 2, 2013 21:24
7date.c Print out today's date in the form: <day-of-year base 7 (0-indexed)>.<year>
// 7date.c
//
// Print out today's date in the form
// <day-of-year base 7 (0-indexed)>.<year>
//
// Examples:
//
// Jan 1, 1925 == 0.1925
//
// Feb 1, 2025 == 43.2025
@tylerneylon
tylerneylon / queue_math.py
Created August 13, 2013 20:31
Empirical bounds checking on approximations related to the performance of a parallel queue structure
#!/usr/bin/python
#
# queue_math.py
#
# Checking some calculations on the memory efficiency of a
# hypothetical queue data structure.
#
import random
import sys
@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 / utf8.c
Last active May 3, 2023 12:17
C utf-8 encoder/decoder
// Stops at any null characters.
int decode_code_point(char **s) {
int k = **s ? __builtin_clz(~(**s << 24)) : 0; // Count # of leading 1 bits.
int mask = (1 << (8 - k)) - 1; // All 1's with k leading 0's.
int value = **s & mask;
for (++(*s), --k; k > 0 && **s; --k, ++(*s)) { // Note that k = #total bytes, or 0.
value <<= 6;
value += (**s & 0x3F);
}
return value;
@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 / md_to_tex.py
Last active September 12, 2021 00:30
Convert markdown to LaTeX
#!/usr/local/bin/python3
#
# Usage:
# md_to_tex.py <md_filename> > myfile.tex
#
# Converts simple markdown to a LaTeX file.
# Use, for example, "pdflatex myfile.tex" to
# generate a pdf file using your output file.
#
# The current script does *not* parse all