Skip to content

Instantly share code, notes, and snippets.

@mistivia
mistivia / borrow.hs
Last active May 31, 2025 19:23
Borrow like Rust in Linear Haskell
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE QualifiedDo #-}
import Data.Type.Bool
import Foreign.Ptr (Ptr)
import Foreign.C.Types (CDouble)
import Foreign.Marshal.Alloc (free)
@mistivia
mistivia / monad.rkt
Last active May 15, 2025 14:13
Monad with do-notation in Racket
#lang racket
(define-syntax define-macro
(lambda (x)
(syntax-case x ()
((_ (macro . args) body ...)
#'(define-macro macro (lambda args body ...)))
((_ macro transformer)
#'(define-syntax macro
(lambda (y)
@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