Skip to content

Instantly share code, notes, and snippets.

View janispritzkau's full-sized avatar

Janis Pritzkau janispritzkau

  • Germany
  • 04:45 (UTC +02:00)
View GitHub Profile
@janispritzkau
janispritzkau / vite-subset-icons-plugin.ts
Last active November 3, 2024 19:28
Material Symbols subset font plugin for Vite (reduces bundle size from megabytes to kilobytes)
import { readFile } from "node:fs/promises";
import { relative } from "node:path";
import { Minimatch } from "minimatch";
import subsetFont from "subset-font";
import { Plugin } from "vite";
export interface SubsetOptions {
codepointsPath: string;
iconsGlob: string;
@janispritzkau
janispritzkau / tailwind.config.ts
Created November 26, 2023 11:20
Tailwind Material Symbols Background Image SVG Plugin
import { Config } from "tailwindcss";
import plugin from "tailwindcss/plugin";
import { readFileSync, readdirSync } from "fs";
import { dirname, join } from "path";
export default {
// ...
plugins: [
plugin(({ addBase, theme }) => {
const colors = flattenColorPalette(theme("colors"));
@janispritzkau
janispritzkau / tailwind.config.js
Created November 23, 2023 18:04
Tailwind Config with Desaturated Grays using OKLCH
import { formatHex, oklch } from "culori";
import type { Config } from "tailwindcss";
import { gray } from "tailwindcss/colors";
export default {
content: ["index.html", "./src/**/*.{ts,tsx,vue}"],
theme: {
extend: {
colors: {
gray: Object.fromEntries(
@janispritzkau
janispritzkau / git_merge_unrelated_histories.md
Last active June 15, 2023 08:34
Merge unrelated histories in Git
  1. git checkout <original_branch>
  2. git merge <new_branch> --allow-unrelated-histories
  3. git checkout next . --force --no-overlay
  4. git commit --no-edit
abstract class Property<T = unknown> {
#values: readonly T[];
constructor(public name: string, values: readonly T[]) {
this.#values = Object.freeze(values);
}
get possibleValues(): readonly T[] {
return this.#values;
}
@janispritzkau
janispritzkau / rsa.ts
Last active November 14, 2022 17:50
Deno RSA encryption and signing with PKCS1 padding in TypeScript
import * as base64url from "https://deno.land/[email protected]/encoding/base64url.ts";
export interface RsaPrivateKey {
n: bigint;
e: bigint;
d: bigint;
p: bigint;
q: bigint;
dp: bigint;
dq: bigint;
@janispritzkau
janispritzkau / auth_puppeteer.ts
Last active November 13, 2022 19:28
Minecraft OAuth authentication using Puppeteer
#!/usr/bin/env -S deno run -A
// you might need to specify a different chrome executable because of a bug
// https://github.com/lucacasonato/deno-puppeteer/issues/65
// PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable (on my linux system)
import { OAuthClient } from "https://deno.land/x/[email protected]/auth/mod.ts";
import puppeteer from "https://deno.land/x/[email protected]/mod.ts";
const oauthClient = new OAuthClient({
@janispritzkau
janispritzkau / aes_128_cfb8.ts
Created November 8, 2022 13:56
Deno AES-128-CFB8 encryption using OpenSSL and FFI
const lib = Deno.dlopen(
Deno.env.get("DENO_SSL_PATH")!,
{
AES_set_encrypt_key: {
parameters: ["buffer", "u32", "buffer"],
result: "i32",
},
AES_cfb8_encrypt: {
parameters: [
"buffer",
@janispritzkau
janispritzkau / iso_weeks.sql
Created August 25, 2022 19:39
Start date and week count for first calendar week of year (PostgreSQL)
SELECT
year,
date_trunc('week', make_date(year, 1, 4))::date AS start, -- first calendar week always contains January 4th.
extract(week from make_date(year + 1, 1, 4) - 7) AS weeks
FROM generate_series(2000, 2030) t(year);
@janispritzkau
janispritzkau / sungrow_sh10rt_modbus.yaml
Created August 9, 2022 09:48
Modbus Registers for Sungrow SH10RT Hybrid Inverter
input_registers:
- name: protocol_number
data_type: uint32
address: 4950
- name: protocol_version
data_type: uint32
address: 4952
- name: arm_software_version
data_type: string
address: 4954