Skip to content

Instantly share code, notes, and snippets.

View Ankitcode99's full-sized avatar
:octocat:
Focusing

Ankit Pandey Ankitcode99

:octocat:
Focusing
View GitHub Profile
@Ankitcode99
Ankitcode99 / complexDaggerExample.java
Created September 18, 2025 06:42
Dagger Framework Examples
import dagger.Component;
import dagger.Module;
import dagger.Provides;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
// Complex Car with deep dependency chains
class ComplexCar {
private final Engine engine;
@Ankitcode99
Ankitcode99 / goChannel.md
Last active October 14, 2024 20:35
Go Thread Pool & Notes
  1. Channel Operations and Goroutine Scheduling

    When a goroutine performs a channel operation (send or receive) that cannot complete immediately, the Go runtime automatically handles the suspension and resumption of the goroutine. This is part of Go's built-in concurrency model.

for job := range pool.jobQueue {
    job(workerID)
}
@Ankitcode99
Ankitcode99 / concurrentQueue.go
Created October 14, 2024 19:51
A thread safe queue
package main
import (
"log"
"math/rand"
"sync"
)
type ConcurrentQueue struct {
queue []int32
@Ankitcode99
Ankitcode99 / goTcpServer.go
Created October 13, 2024 18:33
Resource efficient multithreaded TCP server in golang
package main
import (
"fmt"
"log"
"net"
"sync"
"time"
)
@Ankitcode99
Ankitcode99 / PM2-IPC.ts
Last active April 12, 2024 10:44
A simple implementation of caching and IPC among pm2 workers.
import fastify, { FastifyReply, FastifyRequest } from "fastify";
import pm2 from "pm2";
import { MyCache } from "./cache";
const app = fastify({logger: true, disableRequestLogging: true});
// const NodeCache = require( "node-cache" );
// const myCache = new NodeCache( { stdTTL: 3600, checkperiod: 120 } );
const myCache = new MyCache({ttl:3600, evictionDuration: 60);
function sendDataToPartners(currentPid: number, key: number, value:number) {
pm2.connect(err=>{
@Ankitcode99
Ankitcode99 / webCrawler.go
Created March 25, 2024 07:10
Basic Web Crawler in golang
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
@Ankitcode99
Ankitcode99 / consistentHashing.js
Last active February 24, 2024 05:05
Consistent Hashing Implementation for a K-V Database
const { v4: uuidv4 } = require("uuid");
let consistentHashingRing = [];
const RING_SIZE = 131;
const MOD = 131;
const MODD = 1000000 + 3;
let primeArr = [];
let primeNum = 31;
let REPLICATION_FACTOR = 3;
let serversLocation = new Set();
@Ankitcode99
Ankitcode99 / Sliding-Window-Ratelimiter.js
Created November 22, 2023 16:49
A simple implementation of sliding window rate limiter using Redis.
const express = require('express');
const redis = require('redis');
const app = express();
const PORT = 3000;
const redisClient = redis.createClient({
host: 'localhost',
port: 6379,
});