Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View janispritzkau's full-sized avatar

Janis Pritzkau janispritzkau

View GitHub Profile
@janispritzkau
janispritzkau / game-of-life.html
Last active August 21, 2019 18:42
Code golf: Game of Life (286 bytes)
<canvas id="c"><script>t=c.getContext("2d"),s=150,a=[];for(i=s*s;i--;)a[i]=Math.random()<.1;setInterval(_=>{b=[],t.clearRect(0,0,s,s);for(i=s*s;i--;){n=0;for(j=9;j--;)n+=a[(~~(i/s)+s+j%3-1)%s*s+(i+s+~~(j/3)-1)%s];b[i]=n==3||n-a[i]==3,a[i]&&t.fillRect((i%s),~~(i/s),1,1)}a=b},s)</script>
@janispritzkau
janispritzkau / index.html
Last active November 1, 2019 16:28
Rendering area chart with WebGL (1 million points)
<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebGL Chart</title>
<span id="fps">Loading</span>
<canvas></canvas>
<style>
body {
@janispritzkau
janispritzkau / ejs.ts
Created April 25, 2021 21:34
Deno EJS Template Engine
import { dirname, extname, resolve } from "https://deno.land/std/path/mod.ts";
const MODE_EVAL = 0;
const MODE_ESCAPED = 1;
const MODE_RAW = 2;
interface Range {
source: [number, number];
code: [number, number];
}
@janispritzkau
janispritzkau / analytics.js
Last active April 5, 2022 17:51
Minimal Google Analytics Script (677 bytes minified)
((document, location, navigator) => {
const domain = location.hostname.split(".")
const match = document.cookie.match(/(^|; ?)_ga=GA1\.\d\.(\d+\.\d+)(;|$)/)
// use existing client id or generate one
const cid = match ? match[2] : ~~(2147483648 * Math.random()) + "." + ~~(Date.now() / 1000)
// set cookie at highest possible domain level
for (let i = domain.length; i--;) {
const cookie = `_ga=GA1.${domain.length - i}.${cid}`
@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
@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 / 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 / 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/minecraft_lib@0.0.8/auth/mod.ts";
import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts";
const oauthClient = new OAuthClient({
@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/std@0.164.0/encoding/base64url.ts";
export interface RsaPrivateKey {
n: bigint;
e: bigint;
d: bigint;
p: bigint;
q: bigint;
dp: bigint;
dq: bigint;
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;
}