This file contains hidden or 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
| #![allow(unused_variables, dead_code)] | |
| use std::fmt::{Display, Formatter}; | |
| #[derive(Clone, PartialEq, Eq)] | |
| struct BST { | |
| key: String, | |
| value: u64, | |
| left: Box<Option<BST>>, | |
| right: Box<Option<BST>> |
This file contains hidden or 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
| app.conf.beat_schedule = { | |
| 'renew-expired-subscriptions': { | |
| 'task': 'runner.renew_expired_subscriptions', | |
| 'schedule': 5.0, # Runs in every 5 seconds | |
| #'schedule': crontab(minute=5) # Runs in every 5 minutes | |
| #'args': (arg_1, arg_2, ...), # Run the function with arguments | |
| }, | |
| } |
This file contains hidden or 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
| @app.task( | |
| name='send-email-to-user', | |
| default_retry_delay=300, | |
| max_retry=5, | |
| soft_time_limit=30 | |
| ) | |
| def send_email_to_user( | |
| user_email: str, | |
| email_template: str, | |
| extra_info: dict |
This file contains hidden or 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 logging | |
| import datetime | |
| import smtplib | |
| import ssl | |
| from typing import Optional | |
| from celery import Celery | |
| #from celery.schedules import crontab | |
| REDIS_BASE_URL = 'redis://localhost:6379' |
This file contains hidden or 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
| # src/helpers/config_helper.py | |
| import os | |
| import logging | |
| from typing import Literal, Optional, Union | |
| from functools import lru_cache | |
| from pydantic import BaseSettings, HttpUrl, SecretStr, validator, StrictInt | |
| from dotenv import dotenv_values | |
| class Settings(BaseSettings): |
This file contains hidden or 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
| Filename: example_2.py | |
| Line # Mem usage Increment Occurences Line Contents | |
| ============================================================ | |
| 3 18.6 MiB 18.6 MiB 1 @profile | |
| 4 def wasteful_sum_function() -> int: | |
| 5 19.1 MiB 0.5 MiB 10003 return sum([x**2 for x in range(10**4)]) | |
| Filename: example_2.py | |
| Line # Mem usage Increment Occurences Line Contents | |
| ============================================================ |
This file contains hidden or 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
| from memory_profiler import profile | |
| @profile | |
| def wasteful_sum_function() -> int: | |
| return sum([x**2 for x in range(10**4)]) | |
| @profile | |
| def resource_efficient_sum_function() -> int: | |
| return sum((x**2 for x in range(10**4))) |
This file contains hidden or 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 timeit | |
| import requests | |
| from bs4 import BeautifulSoup | |
| def get_word_count_of(url: str) -> int: | |
| res = requests.get(url) | |
| if res.status_code == 200: | |
| _data = res.text | |
| return count_words(_data) | |
| return 0 |
This file contains hidden or 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 requests | |
| from bs4 import BeautifulSoup | |
| def get_word_count_of(url: str) -> int: | |
| res = requests.get(url) | |
| if res.status_code == 200: | |
| _data = res.text | |
| return count_words(_data) | |
| return 0 |
This file contains hidden or 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 cProfile | |
| from math import sqrt | |
| BIG_NUMBER = 10**25 | |
| def slow_function(n: int) -> None: | |
| for _ in range(10**5): | |
| sqrt(n) | |
| def fast_function(n: int) -> None: |