Skip to content

Instantly share code, notes, and snippets.

View rakeshopensource's full-sized avatar

Rakesh Rathi rakeshopensource

View GitHub Profile
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;
@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()
@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 / 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 / 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 / BloomFilter.java
Created September 14, 2023 16:02
Simple, basic Bloom filter simulation in Java that uses multiple hash functions to efficiently test if an element might be in a set.
package org.rakeshopensource.systemdesign;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.function.Function;
public class BloomFilter <T> {
private final int size;
private final BitSet bitSet;
@rakeshopensource
rakeshopensource / SingleThreadedHttpServer.java
Created September 14, 2023 15:57
Sample basic single threaded event loop in java implemented using non-blocking IO
package org.rakeshopensource.systemdesign;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
@rakeshopensource
rakeshopensource / googlesearch.go
Last active January 12, 2019 08:52
Fake google search example in Go using concurrent Go routines.
package main
import (
"fmt"
"math/rand"
"time"
)
var (
Web = fakeSearch("web")
@rakeshopensource
rakeshopensource / faninseq.go
Last active January 12, 2019 05:27
Go Fan In and Restoring Sequence
package main
import (
"fmt"
"math/rand"
"time"
)
type Message struct {
msg string
@rakeshopensource
rakeshopensource / MapDemo.java
Created April 5, 2018 08:29
Map Sorting using java8 stream api
package com.rakesh;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;