Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# %% | |
import json | |
from datetime import datetime | |
from datetime import timedelta | |
import requests | |
import googlemaps | |
LOCATIONS = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# %% | |
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%% | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Add bookmarks to PDF files. | |
""" | |
import sys | |
import os | |
from apryse_sdk import * | |
LICENCE = os.environ["apryse_licence"] | |
PDFNet.Initialize(LICENCE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
minibox_scenarios = [ | |
"<1.2.3", | |
">=1.2.3 AND <1.3.8", | |
"==1.3.8", | |
] | |
system_patch_scenarios = [ | |
"brand_new_box", # never applied any system patch | |
"used_box", # has applied some system patch, but not all | |
"updated_box", # has applied all system patches |
NewerOlder