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 / taskmaster.lua
Last active April 23, 2024 21:44
Taskmaster: A simple and highly flexible task runner/coroutine manager for ComputerCraft
-- Taskmaster: A simple and highly flexible task runner/coroutine manager for ComputerCraft
-- Supports adding/removing tasks, early exits for tasks, event white/blacklists, automatic
-- terminal redirection, task pausing, promises, and more.
-- Made by JackMacWindows
-- Licensed under CC0 in the public domain
--[[
Examples:
- Run three functions in parallel, and wait for any to exit.
@MCJack123
MCJack123 / css-discord.cpp
Last active January 24, 2024 21:52
Counter-Strike Source Discord RPC program (probably VAC safe, Linux only)
#include <discord.h>
#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
#include <thread>
#include <chrono>
namespace fs = std::filesystem;
@MCJack123
MCJack123 / toml.lua
Created January 23, 2024 00:29
TOML parser for CC Lua
-- TOML library for Lua/CC
-- From Phoenix libsystem serialization.toml
--
-- MIT License
--
-- Copyright (c) 2024 JackMacWindows
--
-- 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
@MCJack123
MCJack123 / mmfs.c
Created December 29, 2023 04:33
Memory-Mapped Filesystem for ESP32: A performance-oriented filesystem driver designed for read-only partitions.
/**
* Memory-Mapped Filesystem for ESP32
* A performance-oriented filesystem driver designed for read-only partitions.
*
* Copyright (c) 2024 JackMacWindows. Licensed under the Apache 2.0 license.
*/
#include <errno.h>
#include <fcntl.h>
#include <esp_partition.h>
@MCJack123
MCJack123 / bfcompile.lua
Created October 30, 2023 00:34
AOT Brainfuck compiler to bytecode for Lua 5.1
--[[
registers: 0 = data table, 1 = data pointer, 2 = function temp, 3 = current data (4 total)
expects `get(): number` and `put(n: number)` global functions
init code
GETGLOBAL R(0), K("setmetatable")
NEWTABLE R(1), 0, 0
NEWTABLE R(2), 0, 1
CLOSURE R(3), KP(0)
SETTABLE R(2), K("__index"), R(3)
@MCJack123
MCJack123 / deflate-ans.lua
Last active September 24, 2023 10:04
A variant of DEFLATE using tabled asymmetrical numeral systems
-- DEFLATE-ANS: A variant of DEFLATE that uses asymmetrical numeral systems
-- instead of Huffman coding, increasing decompression speed with similar
-- compression ratios.
--
-- The block format matches RFC 1951 DEFLATE, with some minor adjustments:
-- * Bit fields are always stored most significant bit first, and bytes are
-- stored most significant byte first. This is for convenience in the bit
-- decoder.
-- * Huffman-encoded blocks are replaced with tANS-encoded blocks. These blocks
-- start with an initial X value (which is R bits long), followed by the codes
@MCJack123
MCJack123 / !SwiftCoroutines.md
Last active August 19, 2023 09:26
Lua-style coroutine objects in Swift 5.5+, using Swift Concurrency

Implementing coroutines in Swift using Swift Concurrency

One of my favorite features of Lua is its first-class support for coroutines. Recently, I started writing a new project using Swift, and I wanted to be able to use coroutines natively in my Swift code. In most Lua VMs, coroutines are a complex feature that require a lot of environmental support to be able to save and restore function calls. However, Swift includes the async and await keywords for pausing functions built into the language. Because of this, I decided to take a crack at using them to implement coroutines natively.

What are coroutines?

A coroutine is an object that represents a function which can be paused and resumed. This function may pause (or yield) itself at any time, which will return execution to the code that last resumed the coroutine. The coroutine can then be resumed later, and the code will pick up right where it left off.

A coroutine also represents a call stack, or a thread of execution. T

@MCJack123
MCJack123 / client.lua
Last active August 18, 2023 22:18
PIN-based door lock system for ComputerCraft, using a monitor for PIN entry
-- Save this as startup.lua on each client computer with a 1x1 monitor and modem attached. You can also optionally attach a speaker for audio feedback.
local secret = "" -- Set this to the same secret that was set in the server file.
local redstoneSide = "left" -- Set this to the side the redstone signal should be output on.
local openTime = 5 -- Set this to the number of seconds to keep the door open for.
local defaultOutput = false -- Set this to the default redstone state for the door. If set to true, this means power will be cut when unlocking.
-- This allows you to place a door sideways, and then have it stay closed even when power is applied externally.\
local accessLevel = 0 -- Set this to the minimum access level required by a PIN.
if not secret or secret == "" then error("Please set some keys inside the script before running.") end
@MCJack123
MCJack123 / ans.lua
Last active August 6, 2023 13:48
Tabled Asymmetrical Numeral Systems (aka Finite State Entropy) for Lua 5.2 (PoC)
-- Tabled Asymmetrical Numeral Systems (aka Finite State Entropy) for Lua 5.2
--
-- MIT License
--
-- Copyright (c) 2023 JackMacWindows
--
-- 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
@MCJack123
MCJack123 / format.lua
Created June 22, 2023 15:14
Quick & dirty Lua formatter written in Lua
-- MIT License
--
-- Copyright (c) 2022-2023 JackMacWindows
--
-- 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: