Skip to content

Instantly share code, notes, and snippets.

@superdev7788
superdev7788 / SkipList.py
Created August 24, 2025 15:48
skip list - A probabilistic data structure
import random
from typing import Optional, Any, List, Tuple
class SkipListNode:
"""Node in the skip list containing key-value pair and forward pointers"""
def __init__(self, key: Any, value: Any, level: int):
self.key = key
self.value = value
@superdev7788
superdev7788 / pub-sub.py
Created August 25, 2025 06:41
Demonstration of Pub/Sub communication pattern
class Broker:
def __init__(self):
# A dictionary to store topics and their subscribers
# key: topic (string), value: set of subscriber callback functions
self.subscribers = {}
def subscribe(self, topic, callback):
"""Adds a new subscriber to a topic."""
# If the topic doesn't exist, create an empty set for it
if topic not in self.subscribers:
@superdev7788
superdev7788 / event-com.py
Created August 25, 2025 06:50
Event-Driven Communication
class EventBus:
def __init__(self):
# A dictionary to store event types and their listener functions
# key: event_type (string), value: list of listener functions
self.listeners = {}
def on(self, event_type, listener):
"""Registers a listener for a specific event type."""
if event_type not in self.listeners:
self.listeners[event_type] = []
@superdev7788
superdev7788 / MD5Hash.py
Created September 19, 2025 13:57
Implementation of MD5 Hash in Python
import struct
import math
class SimpleMD5:
def __init__(self):
# MD5 constants
self.h = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476]
# Pre-computed sine values for MD5 rounds
@superdev7788
superdev7788 / SHA256Hash.py
Created September 19, 2025 14:12
Sample implementation of SHA256 Hash Algorithm in Python
import struct
from typing import List, bytes as Bytes
class SHA256:
"""
A complete implementation of SHA-256 hash algorithm.
This implementation is for educational purposes and to understand
the inner workings of SHA-256. For production use, always use
the hashlib library which is optimized and thoroughly tested.
import os
import hmac
import hashlib
import struct
import base64
from typing import bytes as Bytes, Tuple, List
import time
import secrets
class SimpleBcrypt: