Skip to content

Instantly share code, notes, and snippets.

View keharriso's full-sized avatar

Kevin Harrison keharriso

  • 04:13 (UTC -04:00)
View GitHub Profile
@keharriso
keharriso / Connection.lua
Created December 26, 2018 21:08
Abstraction that unifies LÖVE channels and TCP luasockets
local json = require "dkjson"
local len = string.len
local insert = table.insert
local remove = table.remove
local concat = table.concat
local stringify = json.encode
local parse = json.decode
local compress = love.data.compress
local decompress = love.data.decompress
@keharriso
keharriso / love-moonscript.lua
Created November 29, 2016 22:42
Package loader for love.filesystem moon scripts.
local moonscript = require "moonscript"
-- Add package loader for love.filesystem moon scripts.
table.insert(package.loaders, 2, function (name)
local name_path = name:gsub("%.", "/")
local file_path, text
for path in love.filesystem.getRequirePath():gsub("%.lua", ".moon"):gmatch("[^;]+") do
file_path = path:gsub("?", name_path)
text = love.filesystem.read(file_path)
if text then
@keharriso
keharriso / FindZIP.cmake
Created November 19, 2016 21:57
CMake module for packing and unpacking ZIP files
# FindZIP.cmake - Pack and unpack ZIP files as custom targets
# ------------------------------------------------------------------------------
# Provides:
#
# ZIP_PACK_TARGET TARGET WORKING_DIRECTORY ARCHIVE FILES...
# TARGET - The name of the custom target
# WORKING_DIRECTORY - The working directory for the zip command
# ARCHIVE - The full archive path
# FILES... - The files and directories to include in the archive
# (relative to WORKING_DIRECTORY)
@keharriso
keharriso / FindMoonscript.cmake
Created November 19, 2016 21:56
CMake module for compiling Moonscript code
# FindMoonscript.cmake - Compile Moonscript as a custom target
# ------------------------------------------------------------------------------
# Provides:
#
# MOONSCRIPT_COMPILE_TARGET TARGET WORKING_DIRECTORY OUT_DIR FILES...
# TARGET - The name of the custom target
# WORKING_DIRECTORY - The working directory for the moonc command
# OUT_DIR - The directory to store compiled .lua files
# FILES... - The .moon files to compile (relative to WORKING_DIRECTORY)
#
@keharriso
keharriso / FindLuamin.cmake
Created November 19, 2016 21:56
CMake module for minifying Lua code
# FindLuamin.cmake - Minify Lua code as a custom target
# ------------------------------------------------------------------------------
# Provides:
#
# LUAMIN_MINIFY_TARGET TARGET WORKING_DIRECTORY OUT_DIR FILES...
# TARGET - The name of the custom target
# WORKING_DIRECTORY - The working directory for the luamin command
# OUT_DIR - The directory to store minified .lua files
# FILES... - The .lua files to minify (relative to WORKING_DIRECTORY)
#
#include <stdio.h>
#include <curl/curl.h>
/* ===== HELPER FUNCTIONS ================================================= */
static size_t writeToFile(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream);