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 / find.lua
Created December 9, 2022 07:37
Pure Lua implementation of CraftOS `fs.find`
-- Licensed as CC0
local expect = dofile "/rom/modules/main/cc/expect.lua"
local function splitPath(p)
local retval = {}
for m in p:gmatch("[^/]+") do table.insert(retval, m) end
return retval
end
local function aux_find(parts, p)
@MCJack123
MCJack123 / aoc2022.lua
Last active January 8, 2023 00:27
Advent of Code 2022 solutions (Run in CraftOS-PC w/CCEmuX plugin)
-- Usage: aoc2022 <day>-<1|2> [local]
-- Run `set aoc.session <session token>` before running
local aoc = {}
local function run(n, l)
local f = aoc[n]
local file
if l then file = fs.open("aoc.txt", "r")
else file = http.get("https://adventofcode.com/2022/day/" .. n:match("^%d+") .. "/input", {Cookie = "session=" .. settings.get("aoc.session")}) end
local start = os.epoch "utc"
local r = tostring(f(file))
@MCJack123
MCJack123 / donut.lua
Last active November 29, 2022 04:29
Donut (ComputerCraft edition)
local A,
B,z,b,S,C,F,r=
0,0,{},{},math.sin
,math.cos,math.floor,{
}for c in([[0123456789ab
]]):gmatch"%S"do r[#r+1]=c
end term.clear()for i=0,11--
do term.setPaletteColor(2^i,i/
11,i/18,i/21)end while""do for
n=0,1759 do b[n], z[n]=" ",0 end
@MCJack123
MCJack123 / gh-lang-count.mjs
Last active September 26, 2022 19:07
Script to calculate total language size stats for a user, including Gists
// Usage: node gh-lang-count.mjs <user> [PAK]
import * as process from 'process';
if (!global.fetch) throw new Error("This requires NodeJS 17.5.0 or later.");
if (process.argv.length < 3) throw new Error("Usage: gh-lang-count <user> [PAK]");
const username = process.argv[2];
let key = undefined;
if (process.argv.length > 3) key = "token " + process.argv[3];
async function main() {
@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