Skip to content

Instantly share code, notes, and snippets.

View MCJack123's full-sized avatar
๐Ÿ’š
Go Green!

JackMacWindows MCJack123

๐Ÿ’š
Go Green!
View GitHub Profile
@MCJack123
MCJack123 / loadHeader.lua
Created June 11, 2020 02:28
C preprocessor in Lua
local function split(str, sep)
local retval = {}
for m in str:gmatch("([^" .. sep .. "]+)") do table.insert(retval, m) end
return retval
end
local function dirname(str)
if str:match(".-/.-") then return string.gsub(str, "^(.*)/.*$", "%1")
else return "" end
end
@MCJack123
MCJack123 / randomchar.lua
Created July 7, 2020 23:41
CraftOS-PC rendering stress tests for character & graphics modes
local w, h = term.getSize()
local canBenchmark = term.benchmark ~= nil
local count = 0
local start = os.epoch "utc"
if canBenchmark then term.benchmark() end
pcall(function()
while true do
term.setCursorPos(math.random(1, w), math.random(1, h))
term.setBackgroundColor(2^math.random(0, 15))
term.setTextColor(2^math.random(0, 15))
@MCJack123
MCJack123 / coroutine.c
Created July 11, 2020 07:42
Unsafe, untrustworthy coroutine implementation in C (x64, GCC only, tested on Windows)
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#include <errno.h>
struct coroutine {
int status;
void* (*fn)(void*);
void* arg;
jmp_buf env_resume;
@MCJack123
MCJack123 / fsencrypt.lua
Last active November 27, 2022 07:22
Filesystem encryption program for ComputerCraft
if fs.isUnlocked then
local args = {...}
if args[1] == "lock" or (args[1] == nil and fs.isUnlocked()) then
fs.lock()
print("The filesystem is now locked.")
elseif args[1] == "unlock" or args[1] == nil then
fs.unlock()
print("The filesystem is now unlocked.")
elseif args[1] == "encrypt" then
if args[3] == nil then error("Usage: fsencrypt encrypt <infile> <outfile>") end
@MCJack123
MCJack123 / BenchmarkRenderers.lua
Last active September 11, 2024 16:35
Renderer benchmark program for CraftOS-PC v2.4 (`gist run 802f64508a1f51b3244f5bcc0414ca22`)
if config == nil then error("This must be run in CraftOS-PC v2.4 or later.") end
local function runTests()
local oldClockSpeed = config.get("clockSpeed")
config.set("clockSpeed", 1000)
-- Test characters
term.redirect(term.native())
local benchmark = debug.getregistry().benchmark
local w, h = term.getSize()
local canBenchmark = benchmark ~= nil
@MCJack123
MCJack123 / yahtcc.lua
Last active September 11, 2020 05:31
YahtCC: A Yahtzee clone for ComputerCraft
-- YahtCC by JackMacWindows
-- GPL license
local diceMaps = {
[0] = {0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0},
{0x20, 0x10, 0x95, 0x8f, 0x8f, 0x85},
{0x08, 0x20, 0x95, 0x8f, 0x8d, 0x85},
{0x08, 0x10, 0x95, 0x8f, 0x8d, 0x85},
{0x08, 0x08, 0x95, 0x8d, 0x8d, 0x85},
{0x08, 0x18, 0x95, 0x8d, 0x8d, 0x85},
@MCJack123
MCJack123 / xmsquash.c
Last active January 1, 2021 01:50
Tool to remove extra instruments from XM modules (warning: changes instrument IDs!)
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <windows.h>
#include <io.h>
#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
@MCJack123
MCJack123 / subleq.lua
Last active September 11, 2024 16:36
Dawn emulation for CraftOS-PC Accelerated
local args = {...}
if args[1] == nil then error("Usage: subleq <dawn.bin>") end
if term.drawPixels == nil then error("This program requires CraftOS-PC v2.2 or later.") end
local ok, err = pcall(function()
if _G.dawn_chunks == nil then
local file = fs.open(args[1], "rb")
if file == nil then error("Could not open file at " .. args[1]) end
_G.dawn_chunks = {}
for i = 1, 640 do dawn_chunks[i] = file.read(1048576) end
@MCJack123
MCJack123 / yellowbox.lua
Last active September 5, 2024 17:15
YellowBox: Virtual machines for ComputerCraft
--- YellowBox 1.0
-- By JackMacWindows
--
-- @module yellowbox
--
-- This module allows you to easily create and manage special ComputerCraft
-- containers called "boxes". These boxes contain their own separate execution
-- environment, completely sequestered from the caller's environment. This allows
-- effective "virtual machines" running CraftOS.
--
@MCJack123
MCJack123 / fetch.lua
Last active August 2, 2022 23:53
Fetch work-alike for CC, implementing async HTTP requests
-- Made by JackMacWindows, licensed under CC0
local expect = require "cc.expect".expect
local activeRequests = {}
local kPromiseSuccess, kPromiseFailure = {}, {}
local openHandlers = 0
-- To use, call this function with each URL and optionally a table with options.
-- Then call it with no arguments to process the requests in the queue.