Skip to content

Instantly share code, notes, and snippets.

View yangchenyun's full-sized avatar

Steven Yang yangchenyun

View GitHub Profile
@yangchenyun
yangchenyun / poker_interview.ipynb
Last active April 4, 2024 21:25
Poker_Interview
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yangchenyun
yangchenyun / mileIQ.py
Last active December 17, 2023 21:06
mileHQ Calculator
# %%
import json
from datetime import datetime
from datetime import timedelta
import requests
import googlemaps
LOCATIONS = {
@yangchenyun
yangchenyun / demo.py
Last active October 18, 2023 05:32
unitx_task_unit
# %%
# Approach #1 - Use Proxy Pattern to control, the basic idea is to restrict and record
# setter on python class
class RestrictedProtoMsg:
"""
This class is a wrapper around a protobuf message, restricting the fields that can be modified.
It also keeps track of whether certain fields have been updated.
"""
def __init__(self, proto_msg, writable, should_update):
@yangchenyun
yangchenyun / question1.py
Last active August 30, 2023 22:11
unitx_interview
# A customer of UnitX is trying to identify some defects on a surface. Our neural network is
# capable of locating the defects on an image and returns a list of points representing
# the location of the defects. E.g. [(102, 215), (109, 201), (50, 32)]
# The customer has an extra requirement where if the distance of two points are smaller than x
# pixels, then the points should belong to the same group. Write a function that groups the list of points.
# Input:
# points (A list of tuples)
@yangchenyun
yangchenyun / train.py
Created May 25, 2023 04:48
resnet9_train
#%%
import torch
import torch.nn as nn
import numpy as np
import time
import torchvision
from torchvision import transforms
import torch.optim
from torch.optim.lr_scheduler import LinearLR, SequentialLR
@yangchenyun
yangchenyun / ops.py
Last active May 20, 2023 05:06
convolution_tensor
class Conv(TensorOp):
def __init__(self, stride: Optional[int] = 1, padding: Optional[int] = 0):
self.stride = stride or 1
self.padding = padding or 0
def compute(self, A, B):
N,H,W,C_in = A.shape
K,_,_,C_out = B.shape
P = self.padding
S = self.stride
@yangchenyun
yangchenyun / pdf_bookmark.py
Created April 20, 2023 07:24
random_tools
"""
Add bookmarks to PDF files.
"""
import sys
import os
from apryse_sdk import *
LICENCE = os.environ["apryse_licence"]
PDFNet.Initialize(LICENCE)
@yangchenyun
yangchenyun / elapsed_time.py
Last active March 28, 2023 00:32
CS188 Discussion
def elapseTime(self, gameState):
"""Sample in place, passed the test."""
pacPos = gameState.getPacmanPosition()
newParticles = []
for oldParticle in self.particles:
newParticle = list(oldParticle) # A list of ghost positions
# now loop through and update each entry in newParticle...
for i in range(self.numGhosts):
@yangchenyun
yangchenyun / del.py
Last active March 13, 2023 15:48
Symbolic differentiator
"""
The following program implements a numeric system with primitive data
structures and algorithms that can calculate derivatives for arbitrary
arithmetic expressions.
The core data structure is called `Dual`, which represents a number with its
numeric value and the operation performed in the expression AST. This means that
`Dual` remembers how the value is computed.
All primitive operations (including binary and unary) have the signature
@yangchenyun
yangchenyun / fetch_kindle.js
Last active February 19, 2023 10:10
Get back my books from Kindle
/*
* @fileoverview Program to free the content in kindle books as plain HTML.
*
* This is largely based on reverse engineering kindle cloud app
* (https://read.amazon.com) to read book data from webSQL.
*
* Access to kindle library is required to download this book.
*/
// The Kindle Compression Module copied from http://read.amazon.com application