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 socket | |
def check_domain_exists(domain): | |
try: | |
socket.gethostbyname(domain) | |
return True | |
except socket.gaierror: | |
return False |
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 random | |
orginal_pin = int(input("Enter your 4 digits pin: ")) | |
attempts = 0 | |
while True: | |
# Generate a random 4-digit number | |
pin = random.randint(1000, 9999) | |
attempts += 1 | |
if orginal_pin == pin: |
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 time | |
import multiprocessing as mp | |
import psutil | |
from typing import Any, Callable, List, Tuple | |
def monitor(target: Callable[..., Any], args: Tuple[Any, ...]) -> List[float]: | |
worker_process = mp.Process(target=target, args=args) | |
worker_process.start() | |
p = psutil.Process(worker_process.pid) |
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 schedule | |
import time | |
def print_notification(message): | |
print(message) | |
# Schedule a reminder to be sent every day at 9am | |
schedule.every().day.at('09:00').do(print_notification, message='Remember to take your medication!') | |
# Loop to run scheduled tasks |
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 psutil | |
# Get the current memory usage of the server | |
mem = psutil.virtual_memory() | |
# Print the current memory usage | |
print(f"Current Memory Usage: {mem.used} bytes") | |
# Increase the memory by 2 GB | |
new_mem = mem.total + 2 * 1024 * 1024 * 1024 | |
# Set the new memory value | |
psutil.virtual_memory().total = new_mem |
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 psutil | |
# Measure CPU utilization | |
cpu_utilization = psutil.cpu_percent() | |
print("CPU utilization:", cpu_utilization) | |
# Measure memory usage | |
memory_usage = psutil.virtual_memory().percent | |
print("Memory usage:", memory_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
# Problem Set: 1 | |
x = 121 | |
# x = -121 | |
# x = 10 | |
def is_plaindrom(x): | |
strs = str(x) | |
l,r = 0, len(strs) -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
# coding=utf8 | |
import PIL | |
from PIL import ImageFont | |
from PIL import Image | |
from PIL import ImageDraw | |
def text2png(text, fullpath, color = "#000", bgcolor = "#FFF", fontfullpath = None, fontsize = 13, leftpadding = 3, rightpadding = 3, width = 200): | |
REPLACEMENT_CHARACTER = u'\uFFFD' | |
NEWLINE_REPLACEMENT_STRING = ' ' + REPLACEMENT_CHARACTER + ' ' |
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 pafy | |
import os | |
os.environ["PAFY_BACKEND"] = "internal" | |
PAFY_BACKEND = "internal" | |
url = input(" > Enter youtube video url: ") | |
video = pafy.new(url) |
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 check_na(prev_dict): | |
new_dict = {key:val for key, val in prev_dict.items() if val != 'NA'} | |
return new_dict | |
def parse_na(payload): | |
fake_payload = {} | |
for k, v in payload.items(): | |
if isinstance(v,dict): | |
fake_payload[k] = check_na(v) | |
else: |