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 / typecheck.ts
Created April 6, 2023 05:10
TypeScriptToLua plugin to automatically add type checks to annotated functions
import * as ts from "typescript";
import * as tstl from "@jackmacwindows/typescript-to-lua";
const EXPECT_PLUGIN = "cc.expect";
const EXPECT_METHOD = "expect";
const EXPECT_FUNCTION = "___TS_Expect";
function fillTypeList(args: ts.Expression[], type: ts.TypeNode, context: tstl.TransformationContext): boolean {
if (ts.isUnionTypeNode(type)) {
for (let t of type.types) if (!fillTypeList(args, t, context)) return false;
@MCJack123
MCJack123 / sidplayer.lua
Created March 17, 2023 07:09
Commodore 64 SID player for ComputerCraft (requires some libraries)
local M6502 = require "M6502" -- https://gist.github.com/MCJack123/cf500b62fdbcb135d2db6cf97a771c6e
local SID = require "sid" -- https://gist.github.com/MCJack123/d076bfcab67767cef6fd0292655e03ae
term.clear()
term.setCursorPos(1, 1)
local win = window.create(term.current(), 38, 1, 14, 10)
win.clear()
local status = window.create(term.current(), 1, 1, 37, 19)
local oldterm = term.redirect(status)
local ok, err = pcall(function(...)
@MCJack123
MCJack123 / sapplayer.lua
Created March 17, 2023 07:08
Atari ST SAP player for CraftOS-PC sound plugin (requires https://gist.github.com/MCJack123/cf500b62fdbcb135d2db6cf97a771c6e)
local M6502 = require "M6502"
local nsongs = 1
local defaultsong = 0
local stereo = false
local ntsc = false
local type = 0 -- 0 = B, 1 = C, 2 = D, 3 = S, 4 = R
local fastplay = 312
local initaddr = 0x0000
local musicaddr = 0x0000
@MCJack123
MCJack123 / sid.lua
Created March 17, 2023 07:07
Pure Lua 5.2 port of reSID Commodore 64 SID emulator
-------------------------------------------------------------------------------
-- This file is reSID, a MOS6581 SID emulator engine, ported to Lua.
-- Copyright (C) 2004 Dag Lem <resid@nimrod.no>
-- Lua port Copyright (C) 2023 JackMacWindows <jackmacwindowslinux@gmail.com>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
@MCJack123
MCJack123 / M6502.lua
Created March 17, 2023 07:05
MOS 6502 emulator written in pure Lua
-- MIT License
--
-- Copyright (c) 2018-2022 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 / struct.lua
Last active January 13, 2023 04:23
Lua 5.3+ C struct parser library for declarative binary file serialization
-- 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
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
@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() {