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 numpy as np | |
import matplotlib.pyplot as plt | |
def main() -> None: | |
# Define the matrices | |
W1 = np.eye(3) # Identity matrix | |
W2 = np.array([[3, -2, 1], [2, -2, 0], [0, 1, 1]]) # Rank-deficient matrix | |
# Create figure for W1 |
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
#!/bin/bash | |
# Usage ./gpumeter.sh my-gpu-hungry-script.sh | |
# Check if the command argument is provided | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 <script_to_run>" | |
exit 1 | |
fi |
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 subprocess | |
def get_device(): | |
# Check for CUDA GPU | |
if torch.cuda.is_available(): | |
return 'cuda' | |
# Check for Apple Silicon (M1/M2) using sysctl | |
try: |
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
#!/bin/bash | |
# URL of the website to download from | |
URL="https://www.andrew.cmu.edu/course/11-667/lectures/" | |
# Directory where the files will be saved | |
DESTINATION_DIR="./cmu_course_lectures" | |
# Create the destination directory | |
mkdir -p "$DESTINATION_DIR" |
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
""" | |
Generates video screenshot from a text file of timestamps expressed in seconds. | |
Note: ffmpeg must be installed on your machine. | |
Tested on python3.7 | |
Example usage: | |
``` |
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 main(): | |
""" | |
Inspired from https://github.com/grpc/grpc/blob/master/examples/python/multiprocessing/server.py | |
""" | |
logger.info(f'Initializing server with {NUM_WORKERS} workers') | |
with _reserve_port() as port: | |
bind_address = f"[::]:{port}" | |
logger.info(f"Binding to {bind_address}") | |
sys.stdout.flush() | |
workers = [] |
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 grpc | |
from concurrent import futures | |
server = grpc.server( | |
futures.ProcessPoolExecutor(max_workers=5), # ← HERE: Would be ideal but does not work. | |
options=[ # See https://github.com/grpc/grpc/issues/14436 | |
("grpc.max_send_message_length", -1), | |
("grpc.max_receive_message_length", -1), | |
] | |
) |
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 get_text_from_image(img: bytes) -> str: | |
""" | |
Perform OCR over an image. | |
Args: | |
img (bytes) : a pickled image - encoded with openCV. | |
Returns: | |
The text found in the image by the OCR module. |
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 collections | |
class Solution: | |
def deleteAndEarn(self, nums: List[int]) -> int: | |
m: int = max(nums) | |
buckets: List[int] = [0 for _ in range(m+1)] | |
counter = collections.Counter(nums) | |
for k, v in counter.items(): | |
buckets[k] = v*k | |
take, skip = 0, 0 |
NewerOlder