Skip to content

Instantly share code, notes, and snippets.


Z. "Alan" Xiang xziyue

View GitHub Profile
english_digits = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
# check if string s1 starts with s2
def startswith(s1, s2):
if len(s2) > len(s1):
return False
for i in range(len(s2)):
if s1[i] != s2[i]:
return False
return True
xziyue / latex3-maze-game.tex
Created Oct 18, 2020
LaTeX3 maze PDF game
View latex3-maze-game.tex
\usepackage[paperwidth=8cm, paperheight=8cm, margin=2mm]{geometry}
xziyue /
Last active Sep 28, 2020
"typing" with emojis in discord
import os
import sys
import numpy as np
from PIL import Image, ImageFont, ImageDraw, ImageEnhance
import matplotlib.pyplot as plt
# parameters
font_size = 12
threshold = 0.9
emoji = ':a_:'
xziyue / lua_latex_parser.lua
Created Aug 11, 2020
Simple LaTeX parser in Lua
View lua_latex_parser.lua
inspect = require "inspect.lua"
function raise_error(...)
local arg = {...}
local description = "a luaprogtable package exception occured:\n" .. table.concat(arg, ", ")
local _spacer = lpeg.S(" \t\f\v\n\r")
View example-my-table.tex
Deadline & No. & Lorem Ipsum & Dolor Sit & Amet Consectetuer & Adipiscing Elit & Aenean Commodo \\ \hline
\def\@linkcolor{blue}\hyperref[subsec-2020-07-15]{2020-07-15} & \def\@linkcolor{green}\hyperref[subsubsec-2020-07-15-basic]{1} & \def\@linkcolor{red}\hyperref[figure-2020-07-15-basic-lorem-ipsum]{4.43} & \def\@linkcolor{red}\hyperref[figure-2020-07-15-basic-dolor-sit
xziyue / tex-file-buffer.sty
Created Jul 7, 2020
Mimicking file system input in LuaTeX
View tex-file-buffer.sty
\RequirePackage{luacode, luatexbase}
TeXFileBuffer = {content={}, finished=false}
function TeXFileBuffer:new()
o = {}
setmetatable(o, self)
self.__index = self
return o
xziyue / jekyll-index-term-new.rb
Last active Jul 5, 2020
A Simple Ruby Program For Jekyll Indexing
View jekyll-index-term-new.rb
require 'digest/sha1'
module Jekyll
module JekyllIndexTermFilter
@@show_warning = true
@@tag_re = /(%+)({)(.*?)(}%)/
@@tag_alias_re = /(?<!\\)@/
@@TagInfo =, :raw, :segments)
xziyue /
Created Dec 11, 2019
Converting colored LaTeX listing to HTML
from import TexNode, TexEnv, TexCmd, RArg
from TexSoup import TexSoup
import re
import copy
import html as htmlib
class Tex2HTML:
def __init__(self):
xziyue / jekyll-index-term.rb
Last active Dec 11, 2019
A simple Ruby program to support indexing in Jekyll
View jekyll-index-term.rb
require 'digest/sha1'
module Jekyll
module JekyllIndexTermFilter
# html display name, index name
def getnames(matchedString)
stripped = matchedString.strip()
matchResult = stripped.match(/(?<!\\)@/)
xziyue /
Last active Nov 3, 2019
Simulating a small circle rolling on another big circle
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.animation import FuncAnimation
tessellatePieces = 300
assert tessellatePieces % 2 == 0
bigCircleAngles = np.linspace(0.0, 2.0 * np.pi, tessellatePieces, endpoint=False)
smallCircleAngles = np.linspace(0.0, 2.0 * np.pi, tessellatePieces // 2, endpoint=False)
You can’t perform that action at this time.