Skip to content

Instantly share code, notes, and snippets.

Avatar

Z. "Alan" Xiang xziyue

View GitHub Profile
@xziyue
xziyue / correlation_comp.py
Last active Feb 4, 2022
Some random correlation?
View correlation_comp.py
import itertools
import numpy as np
class Calculator:
def __init__(self, vars):
self.vars = vars
self.num_vars = len(vars)
self.var_index = np.arange(self.num_vars, dtype=np.uint64)
View sms_latex.tex
% https://tex.stackexchange.com/questions/632271/chat-like-text-bock-in-tikz-environment
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{xparse}
\usepackage{calc}
\usepackage{varwidth}
View seismic_wave.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xziyue
xziyue / video_to_str.ipynb
Last active Jan 31, 2021
an example to represent videos using characters
View video_to_str.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xziyue
xziyue / render_video_frame_str.py
Last active Jan 31, 2021
renders the string for video frames
View render_video_frame_str.py
# used in conjunction with https://gist.github.com/xziyue/0e83c7c6938d125b05d5bcad5e12e43a
import pickle
from PIL import Image, ImageFont, ImageDraw, ImageOps
import os
from multiprocessing import Pool
def generate_render_param(text_dim, font, fontsize, spacing):
test_str = '\n'.join([' ' * text_dim[1] for _ in range(text_dim[0])])
@xziyue
xziyue / chn_to_pinyin.lua
Created Dec 29, 2020
Chinese characters' pinyin lookup table
View chn_to_pinyin.lua
chn_to_pinyin = {
["吖"]="ā",["阿"]="ā",["啊"]="ā",["锕"]="ā",["錒"]="ā",["嗄"]="á",
["厑"]="ae",["哎"]="āi",["哀"]="āi",["唉"]="āi",["埃"]="āi",["挨"]="āi",
["溾"]="āi",["锿"]="āi",["鎄"]="āi",["啀"]="ái",["捱"]="ái",["皑"]="ái",
["凒"]="ái",["嵦"]="ái",["溰"]="ái",["嘊"]="ái",["敱"]="ái",["敳"]="ái",
["皚"]="ái",["癌"]="ái",["娾"]="ái",["隑"]="ái",["剴"]="ái",["騃"]="ái",
["毐"]="ǎi",["昹"]="ǎi",["矮"]="ǎi",["蔼"]="ǎi",["躷"]="ǎi",["濭"]="ǎi",
["藹"]="ǎi",["譪"]="ǎi",["霭"]="ǎi",["靄"]="ǎi",["鯦"]="ǎi",["噯"]="ài",
["艾"]="ài",["伌"]="ài",["爱"]="ài",["砹"]="ài",["硋"]="ài",["隘"]="ài",
["嗌"]="ài",["塧"]="ài",["嫒"]="ài",["愛"]="ài",["碍"]="ài",["叆"]="ài",
@xziyue
xziyue / enter_list_to_groovy.py
Created Dec 26, 2020
enter groovy music list into Discord
View enter_list_to_groovy.py
import time
from pynput.keyboard import Key, Controller
import pyperclip
import json
with open('crawl_list.json', 'r') as infile:
song_list = json.load(infile)
kb = Controller()
@xziyue
xziyue / groovy_music_from_apply.py
Created Dec 26, 2020
Pull song lists from Apple Music for Groovy BOT
View groovy_music_from_apply.py
from urllib.request import urlopen
from bs4 import BeautifulSoup
import json
import os
from youtube_search import YoutubeSearch
list_url = 'https://music.apple.com/us/playlist/a-list-pop/pl.5ee8333dbe944d9f9151e97d92d1ead9'
youtube_url = 'https://www.youtube.com'
use_cached = True
cached_filename = 'crawl_list.html'
View parse_digits.py
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
xziyue / latex3-maze-game.tex
Created Oct 18, 2020
LaTeX3 maze PDF game
View latex3-maze-game.tex
\documentclass{article}
\usepackage[paperwidth=8cm, paperheight=8cm, margin=2mm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\usepackage{expl3}
\usepackage{enumitem}
\usepackage{hyperref}
\pagestyle{empty}