Skip to content

Instantly share code, notes, and snippets.

View ggcrunchy's full-sized avatar

Steven Johnson ggcrunchy

View GitHub Profile
@ggcrunchy
ggcrunchy / main.lua
Created January 24, 2020 18:11
Integer division using "bitwise ops", long division approach instead of iterated subtraction
-- Tested on repl.it
local N = 8 -- or 16, etc. Could also adapt for fixed point
local lshift = math.ldexp
local HighBitMask = lshift(1, N - 1)
local function Div (a, b)
local acc, result = 0, 0
local mask = HighBitMask -- one-hot mask
@ggcrunchy
ggcrunchy / main.lua
Created December 19, 2017 02:06
Little LOC counter
local lfs = require("lfs")
local N, NFiles, NSpaces = 0, 0, 0
local doc_path = system.pathForFile( "", system.ResourceDirectory )
local function About (name, file, indent)
print(indent, file)
local n, nspaces = 0, 0
for line in io.lines(name) do
@ggcrunchy
ggcrunchy / cachestack.lua
Last active June 11, 2017 02:55
A mechanism for caching temporary objects
--- Implements a system for deterministic recycling of objects, via an underlying cache.
--
-- When an object is created, or fetched from the cache, it may be registered with this
-- system. At a given point in execution, the system will then claim the object and add it to
-- the cache. The system is primarily intended for more intense parts of a program and must
-- be activated explicitly, being idle otherwise. When not running, registration is a no-op,
-- though the cache remains available for fetching.
--
-- An instance of this system is created via the @{NewCacheStack} function. (Typical programs
-- will only need one instance, but this is not required, e.g. various subsystems could each
@ggcrunchy
ggcrunchy / msvcbuild.bat
Created September 9, 2016 17:03
Batchfile to build luaffifb on Windows (with VS2013)
if not defined DevEnvDir (
call "%VS120COMNTOOLS%vsvars32.bat"
)
@if not defined INCLUDE goto :FAIL
@setlocal
@if "%1"=="debug-5.1" goto :DEBUG_5_1
@ggcrunchy
ggcrunchy / main.lua
Created August 1, 2016 19:09
A little complex number test
local CX, CY = display.contentCenterX, display.contentCenterY
local N = 15
local R = 50
local cosa, sina = R, 0 -- can be R, 0 if you have a fixed radius; otherwise, you will scale these
-- intermediate steps
local cosda, sinda = math.cos(2 * math.pi / N), math.sin(2 * math.pi / N)
@ggcrunchy
ggcrunchy / ByteReader.cpp
Last active July 18, 2016 03:54
An attempt at a nice byte-reading interface, for Lua-C/C++ interop in various projects
/*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
@ggcrunchy
ggcrunchy / Image1.jpg
Last active June 7, 2016 21:51
Meshes, regions
Image1.jpg
@ggcrunchy
ggcrunchy / Image1.jpg
Last active June 7, 2016 21:52
Meshes, degenerate polygons
Image1.jpg
@ggcrunchy
ggcrunchy / Image1.jpg
Last active March 11, 2018 13:02
Mesh-based cloth
Image1.jpg
@ggcrunchy
ggcrunchy / Image1.jpg
Last active June 3, 2016 22:53
Mesh curve, 3d-ish
Image1.jpg