Skip to content

Instantly share code, notes, and snippets.

@leonmak
leonmak / bayes-visualization.html
Last active March 22, 2026 11:39
Bayes one-pager
<html lang="en">
<head>
<style>
:root {
--bg: #ffffff;
--bg2: #f5f4f0;
--bg3: #eae9e4;
--tx: #1a1a18;
--tx2: #5f5e5a;
--tx3: #888780;
@leonmak
leonmak / confusion-matrix.html
Last active March 22, 2026 10:42
Confusion Matrix - small explainer
<!-- saved from url=(0053)file:///Users/leonmak/Downloads/confusion-matrix.html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Confusion Matrix Visualization</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
@leonmak
leonmak / board.py
Last active February 15, 2025 12:51
multi-threaded board game
import random
import threading
import time
num_p = 10
m, n = 5, 5
# position (y,x) - lock, players in pos
board_locks = {(i//m, i % n): threading.Lock() for i in range(m*n)}
board_players = {(i//m, i % n): set() for i in range(m*n)}
@leonmak
leonmak / README.md
Last active November 10, 2023 13:11
how to setup matrix server dendrite

Docker

in ~/docker/matrix:

  • wget https://raw.githubusercontent.com/matrix-org/dendrite/main/build/docker/docker-compose.yml
  • edit docker-compose.yaml
    • to add postgres password
    • to add volume file below
      • ./config:/etc/dendrite for below config
      • ./:/mnt for keys in container, see below
  • edit config/dendrite.yaml
@leonmak
leonmak / fetch-content.js
Created October 17, 2022 06:12
get-substack
const runner = ((links) => {
var parser = new DOMParser();
links.forEach(async link => {
const resp = await fetch(link)
const text = await resp.text()
const doc = parser.parseFromString(text, "text/html");
const title = doc.querySelector('.post-title').textContent;
const subtitle = doc.querySelector('.subtitle').textContent
const bodyHTML = doc.querySelector('.available-content').innerHTML;
const html = `<html>
@leonmak
leonmak / test2.json
Last active September 5, 2022 04:30
test2.json
[
{
"id": "gender",
"type": "select",
"question": "Gender?",
"options": [
{
"value": "0",
"label": "Decline to answer"
},
@leonmak
leonmak / test.json
Last active January 27, 2022 08:48
test
[
{
"id": "dateOfBirth",
"required": true,
"type": "date",
"question": "生年月日",
"format": "yyyy/MM/dd",
"min": "2008/01/02"
}
]
@leonmak
leonmak / auth.js
Last active May 24, 2021 14:05
chrome extension login id token
// need to use launchWebAuthFlow in chrome extension
// can't use gapi in extension
// https://github.com/google/google-api-javascript-client/issues/64
async function getIdTokenInfo(id_token: string) {
const resp = await fetch(
`https://oauth2.googleapis.com/tokeninfo?id_token=${id_token}`
);
return resp.json();
}
@leonmak
leonmak / pecs.java
Last active May 26, 2020 06:07
Producer extend Consumer super
import java.util.ArrayList;
import java.util.List;
class Scratch {
class Shark {
private final String name = "Sharkie";
public String getName() { return name; }
}// A
class HammerShark extends Shark{
@leonmak
leonmak / mac_word_move.plist
Last active May 30, 2019 05:59
iterm2 mac profile - word movement, deletion and pane selection
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AlternateMouseScroll</key>
<true/>
<key>AppleAntiAliasingThreshold</key>
<integer>1</integer>
<key>AppleScrollAnimationEnabled</key>
<integer>0</integer>