Skip to content

Instantly share code, notes, and snippets.

View rakeshopensource's full-sized avatar

Rakesh Rathi rakeshopensource

View GitHub Profile
@rakeshopensource
rakeshopensource / LSMTreeDriver.java
Last active September 15, 2023 09:24
Explore How NoSQL databases work with simple Java simulation of LSM trees. This lets you see how data storage and retrieval happens, all running in-memory for easy learning and experimentation. Get a hands-on understanding of LSM trees without the complexity of disk storage.
package org.rakeshopensource.systemdesign;
import java.util.*;
import java.util.function.Function;
class MemTable<K, V> {
private final Map<K, V> data;
public MemTable() {
data = new HashMap<>();
@rakeshopensource
rakeshopensource / ConsistentHashing.java
Last active September 17, 2023 12:04
Explore the functioning of Consistent Hashing with a straightforward Java in-memory simulation. This simulation not only incorporates the core concept of Consistent Hashing but also encompasses key features such as data redistribution when nodes are added or removed, and the ability to serve data from replicas in the event of node crashes.
org.rakeshopensource.systemdesign
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class ConsistentHashing<K, V> {
public static class Details<K, V> {
K node, key;
V value;
@rakeshopensource
rakeshopensource / TimeBasedOnetimePassword.java
Created September 22, 2023 10:22
The Time-Based One-Time Password (TOTP) algorithm stands as a prevalent technique for producing single-use codes, pivotal for two-factor authentication and enhancing security protocols. For a practical dive into its workings, I've written custom implementation in java.
package org.rakeshopensource.systemdesign;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.util.stream.IntStream;
public class TimeBasedOnetimePassword {
@rakeshopensource
rakeshopensource / video_streaming_server.py
Last active September 29, 2023 17:47
This handles video streaming and transcoding using FFmpeg. It listens for incoming video streams, transcodes them into different resolutions (720p and 1080p), and generates an HLS (HTTP Live Streaming) playlist file (master.m3u8) that references the transcoded video segments.
import os
import subprocess
import threading
from fastapi import FastAPI
from starlette.responses import Response
from threading import Lock
app = FastAPI()
lock = Lock()
package org.rakeshopensource.consistenthashing;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class ConsistentHashingV2<K, V> {
public static class Details<K, V> {
K node, key;
V value;