Skip to content

Instantly share code, notes, and snippets.

@MineRobber9000
MineRobber9000 / mdfpwm.py
Created March 4, 2024 06:51
MDFPWM converter in Python. Assumes you have up-to-date ffmpeg in PATH.
# MDFPWM encoder
# Uses ffmpeg to encode a WAV file as dfpwm
# Assumes ffmpeg is on PATH
# CC0, whatever
# credit Drucifer@SwitchCraft.kst for the format
import subprocess, tempfile, os, os.path, struct, json
def I(n):
return struct.pack("<I",n)
@MineRobber9000
MineRobber9000 / base64.ms
Created February 25, 2024 19:16
base64 encode/decode in MiniScript (Mini Micro exclusive)
// base64 in MiniScript
// by minerobber
// Mini Micro-exclusive (uses RawData)
// use base64.encode/decode for standard base64
// also supports variants (use .encode/decode on variants):
// - standard (A-Za-z0-9+/; base64.standard)
// - URL (A-Za-z0-9-_; base64.url)
// - B64 (crypt/GEDCOM; ./0-9A-Za-z; base64.b64/crypt/gedcom)
// - bcrypt (./A-Za-z0-9; base64.bcrypt)
// - bash base64 literals (0-9A-Za-z@_; base64.bash)
@MineRobber9000
MineRobber9000 / donotuse3.py
Last active February 8, 2024 12:48
How to NEVER use lambdas - Python 3 edition
###########################################################
# How to NEVER use lambdas. An inneficient and yet educa- #
# tonal [sic] guide to the proper misuse of the lambda #
# construct in Python 3.x. [DO NOT USE ANY OF THIS EVER] #
# original by (and apologies to): e000 (13/6/11) #
# now in Python 3 courtesy of: khuxkm (17/9/20) #
###########################################################
## Part 1. Basic LAMBDA Introduction ##
# If you're reading this, you've probably already read e000's
@MineRobber9000
MineRobber9000 / broadcast_with_metadata.liq
Created July 26, 2020 03:23
Broadcast from liquidsoap with custom metadata
#!/usr/bin/liquidsoap
set("log.file", false)
# Allow a UNIX domain socket server. (You can make a telnet server, but the UNIX domain socket is easier for me to grok.)
set("server.socket",true)
set("server.socket.path","/home/khuxkm/RadioMineRobber/socket")
# This is your input source. In this example, it's just the tracks from `tracks.pls`, but it could be soundcard input or line-in
pl = mksafe(playlist("tracks.pls"))
@MineRobber9000
MineRobber9000 / basic.lua
Last active August 11, 2023 02:09
Dartmouth BASIC interpreter
local functions = {}
for v in ("ABS ATN COS EXP INT LOG RND SIN SQR TAN "):gmatch("(.-) ") do
functions[v]=true
end
for c in ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"):gmatch("(.)") do
functions["FN"..c]=true
end
local statements = {}
for v in ("LET PRINT END READ DATA GOTO IF FOR NEXT GOSUB RETURN DEF DIM REM STOP INPUT "):gmatch("(.-) ") do
statements[v]=true
@MineRobber9000
MineRobber9000 / switchcase.lua
Created July 22, 2023 04:59
syntax sugary switch case in lua
local _nil = setmetatable({},{__newindex=function() end}) -- sentinel
local function switch(val)
if val==nil then val=_nil end
return function(cases)
return (cases[val] or cases.default or function() end)()
end
end
return setmetatable({["_nil"]=_nil,switch=switch},{__call=function(t,...) return switch(...) end})
@MineRobber9000
MineRobber9000 / tic80gfx.py
Created June 24, 2023 02:36
TIC-80 graphics converter. Requires pillow.
"""TIC-80 graphics converter. Requires pillow.
usage: tic80gfx.py [-b BACKGROUND_COLOR] [-c COMMENT] [-p PALETTE] image index output
positional arguments:
image The image to convert.
index The index number for the top-left sprite.
output Where the converted image data will be saved.
options:
@MineRobber9000
MineRobber9000 / README.md
Created December 10, 2022 07:47
multiMon

multiMon

An update of the original by Shazz. Adds all term functions that have been added since 2014, and changes the architecture a bit.

To use

Unfortunately, due to the nature of this library, you still need to use os.loadAPI to use it (yuck, I know).

os.loadAPI("multiMon")
@MineRobber9000
MineRobber9000 / README.md
Created July 7, 2020 03:29
Import Python modules from GitHub

githubimport

Allows you to import Python modules from the top level of a GitHub repository. Basically, golang's import semantics but in Python fashion.

>>> import githubimport
>>> from MineRobber9000.test_modules import blah
>>> blah.foo()
"bar"
@MineRobber9000
MineRobber9000 / README.md
Created March 4, 2020 00:54
TOTP and HOTP implemented in Python

totp.py

A simple library. Despite its name, it does TOTP and HOTP. To do a TOTP:

import totp, base64

secret = base64.b32decode("ABCDEFGHIJKLMNOP")
code = totp.totp(secret)
if code==input("Insert TOTP here:").strip(): print("Success")