Skip to content

Instantly share code, notes, and snippets.

View mofas's full-sized avatar

Chung Yen Li mofas

View GitHub Profile
.root___1Rh2d {
padding: .5rem 1rem .5625rem;
border: none;
color: #fff;
font-size: larger;
cursor: pointer;
border-radius: 1.25rem;
border: 2px solid #900
}
@mofas
mofas / a.js
Last active March 8, 2020 23:00
Search Google
async function queryGoogle(target) {
const page = await browser.newPage();
await page.goto('https://google.com');
await page.keyboard.type(target + " MSA")
await page.keyboard.press("Enter")
await page.waitForNavigation();
await page.content()
const title = await page.evaluate(() => {
let elements = document.querySelectorAll('h3');
return elements[0].textContent;
@mofas
mofas / limitCoint.py
Last active September 2, 2019 21:49
Coin changes
dfs (remainCoins, target):
if target === 0:
# calculate what coins you used here
usedCoin = ...
results.append(usedCoin)
return
if target < 0:
return
for coin in remainCoins:
@mofas
mofas / min-char-rnn.py
Created March 7, 2019 04:12 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@mofas
mofas / main.py
Last active February 8, 2019 01:18
For Pan
import sys
import numpy as np
from scipy.cluster.hierarchy import dendrogram, linkage
import matplotlib.pyplot as plt
def minidistance(S1, S2) :
N = len(S1)
M = len(S2)
matrix = np.zeros((N + 1, M + 1), dtype=int) #Build an alignment matrix
matrix[0][0] = 0
@mofas
mofas / main.py
Created February 4, 2019 20:14
sarbina cute cute
from scipy import fftpack
import imageio
import numpy
# load in an image, convert to grayscale if needed
image = imageio.imread('ft/input.png', as_gray=True)
# take the fourier transform of the image
fft2 = fftpack.fftshift(fftpack.fft2(image))
@mofas
mofas / main.py
Created February 1, 2019 17:11
For eddie
def get_next_status_set(status):
ret = []
status_len = len(status)
for i in range(status_len - 1):
if status[i] == '1' and status[i + 1] == '0':
new = status[:]
new[i] = '0'
new[i + 1] = '1'
ret.append(''.join(new))
# handl the last case
@mofas
mofas / 965.py
Last active January 5, 2019 21:57
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
def isUnivalTree(self, root):
"""
:type root: TreeNode
@mofas
mofas / iter_rec_diff.py
Created November 22, 2018 16:49
Explain the iteration and recursion for beginner
def fact1(n):
acc = 1
for i in range(n):
# print(acc, i + 1)
acc *= (i + 1)
return acc
seq = ['A', 'B', 'C']
current = []
next = []
for char in seq:
for c in current:
next.append(c + char)
next.append(char + c)
next.append(char)
current = current + next