Skip to content

Instantly share code, notes, and snippets.

View Yoxem's full-sized avatar

Tan, Kian-ting Yoxem

View GitHub Profile
@Yoxem
Yoxem / line_breaking.py
Created May 22, 2021 22:25
Knuth Line-breaking implementation in Python
#!/usr/bin/env python3
#-*-coding:utf-8-*-
# License: GPLv3
import functools
import math
import re
line_width = 40
#input_text = "aaa bb cc ddddd"
@Yoxem
Yoxem / test.html
Last active May 9, 2021 16:55
a test for how to insert a string or html parts after ith character in innerHTML of a HTML element.
<html>
<!--
這是示範「如何在某個 HTML parts 的第幾個字插入字串(或是 HTML 標籤的範例)」
License : Public Domain
-->
<head>
<title>test for input string</title>
</head>
<body>
<div id="test">台灣 ê siaⁿ-im,tī<b> 佗位? Lorem <i>ipsum</i></b><i> dolor sit</i> amet, inis me Johano agus mar sin de.</div>
@Yoxem
Yoxem / closure.c
Last active May 23, 2021 07:27
finding duplicated variable and type interfence using Racket
#include <stdio.h>
/*
lambda 函數的案例
(define foo (lambda (x) 10) [fv ()])
(foo foo)
*/
typedef union object object;
@Yoxem
Yoxem / expanding-expression.rkt
Created February 7, 2021 23:47
Expending expression in Racket
#lang racket
(define expr
'(+ (- 5 (* 4 3)) (* 7 (* 2 8))))
(struct exp-and-holder (exp holder) #:transparent)
(define (main-converter exp)
(let*
((var-holder '())
(exp-holder (exp-and-holder exp var-holder)))
@Yoxem
Yoxem / emulator.py
Created January 31, 2021 10:14
A draft of a assembly language-like machine emulator written in Python
#!/usr/bin/env/python3
# Authur: Yoxem
# License: Public Domain
code = [["MOV", 12 ,"GEN1"], ["MOV", "GEN1", ["GEN2", 6]], ["ADD", "GEN1", 12], ["ADD", "GEN1", "GEN2"]]
memory = [0] * 20;
registers = {
'GEN1' : 0,
@Yoxem
Yoxem / find-free-var.rkt
Last active October 3, 2020 13:51
find-free-var.rkt free variable finder. Nacessesary while closure conversion is operated.
#lang racket
;; find-free-var.rkt free variable finder. Nacessesary while closure conversion is operated.
;; ref: the algorithm from Definition 1.4.1, Type Theory andd Formal Proof: An Introdution
;; remove items from a list
(define (remove-items items list)
(if (eq? items empty)
list
(remove-items (cdr items) (remove (car items) list)))
)
@Yoxem
Yoxem / pattern-match.rkt
Last active October 2, 2020 12:07
pattern-match.rkt - implementation of basic pattern match
#lang racket
; pattern-match.rkt - implementation of basic pattern match
(define (conbining-cond-and-match-list ls)
(cons 'cond ls))
(define (convert-match input)
(define pattern-list (cddr input))
(cond
[(not (eq? (car input) 'match)) (error "the head of input is not \"match\". Exit.")]
@Yoxem
Yoxem / extend-a-macro.rkt
Created August 14, 2020 17:53
Extend a macroin Racket
#lang racket
(define (combine-two-list x y)
(if (eq? x '()) '()
(cons (cons (car x) (car y)) (combine-two-list (cdr x) (cdr y)))))
; (combine-two-list '(a b c) '(1 2 3)) -> '((a . 1) (b . 2) (c . 3))
(define (walk-the-tree expr-tree macro-var-list)
(cond
((pair? expr-tree) (cons (walk-the-tree (car expr-tree) macro-var-list)
@Yoxem
Yoxem / parser.py
Last active May 11, 2020 16:25
Compiler Test
import re
# test code
# test = "1 + 2 * (23 / 12)"
test1 = "(123 (88) 1) 9(8 7) "
test2 = '''
12
(+ 2 3)
(let (int x) 2)
@Yoxem
Yoxem / poj-test.mim
Created April 16, 2020 13:40
Test m17n-input method-table
-test.mim
;; zh-pinyin.mim -- Input method for Chinese Pinyin characters
;; Copyright (C) 2004, 2005
;; National Institute of Advanced Industrial Science and Technology (AIST)
;; Registration Number H15PRO112
;; This file is part of the m17n database; a sub-part of the m17n
;; library.
;; The m17n library is free software; you can redistribute it and/or