Skip to content

Instantly share code, notes, and snippets.

View MikuAuahDark's full-sized avatar

Miku AuahDark MikuAuahDark

View GitHub Profile
@MikuAuahDark
MikuAuahDark / crc16_ccitt.lua
Created January 9, 2018 12:33
CRC-16 CCITT in LuaJIT
-- Converted from https://gist.github.com/chitchcock/5112270
-- Requires LuaBitOp or LuaJIT (since LuaJIT comes with LuaBitOp)
local bit = require("bit")
local crcTable = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5,
0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b,
0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210,
0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c,
@MikuAuahDark
MikuAuahDark / crc16_ccitt.c
Created April 2, 2018 11:55
Another CRC16, but in C
/* CRC16-CCITT */
#include <stdlib.h>
const unsigned short crcTable[] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5,
0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b,
0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210,
0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c,
0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401,
@MikuAuahDark
MikuAuahDark / makevis.lua
Created April 26, 2018 14:19
Rainmeter Circle Visualizer
-- Visualizer builder script
-- Copyright (c) 2018 MikuAuahDark
--
-- This software is provided 'as-is', without any express or implied
-- warranty. In no event will the authors be held liable for any damages
-- arising from the use of this software.
--
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely, subject to the following restrictions:
@MikuAuahDark
MikuAuahDark / clHCA.def
Created June 13, 2018 15:18
deHCA: LuaJIT FFI Binding to vgmstream's clHCA to play HCA audio in LOVE
; If you're using MSVC, use this DEF file or deHCA will complain
; about a nil value. Example command to build clHCA in Windows:
; > cl.exe /c /Ox /Ot /GL /arch:SSE2 /MD clHCA.c
; > link.exe /DLL /LTCG /DEF:clHCA.def /OUT:clHCA.dll clHCA.obj
; Then copy clHCA.dll to LOVE directory.
; The library name must be "clHCA" (clHCA.dll/libclHCA.so/libclHCA.dylib)
EXPORTS
clHCA_isOurFile0
clHCA_isOurFile1
clHCA_sizeof
@MikuAuahDark
MikuAuahDark / fragment.glsl
Last active June 29, 2018 06:30
LOVE 11.0 default shader (OpenGLES 3.x)
#version 300 es
#define PIXEL PIXEL
#if !defined(GL_ES) && __VERSION__ < 140
#define lowp
#define mediump
#define highp
#endif
#if defined(VERTEX) || __VERSION__ > 100 || defined(GL_FRAGMENT_PRECISION_HIGH)
@MikuAuahDark
MikuAuahDark / conf.lua
Created July 10, 2018 16:18
Play grayscale image as audio (really?)
--[[
Some notice:
1. This code is compatible with LOVE 0.10.0, and LOVE 11.0 (probably later version too)
2. Audio must have sample rate of 28224Hz
3. Audio is encoded to 8bit PCM (128 denotes 0) then converted to PNG
]]
local ffi = require("ffi")
function love.conf(t)
t.window = nil
@MikuAuahDark
MikuAuahDark / Makefile
Created November 22, 2018 10:17
Simple makefile to zopflipng images from `old/` to`.`
SRC_FILES := $(wildcard old/*.png)
DST_FILES := $(patsubst old/%.png,%.png,$(SRC_FILES))
all: $(DST_FILES)
%.png: old/%.png
zopflipng $< --lossy_transparent --filters=01234mepb --iterations=10 $@
@MikuAuahDark
MikuAuahDark / .lua
Created December 17, 2018 12:07
32-bit unsigned integer multiplication in Lua
function dwordMultiply(a, b)
a = a % 4294967296
b = b % 4294967296
local ah, al = math.floor(a / 65536), a % 65536
local bh, bl = math.floor(b / 65536), b % 65536
local high = ((ah * bl) + (al * bh)) % 65536
return ((high * 65536) + (al * bl)) % 4294967296
end
@MikuAuahDark
MikuAuahDark / main.c
Last active October 13, 2019 15:46
Lazy HCA2WAV using clHCA
/* HCA2WAV */
/* This is one shot tool, error handling is lazy, */
/* memory may not be freed. Any efforts fixing this */
/* is useless */
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#endif
@MikuAuahDark
MikuAuahDark / transform_hack.lua
Created May 3, 2019 16:31
Extend functionality of LOVE 11.0 Transform object
-- Script that monkeypatch LOVE Transform
-- to add 3D support
local love = require("love")
local t = love.math.newTransform()
local t2 = love.math.newTransform()
local transformMt = getmetatable(t)
local function applyDump(ts, ...)
t2:reset()
t2:apply(ts)