Skip to content

Instantly share code, notes, and snippets.

@hsk
hsk / mdminipadmap.py
Last active May 23, 2024 03:49
MDMiniPadKeyMapper
# read https://qiita.com/wisteria/items/5c7c218bb0b3dfce984b
import usb.core, usb.util, pyautogui, time
class MDMiniPad:
def __init__(self):
self.dev = usb.core.find(idVendor=0x0ca3,idProduct=0x0024)
self.ep = usb.util.find_descriptor(
self.dev.get_active_configuration()[(0,0)],
custom_match = lambda e:
usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_IN)
interface = 0
@hsk
hsk / cek.pl
Created February 16, 2023 00:50
cek machine
% https://github.com/pycket/pycket/blob/master/papers/icfp15-paper.pdf
% e ::= x | λ(x,e) | e $ e | i | e + e | add(x,x)
% k ::= [] | [arg(e,p)|k] | [fun(v,p)|k]
:- op(1100,yfx,$).
v(I):- integer(I).
v(λ(_X,_E)).
cek(X/P/K , V/P/K):- atom(X),member(X->V,P).
cek((E1$E2)/P/K , E1/P/[arg(E2,P)|K]).
cek(V/P/[arg(E,P_)|K] , E/P_/[fun(V,P)|K]):- v(V).
cek(V/_/[fun(λ(X,E),P_)|K], E/[X->V|P_]/K):- v(V).
@hsk
hsk / pacmam.pl
Created January 12, 2023 06:26
Roguelike PacMan
read_key([Code|Codes]):- get_single_char(Code), read_pending_codes(user,Codes,[]).
read_keyatom(KAtom) :- read_key(Codes), codes_keyatom(Codes,KAtom).
codes_keyatom([27,91,65],up) :- !.
codes_keyatom([27,91,66],down) :- !.
codes_keyatom([27,91,67],right) :- !.
codes_keyatom([27,91,68],left) :- !.
data('#####################').
data('#.........#.........#').
@hsk
hsk / shiftreset.pl
Last active March 4, 2023 02:22
shift/reset
% shiftreset.pl
% http://pllab.is.ocha.ac.jp/~asai/cw2011tutorial/main-j.pdf
% 汎用構文定義用述語
:- op(1200,xfx,::=),op(600,xfx,∈).
G∈(G|_). G∈(_|G2):-!, G∈G2. G∈G.
bnf(G,E):-G=..[O|Gs],E=..[O|Es],maplist(bnf,Gs,Es),!.
bnf(G,E):-(G::=Gs),!,G1∈Gs,bnf(G1,E),!.
bnf(i,I):-integer(I),!.
bnf(x,I):- atom(I),!.
@hsk
hsk / calc.rkt
Last active March 4, 2023 02:23
#lang racket
(require redex)
(define-language calc
(e ::= n (e + e) (e - e) (e * e) (e / e) (- e))
(n ::= number))
(define-metafunction calc
⊢ : e -> n
[(⊢ n) n]
@hsk
hsk / eval.pl
Created February 19, 2022 11:36
% ------------------------ SYNTAX ------------------------
m(M) :- M = true
; M = false
; M = if(M1,M2,M3) , m(M1),m(M2),m(M3)
; M = zero
; M = succ(M1) , m(M1)
; M = pred(M1) , m(M1)
; M = iszero(M1) , m(M1)
.
@hsk
hsk / occ.pl
Last active February 20, 2022 01:36
% Implementation on Prolog of The Design and Implementation of Typed Scheme
:- op(1200,xfx,[::=]),op(600,xfx,[∈,<:,:>]).
:- op(990,xfx,[⊢]),op(990,fy,[⊢]).
:- op(250,yf,[*]).
:- op(920, xfx, ['→', '↠']).
:- op(600,yfx,[$]).
G∈(G|_). G∈(_|G2):-G∈G2. G∈G :- G\=(_|_).
bnf(S/[S2],AEs) :- compound_name_arguments(AEs,A,Es),bnf(S,A),bnf(S2,Es).
bnf(G,E):-G=..[O|Gs],E=..[O|Es],maplist(bnf,Gs,Es),!.
bnf(G,E):-(G::=Gs),!,G1∈Gs,bnf(G1,E),!.
@hsk
hsk / bigstep.rkt
Created February 5, 2022 03:20
racket redex big-step define-language λ
#lang racket
(require redex)
(provide λ λV ev)
(define-language λ
(e ::= (e e) x (λ (x τ) e) (if0 e e e) (e + e) n)
(n ::= number)
(τ ::= (τ -> τ) num)
(x ::= variable-not-otherwise-mentioned))
@hsk
hsk / parser.rs
Created August 1, 2021 04:31
nom with struct context
use nom::bytes::complete::tag;
use nom::character::complete::multispace0;
use nom::combinator::map;
use nom::error::VerboseError;
use nom::sequence::tuple;
use nom::IResult;
struct Ctx {
a: i32
}
impl Ctx {
use nom;
use nom::{
bytes::complete::{tag, take_until, take_while1},
branch::alt,
character::complete::{char, multispace0},
combinator::{map, cut},
error::VerboseError,
multi::{many1,separated_list0},
sequence::{preceded, terminated, tuple, separated_pair},
IResult,