Skip to content

Instantly share code, notes, and snippets.

View Artoria2e5's full-sized avatar
🌪️
not focusing!

Mingye Wang Artoria2e5

🌪️
not focusing!
View GitHub Profile
@Artoria2e5
Artoria2e5 / chroma.ts
Last active November 6, 2024 13:52
Maximize chroma in Oklch without changing L and h
// This is just https://bottosson.github.io/posts/gamutclipping/ crudely translated to TS
type Lab = { L: number; a: number; b: number };
type RGB = { r: number; g: number; b: number };
type sRGB = { r: number; g: number; b: number };
function linear_srgb_to_oklab(c: RGB): Lab {
const l = 0.4122214708 * c.r + 0.5363325363 * c.g + 0.0514459929 * c.b;
const m = 0.2119034982 * c.r + 0.6806995451 * c.g + 0.1073969566 * c.b;
const s = 0.0883024619 * c.r + 0.2817188376 * c.g + 0.6299787005 * c.b;
@Artoria2e5
Artoria2e5 / 00_README.md
Last active May 24, 2023 14:35
Want a C version of bits/stdc++.h? Now you have it.

bits/stdc.h

People worry about the lack of an everything include file for stdc like libstdc++ had for C++. Worry no more! Now you can also mindlessly use one pch for C!

Honestly, just std C headers is no where near big (and slow) enough to make people want to use pch. At least we should drag POSIX in.

LOICENSE

This stuff is GPL 3+ with the GCC Runtime Library Exception 3.1. What does it mean?

@Artoria2e5
Artoria2e5 / 00_main.md
Last active September 5, 2023 05:05
can we backport librsvg to buster?

Environment

I took a WSL1 environment containing Bullseye and performed a downgrade to Buster per https://wiki.debian.org/SystemDowngrade. Apt isn't complaining at all, so it's probably a good enough buster.

Dependencies

apt install librsvg2-dev build-essential fakeroot devscripts
apt build-dep librsvg2-dev
@Artoria2e5
Artoria2e5 / fish.sh
Created March 15, 2023 17:42
Make fishingbot turn. Lol.
#!/bin/bash
# companion script to fishingbot -- automatically turn
# Use the MiniHUD mod to get the yaw and pitch values
# Yaw wraps around at -180
YAW_MIN=135
YAW_MAX=-135
YAW_STEP=5
PITCH_MIN=-1
@Artoria2e5
Artoria2e5 / viks.md
Last active March 2, 2023 13:50
Victoria 3 savefile format
  • Files always start with AD 55 01 00 03 00
  • Strings are coded as length (uint16 LE), followed by bytes
  • 0F 00 is... something
  • meta is just the head portion of gamestate (country name, country flag, mods, game flags/rules)
@Artoria2e5
Artoria2e5 / README.md
Created May 19, 2021 02:48
glob(3) for winpaths

Instead of writing stuff I decided to chicken out and talk.

Anyways, Windows paths use \ as the path separator. You might see it as horrible (it is), but for globbing it is actually fine since ? and * are disallowed in filenames. You will still need to escape [ and the extglob (, but recall that | is disallowed too so you can just use that as the escape character.

You may or may not need to have a compile step to convert this glob into actual glob(7). For that you just replace all instances of \ with /, and all

@Artoria2e5
Artoria2e5 / cursed_wav.py
Last active May 4, 2021 08:34
Pretend that your 32-bit floating-point WAV is 32-bit integer
#!/usr/bin/env python3
"""
This cursed piece of shit lets you pretend your 32-bit floating-point
WAV is actually 32-bit integer, so FLAC may take it. Now the only encoder
that does 32-bit integer is some SVN build of FLAKE I have no intention
of compiling, so I can't test how badly it compresses.
What I can tell you is that WavPack hates it. It compressess down to about
84% of the original, which is worse than 7-zip. On the other hand the original
f32 version goes down to 58%. The test file is decoded from Open Goldberg,
@Artoria2e5
Artoria2e5 / addendum_italics.md
Created March 8, 2021 10:18
Addendum to "Italics and colour in manual pages on a nosh user-space virtual terminal"

Addendum to Italics and colour in manual pages on a nosh user-space virtual terminal

This is an addendum to Jonathan de Boyne Pollard's Italics and colour in manual pages on a nosh user-space virtual terminal.

FreeBSD and other mandoc deployments

FreeBSD et al. has switched to mandoc as their main manpage formatter. This formatter is faster, but is only capable of emitting overstrike for bold and underline. The only way to see italicized text is by telling less to make italics when it wants underline:

export LESS_TERMCAP_us=$(tput sitm || tput us) LESS_TERMCAP_ue=$(tput ritm || tput ue) 2>/dev/null
objc_alloc=func
func.objc_alloc.args=1
func.objc_alloc.args.0=void*,id
func.objc_alloc.ret=void
objc_autorelease=func
func.objc_autorelease.args=1
func.objc_autorelease.args.0=void*,id
func.objc_autorelease.ret=void*
@Artoria2e5
Artoria2e5 / sun_getopt.c
Last active October 5, 2020 01:06
getopt(3) in the Solaris way, as a wrapper around getopt_long(3)
/**
* sun_getopt - Solaris-style getopt(3), as a wrapper around getopt_long(3).
*
* Written by Mingye Wang (Artoria2e5). Dedicated to the public domain under
* Creative Commons Zero.
*
* Untested. Like not even fed to a compiler once.
*/
#include "sun_getopt.h"