Skip to content

Instantly share code, notes, and snippets.

View bhuiyanmobasshir94's full-sized avatar
🎖️
Focused on achievement

Mobasshir Bhuiya bhuiyanmobasshir94

🎖️
Focused on achievement
View GitHub Profile
import socket
def check_domain_exists(domain):
try:
socket.gethostbyname(domain)
return True
except socket.gaierror:
return False
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:
@bhuiyanmobasshir94
bhuiyanmobasshir94 / print_cpu_usage.py
Last active April 28, 2023 02:40 — forked from rkaneko/print_cpu_usage.py
Profile CPU usage in Python using psutil.
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)
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
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
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)
# Problem Set: 1
x = 121
# x = -121
# x = 10
def is_plaindrom(x):
strs = str(x)
l,r = 0, len(strs) -1
@bhuiyanmobasshir94
bhuiyanmobasshir94 / text2png.py
Created September 3, 2022 07:30 — forked from destan/text2png.py
Python text to image (png) conversion with automatic new line calculation
# 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 + ' '
import pafy
import os
os.environ["PAFY_BACKEND"] = "internal"
PAFY_BACKEND = "internal"
url = input(" > Enter youtube video url: ")
video = pafy.new(url)
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: