Skip to content

Instantly share code, notes, and snippets.

View marethyu's full-sized avatar
🙈
Playing hide and seek

Jimmy Yang marethyu

🙈
Playing hide and seek
  • UBC
  • Canada
View GitHub Profile
@marethyu
marethyu / turing.py
Created April 6, 2024 22:33
Python script to simulate Turing machine.
"""
Turing machine implementation in Python
Example input:
(Machine to generate Collatz sequence)
0,I;1,I,R
1,I;2,I,L
2,I;3,I,R
@marethyu
marethyu / cw_fetch_latest.py
Last active April 1, 2024 00:53
Script to fetch the latest chapter of a series in Comicwalker
import itertools
import json
import os
import requests
import sys
from bs4 import BeautifulSoup
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
@marethyu
marethyu / simplex.py
Created February 11, 2024 22:32
Simplex method in Python
"""
The function simplex takes initial feasible dictionary of a LP problem with
m basic variables and n non-basic variables, represented by (m+1)x(n+1) matrix
wrapped in numpy.array, as its only input.
The format of the input matrix input is as follows:
In each row, the first column is reserved for additive constant
while the rest of the columns stores coefficients of non-basic variable.
The first row describes the objective function while the rest of the rows
list constraints. You can check some examples near the end of the file.
@marethyu
marethyu / pi.cpp
Created December 27, 2023 03:45
DFT demo
/* g++ pi.cpp -o pi -std=c++14 -lSDL2 */
/* Grab pi.csv from https://dsp.stackexchange.com/a/59181/70343 */
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <algorithm>
import matplotlib.pyplot as plt
import numpy as np
from math import comb, log
def annotate_max(x, y, ax=None):
xmax = x[np.argmax(y)]
ymax = y.max()
text= "U_A={:.3f}, S={:.3f}".format(xmax, ymax)
if not ax:
# Draw 5 cards from the standard deck of 52 cards. Denote random variables X to be the number of black cards in the hand and Y to be the number of spades in the hand.
from math import comb
from pandas import DataFrame
nways = comb(52, 5)
joint_pmf = [[0.0 for x in range(7)] for y in range(7)]
total = 0.0
#include <iostream>
#include <bitset>
#include <cstdint>
#include <array>
using BYTE = uint8_t;
struct HALFWORD
{
union
@marethyu
marethyu / Back
Created March 30, 2022 08:01
Anki mining deck note
{{FrontSide}}
<hr id=answer>
読み方: {{Reading}} <br>
品詞: {{PartOfSpeech}} <br>
{{#Picture}}
画像: <br>
<div id="center-text">{{Picture}}<br></div>
@marethyu
marethyu / comic-walker.py
Created March 26, 2022 08:19 — forked from bluecookies/comic-walker.py
working comic walker downloader as of 2018-03-22
from sys import argv
import requests
import json
import os
import itertools
endpoint_url = "https://ssl.seiga.nicovideo.jp"
OUT_DIR = "out"
# endpoint + "/api/v1/comicwalker/episodes/" + episode_id + "/frames"
use std::process;
use std::thread;
use std::time::Duration;
use rand::Rng;
use sdl2::event::Event;
use sdl2::pixels::PixelFormatEnum;
const WIDTH: usize = 256;