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 / yahtcc-phoenix.lua
Created September 3, 2022 23:52
YahtCC port for Phoenix
-- YahtCC by JackMacWindows (Phoenix version)
-- GPL license
local util = require "system.util"
local keys = require "system.keys"
local terminal = require "system.terminal"
local hardware = require "system.hardware"
local term, termerr = terminal.openterm()
if not term then error("Could not open terminal: " .. termerr) end
@MCJack123
MCJack123 / sane-api.md
Created June 6, 2022 04:13
On Writing a Sane API

On Writing a Sane API

Over my years on the ComputerCraft Discord server, I've had the opportunity to witness the creation of numerous APIs/libraries of all sorts. I've gotten to examine these APIs in depth, as well as answer questions involving the APIs that the creators or users have. As an API designer myself, I compare the designs of other APIs with my designs, and I've noticed a number of patterns that make or break an API design. I've seen plenty of designs that make me go "WTF???", and lots that I just can't understand, even at my advanced level of programming (not to toot my own horn).

This article outlines some rules for making a sane API, which is easy to use, understandable, and doesn't make the user spin in circles to make things with it. Note that when I use the term "API", I'm primarily referring to code libraries and their public interfaces, but a number of points can be applied to web APIs as well. Since I have the most experience in Lua APIs, I'll be focu

@MCJack123
MCJack123 / config-ui.lua
Created April 8, 2022 00:32
TUI configuration utility for CraftOS-PC (requires Tamperer: https://github.com/Fatboychummy-CC/Tamperer)
local tamperer = require "tamperer"
settings.save(".settings")
settings.clear()
local cfg = {
name = "Configuration",
info = "Configure CraftOS-PC's behavior",
bigInfo = "",
colors = {
bg = {
main = "black",
@MCJack123
MCJack123 / DFPWM-WAV-format.md
Last active January 30, 2024 18:21
Specification for DFPWM stored in WAV files

WAV format for DFPWM data

This document describes how to store DFPWM data in a WAV file.

Overview

DFPWM data is specified through the WAVE_FORMAT_EXTENDED data type, with the UUID 3ac1fa38-811d-4361-a40d-ce53ca607cd1. Channels are stored interleaved, and samples are packed in groups of 8 per byte, as is consistent with raw DFPWM data. Only DFPWM1a data is considered here - original DFPWM should not be stored using this UUID.

fmt  chunk

The fmt  chunk follows the standard layout for WAVE_FORMAT_EXTENDED, using the assigned DFPWM UUID:

| Offset | Bytes | Description |

@MCJack123
MCJack123 / micserver.cpp
Created February 27, 2022 00:32
Microphone to WebSocket loopback server (requires Poco and PortAudio)
/*
* Microphone to WebSocket loopback server
* Requires Poco and PortAudio
* Compile with g++ -o micserver micserver.cpp -lPocoFoundation -lPocoNet -lPocoUtil -lportaudio
*
* MIT License
*
* Copyright (c) 2022 JackMacWindows
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@MCJack123
MCJack123 / aoc2021.lua
Last active December 2, 2022 05:42
JackMacWindows's Advent of Code 2021 programs
-- 3-1
local file = fs.open("aoc.txt", "r")
local count = {{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, }
repeat
local l = file.readLine()
if not l then break end
l:gsub("()([01])", function(pos, num) count[pos][tonumber(num)+1] = count[pos][tonumber(num)+1] + 1 end)
until not l
@MCJack123
MCJack123 / aukit.lua
Last active January 27, 2022 01:08
AUKit: Audio decoding and processing framework for ComputerCraft
--- AUKit: Audio decoding and processing framework for ComputerCraft
--
-- AUKit is a framework designed to simplify the process of loading, modifying,
-- and playing audio files in various formats. It includes support for loading
-- audio from many sources, including PCM, DFPWM, and IMA ADPCM codecs, as well
-- as WAV, AIFF, AU, and FLAC files. It can also generate audio on-the-fly as
-- tones, noise, or silence.
--
-- AUKit uses a structure called Audio to store information about each audio
-- chunk. An audio object holds the sample rate of the audio, as well as the
@MCJack123
MCJack123 / imgquant.lua
Last active November 7, 2022 20:35
Basic image quantization library for ComputerCraft
-- MIT License
--
-- Copyright (c) 2021 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:
@MCJack123
MCJack123 / string_pack.lua
Last active August 26, 2023 13:28
Backport of string.pack for Lua 5.2 [WIP]
-- MIT License
--
-- Copyright (c) 2021 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:
@MCJack123
MCJack123 / jscc.mm
Created July 20, 2021 03:37
JavaScriptCore integration for CraftOS-PC (bad code)
#import <JavaScriptCore/JavaScriptCore.h>
#include <CraftOS-PC.hpp>
#include <math.h>
#include <float.h>
#include <stdarg.h>
static JSContext * ctx;
static JSValue * Function;
static int jsc_call(lua_State *L);