Skip to content

Instantly share code, notes, and snippets.

View tylerneylon's full-sized avatar
😆

Tyler Neylon tylerneylon

😆
View GitHub Profile
@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 / random_subset.lua
Created March 21, 2016 21:59
Choose a uniformly random k-subset of [1,n] in O(k) time.
-- This returns a sequence of k distinct indexes in the range [1, n] chosen so
-- that, within the context of the pseudorandom generator, each k-subset has an
-- equal probability of being returned.
function random_indexes(k, n)
-- This is a partial Fisher-Yates shuffle, as suggested by this answer:
-- http://stackoverflow.com/a/29868630/3561
local shuf = {}
local indexes = {}
for i = 1, k do
local j = math.random(i, n)
@tylerneylon
tylerneylon / [goes in your .profile]
Last active April 28, 2016 21:12
A simple bash function to help you stay focused.
timey() {
# Inspired by
# https://gist.github.com/commanda/775ebcbe630919b554128b31c3dfb9dd
if [ "$#" -ne 1 ]; then
echo "usage: timey <number of minutes>"
return
fi
url=https://media.giphy.com/media/yWh7b6fWA5rJm/giphy.gif
seconds=$(( $1 * 60 ))
((sleep $seconds; open -a "Google Chrome.app" $url) &)
@tylerneylon
tylerneylon / in_yo_.profile
Last active May 4, 2016 01:09
Bash function to simplify usage of mac os x s
ssfile ()
{
f="$(ls -1tr $HOME/Desktop/Screen*.png | tail -1)";
g=$(echo $f | tr ' ' _);
mv "$f" "$g";
echo $g
}
@tylerneylon
tylerneylon / whatisit.py
Created March 26, 2017 00:54
20 shortish lines that do something fun.
import itertools, os, sys
it, chars = 20, '.-=*x#X'
sys.stdout.write('\x1b[?25l')
w = int(os.popen('tput cols').read())
h = int(os.popen('tput lines').read()) - 1
x_max, y_max = float(w) / (2.0 * h) * 1.2, 1.2
for j in itertools.count(1):
sys.stdout.write('\x1b[1;1H')
@tylerneylon
tylerneylon / bye_camels.py
Created September 19, 2014 23:03
Convert camel case to underscores.
#!/usr/local/bin/python3
#
# bye_camels.py from https://github.com/tylerneylon/cstructs
#
"""
Usage:
bye_camels.py <input_file> [<output_file>]
bye_camels.py -i <input_file> <output_file>
Replaces all camel-case identifiers in the input with
@tylerneylon
tylerneylon / lua_interp.c
Last active September 4, 2017 03:17
A bare-bones Lua interpreter, in C.
// A bare-bones Lua interpreter, in C.
#include <stdio.h>
#include <string.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
int main() {
@tylerneylon
tylerneylon / keylog.c
Created July 2, 2015 21:59
log keyboard input to any shell command
// keylog.c
//
// Usage:
// ./keylog [command ...]
//
// This runs the given command, capturing all keyboard input in the file
// "outfile." This is currently written for mac os x. I'm guessing slight edits
// would allow it to work on other *nix systems as well.
//
// I learned how to do this by looking at the source of the "script" binary,
@tylerneylon
tylerneylon / cow.c
Created September 4, 2017 01:58
An example Lua module written in C.
// A Lua module written in C.
//
// This module enables terminal-based ASCII art
// of a loquacious bovine nature.
//
#include <stdio.h>
#include <stdlib.h>
#include "lua.h"