Skip to content

Instantly share code, notes, and snippets.

View mistivia's full-sized avatar

小葉薜荔 mistivia

View GitHub Profile
@mistivia
mistivia / StateMonad.js
Created May 12, 2025 22:08
state monad in javascript
let StateM = (_ => {
let self = {};
self.new = m => {
m.bind = self.bind(m);
return m;
};
self.pure = x => self.new(s => [x, s]);
self.bind = m => k => self.new(s => {
let [x, ns] = m(s);
return k(x)(ns);
@mistivia
mistivia / Accessor.hs
Last active April 23, 2025 07:15
Simple yet usable lens-like utility functions to access nested record fileds in haskell
-- The Library
accessor getter setter f x = (setter newVal x, getter x) where newVal = f (getter x)
get accessor x = snd $ accessor id x
set accessor f x = fst $ accessor f x
composeAccessors ac1 ac2 modifier obj =
(newObj, value)
#!/usr/bin/env python3
import json
import urllib.request
import urllib.error
import sys
OPENAI_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxx"
API_URL="https://example.com/v1/chat/completions"
@mistivia
mistivia / tts_saved_deck.json
Created March 4, 2025 18:03
Tabletop Simulator Saved Deck Object Example
{
"ObjectStates": [
{
"Name": "Deck",
"Transform": {
"posX": 0,
"posY": 1,
"posZ": 0,
"rotX": 0,
"rotY": 180.0,
@mistivia
mistivia / neovim-init.vim
Last active March 12, 2025 13:32
init file for neovim
call plug#begin()
"Plug 'nvim-lua/plenary.nvim'
"Plug 'github/copilot.vim'
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-tree/nvim-tree.lua'
Plug 'nvim-tree/nvim-web-devicons'
Plug 'akinsho/bufferline.nvim'
Plug 'leafOfTree/vim-svelte-plugin'
@mistivia
mistivia / str_lambda.py
Last active January 26, 2025 03:34
create multi-line lambda from string in Python
def str_lambda(code, name = '_'):
env = {}
eval("exec(code, env)", {"code": 'def ' + name + code, "env": env})
return env[name]
f = str_lambda("""(a, b):
return a + b""")
print(f(1, 2))
#!/usr/bin/env python3
import logging
from telegram import ForceReply, Update, Message, Chat
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters
from collections import deque
import subprocess
import asyncio
import random
import json
@mistivia
mistivia / yugioh-card-loader-script.lua
Last active January 13, 2025 19:09
Yu-Gi-Oh Card Loader for Tabletop Simulator
function showPanel(player, value, id)
if (UI.getAttribute(value, "active") == "false") then
UI.show(value)
end
end
function hidePanel(player, value, id)
UI.hide(value)
end
#!/bin/bash
lang=eng
rm /tmp/scrtrans*
shotgun -g $(slop) /tmp/scrtrans.png
tesseract -l $lang /tmp/scrtrans.png /tmp/scrtrans
cat /tmp/scrtrans.txt | tr '\n' ' ' > /tmp/scrtrans.txt.2
mv /tmp/scrtrans.txt.2 /tmp/scrtrans.txt
@mistivia
mistivia / gemini-translate.py
Created January 7, 2025 14:58
AI Transalation with Gemini
#!/usr/bin/env python3
import json
import urllib.request
import urllib.parse
import sys
input = sys.stdin.read()
apikey = 'xxxxxxxxx'