Skip to content

Instantly share code, notes, and snippets.

@abbasEbadian
abbasEbadian / countries.json
Created May 27, 2024 14:04
List of countries with name, code, area code and emoji in json. A composition of @anubhavshrimal gist and @npm/country-flag-emoji-json.
[{
"name": "Afghanistan",
"area_code": "+93",
"code": "AF",
"emoji": "🇦🇫",
"unicode": "U+1F1E6 U+1F1EB",
"image": "https://cdn.jsdelivr.net/npm/[email protected]/dist/images/AF.svg"
}, {
"name": "Åland Islands",
"area_code": "+358",
@abbasEbadian
abbasEbadian / traverse.py
Last active August 23, 2021 13:20
Python Tree Traversal - BFS and DFS( inorder - preorder - postorder )
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def __repr__(self):
return str(self.value)
class Tree:
def __init__(self):
self.root = Node(0)
@abbasEbadian
abbasEbadian / find_jalaali_holdays
Created August 15, 2021 06:35
پیدا کردن روزهای تعطیل تقویم با پایتون - Get holidays of jalali calendar
##################################
# author: [email protected] #
##################################
import requests
import datetime, jdatetime
today = datetime.datetime.now()
eid = datetime.datetime(2022, 3, 20) # 29 esfand 1400
dates = []
@abbasEbadian
abbasEbadian / SJF - nonPreemptive.py
Last active May 12, 2021 11:35
Non Preemptive SJF easy to understnad implementation with Python
# Check if all tasks have been executed
def check_all_done(tasks):
all_done = True
for task in tasks:
if tasks[task]["duration"] >0 :
all_done = False
break
return all_done
# Get the task with shortest remainig service time (duration)
@abbasEbadian
abbasEbadian / gist:a59a0fd6504be087a94ed778af7a66a5
Last active April 28, 2021 08:00
Convert any number from base r1 to base r2 in python where r1, r2 in [2, 36]
def change_base(n, r1, r2):
if n == 0:
return 0
n = to_base10(n, r1)
digits = ""
while n:
digit = int(n % r2)
if digit > 9:
digit = str(chr(65+digit-10))
digits += str(digit)