Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Rami Awar RamiAwar

🏠
Working from home
View GitHub Profile
View image_upload_v2.py
def verify_image(file):
"""Verifies that file is a valid image"""
return file.ext in ("jpg", "jpeg", "png")
def store_file(file):
"""Upload file to storage microservice"""
return storage_service.upload_image(file)
def upload_image(file):
"""API route to upload image"""
View image_upload.py
def verify_image(file):
"""Verifies that file is a valid image"""
return file.ext in ("jpg", "jpeg", "png")
def store_file(file):
"""Uploads a file to the document storage server, returns URL"""
pass
def upload_image(file):
"""API route to upload image"""
View e.py
def calculate_stats(exam_results: List[int]) -> Dict[str, float]:
max_score = max(exam_results)
min_score = min(exam_results)
avg_score = sum(exam_results) / len(exam_results)
return {"max": max_score, "min": min_score, "avg": avg_score}
def post_exam_computation(exam_id):
exam_results = db.get(exam_id)
exam_stats = calculate_stats(exam_results)
View d.py
def calculate_stats(exam_results):
max_score = max(exam_results)
min_score = min(exam_results)
return {"max": max_score, "min": min_score}
def post_exam_computation(exam_id):
exam_results = db.get(exam_id)
exam_stats = calculate_stats(exam_results)
db.save(exam_stats)
View c.py
def post_exam_computation(exam_id): # Requires exam_id
exam_results = db.get(exam_id) # Requires mocking db
max_score = max(exam_results) # Need exam results
min_score = min(exam_results)
exam_stats = {"max": max_score, "min": min_score}
db.save(exam_stats) # Requires mocking db
View b.y
def post_exam_computation(exam_id):
exam_results = db.get(exam_id)
max_score = max(exam_results)
min_score = min(exam_results)
avg_score = sum(exam_results) / len(exam_results)
exam_stats = {"max": max_score, "min": min_score, "avg": avg_score}
db.save(exam_stats)
View a.py
def post_exam_computation(exam_id):
exam_results = db.get(exam_id) # Database call
max_score = max(exam_results)
min_score = min(exam_results)
exam_stats = {"max": max_score, "min": min_score}
db.save(exam_stats)
View pydantic_sanic_decorator.py
def validate_unwrap(path_model=None, query_model=None, body_model=None):
"""Validates a Sanic route handler using path, query and body pydantic models.
This decorator would automatically validate the request path/query/body models and
plug in instances of the pydantic models as additional arguments to the route handler.
Usage:
from pydantic import BaseModel, validator
class CustomerIn(BaseModel):
first_name: str
View zshenv
export PATH=/usr/local/bin:$PATH
export PROMPT=" %(?.%F{green}√.%F{red}X %?) %F{green}%n@%1d λ "
eval "$(pyenv init -)"
# Git integration
autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
View camera_face_scroll.py
'''This python code performs face tracking and simulates scrolling. First, the image feed is recieved from the camera. A facial detection algorithm is applied
once in every 5 frames. On detecting the face, a rectangular frame is drawn around the detected face, and the deviation from the center of the screen to the center of the face is taken as the scroll delta.
Requires Python + OpenCV'''
import cv2
from pynput.mouse import Button, Controller
mouse = Controller()
HAAR_CASCADE_PATH = "haarcascade_frontalface_alt.xml"