Skip to content

Instantly share code, notes, and snippets.

View ChaunceyHoover's full-sized avatar

Chauncey Hoover ChaunceyHoover

View GitHub Profile
@ChaunceyHoover
ChaunceyHoover / Case Insensitive Pattern Generator.lua
Created August 8, 2019 12:58
A simple pattern/filter generator. Could be useful for a blacklist of words or something, probably.
function case_insensitive_pattern(pattern)
local p = pattern:gsub("(%%?)(.)", function(percent, letter) -- match regex
if percent ~= "" or not letter:match("%a") then
-- if % is matched or 'letter' is not a letter
return percent .. letter
else
return string.format("[%s%s]", letter:upper(), letter:lower())
end
end)
return p
@ChaunceyHoover
ChaunceyHoover / String Generator.lua
Created August 8, 2019 12:56
Simple lua string generator
function rand_str(len)
len = tonumber(len) or 1
local function rand_char()
return math.random() > 0.5
and string.char(math.random(65, 90))
or string.char(math.random(97, 122))
end
local function rand_num()
return string.char(math.random(48, 57))
@ChaunceyHoover
ChaunceyHoover / String separator.lua
Last active August 8, 2019 12:56
Simple separator/explode function for Lua
function explode(input, separator)
if input:len() == 0 then return {} end
if input:len() == 1 then return { input } end
separator = type(separator) == "string" and separator:sub(1, 1) or tostring(separator)
local results = {}
local lastPos = 1 -- Note: in Lua, '1' is the start of everything, including strings
for i = 1, input:len() do -- or: for i = 1, string.len(input) do
if string.sub(input, i, i) == separator then -- or: if input:sub(i, i) == separator then
@ChaunceyHoover
ChaunceyHoover / meme-speak.ahk
Created July 17, 2018 00:35
Meme-Speak™ - rEPeaTEdLy turNs caPS LOCK oN and ofF sO yoU Can SPeAK LiKE ReaL memERs
; Meme-Speak™ - rEPeaTEdLy turNs caPS LOCK oN and ofF sO yoU Can SPeAK LiKE ReaL memERs
Repeat = False
; Turns meme-speak on
F1::
Repeat := True
while (Repeat) {
SetCapsLockState, on
Sleep, 10
SetCapsLockState, off
import time
import colorsys
import RPi.GPIO as GPIO
import Adafruit_WS2801
import Adafruit_GPIO.SPI as SPI
PIXEL_COUNT = 160
BRIGHTNESS = 0.05
@ChaunceyHoover
ChaunceyHoover / sleep.lua
Last active January 26, 2023 16:17
Lua asynchronous and synchronous sleeping
function sleep(time, func, ...)
local now = os.time()
local thread = coroutine.create(func)
repeat until (os.time() - now > time)
coroutine.resume(thread, ...)
end
function asleep(time, func, ...)
coroutine.wrap(function()
local now = os.time()
@ChaunceyHoover
ChaunceyHoover / frequencies.h
Last active October 2, 2022 17:36
A simple note-to-frequency header file, aimed for those who like to play with Window.h's `Beep` function. Also includes a Note-to-Millisecond macro for those aiming to make some moonbase-alpha tier music.
#ifndef HEADER_FREQUENCY_H
#define HEADER_FREQUENCY_H
// Taken from http://www.phy.mtu.edu/~suits/notefreqs.html
// Rounded to nearest number
// Format: <note><octave>(sharp/flat)
// Ex: C5S = C# note in 5th octave
#define C0 16
#define C0S 17
#define D0F C0S