Skip to content

Instantly share code, notes, and snippets.

View RuolinZheng08's full-sized avatar

Lynn Zheng RuolinZheng08

View GitHub Profile
@RuolinZheng08
RuolinZheng08 / epidemic_network.ipynb
Last active January 31, 2021 20:59
[Python, Statistics] An SIR (Susceptible, Infected and Recovered) Network Example
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@RuolinZheng08
RuolinZheng08 / permutation_test.ipynb
Created January 31, 2021 20:45
[Python, Statistics] Permutation Test
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@RuolinZheng08
RuolinZheng08 / tree_traversal_template.py
Created November 20, 2020 15:19
[Algo] Tree Traversal Template
# DFS
def preorder(self, root):
if not root:
return []
ret = []
stack = [root]
while stack:
node = stack.pop()
ret.append(node.val)
if node.right:
@RuolinZheng08
RuolinZheng08 / graph_traversal_template.py
Last active July 1, 2022 13:54
[Algo] Graph Traversal Template
# Iterative
def dfs(graph, start):
visited, stack = set(), [start]
while stack:
node = stack.pop()
visited.add(node)
for neighbor in graph[node]:
if not neighbor in visited:
stack.append(neighbor)
return visited
@RuolinZheng08
RuolinZheng08 / backtracking_template.py
Last active March 28, 2024 18:48
[Algo] Backtracking Template & N-Queens Solution
def is_valid_state(state):
# check if it is a valid solution
return True
def get_candidates(state):
return []
def search(state, solutions):
if is_valid_state(state):
solutions.append(state.copy())
@RuolinZheng08
RuolinZheng08 / CreatorDefinedDisplayable.rpy
Last active July 1, 2022 13:54
[Ren'Py, Template] Creator-Defined Displayable
class CreatorDefinedDisplayable(renpy.Displayable):
def __init__(self):
super(CreatorDefinedDisplayable, self).__init__()
def render(self, width, height, st, at):
render = renpy.Render(width, height)
return render
def event(self, ev, x, y, st):
@RuolinZheng08
RuolinZheng08 / sudoku_solver.py
Created August 9, 2020 21:43
[Python] Sudoku Solver | CodePath Dynamic Programming & Backtracking Project
from itertools import product
class SudokuSolver:
"""
Solve a sudoku puzzle given as a 81-digit string with . denoting empty
"""
SHAPE = 9
GRID = 3
EMPTY = '.'
@RuolinZheng08
RuolinZheng08 / HtmlToPdf.java
Last active February 8, 2023 04:50
[Java] HTML (to XHTML) then to PDF with CSS 2.1 Support | Flying Saucer + OpenPDF
import java.io.*;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.xhtmlrenderer.extend.FontResolver;
import org.xhtmlrenderer.pdf.ITextRenderer;
public class HtmlToPdf {
public static void main(String[] args) throws IOException {
String html = "<h1>hello</h1>";
String xhtml = htmlToXhtml(html);
@RuolinZheng08
RuolinZheng08 / index.html
Last active January 31, 2021 20:47
[Template] Dummy index.html for GitHub repo page
<!DOCTYPE html>
<html>
<head>
<title></title>
<!-- Just a dummy html to redirect to my subdirectory -->
<meta http-equiv="refresh" content="0; url=[INSERT URL HERE]">
</head>
<body>
</body>
@RuolinZheng08
RuolinZheng08 / mfcc.py
Last active January 31, 2021 20:47
[Python] Mel-frequency Cepstrum
from IPython.display import Audio
import numpy as np
from numpy.fft import fft, ifft
from scipy.fftpack import dct, idct
from scipy.signal import stft
import soundfile as sf