Skip to content

Instantly share code, notes, and snippets.

/*
Original problem from LeetCode: Course Schedule II
Leetcode Link: https://leetcode.com/problems/course-schedule-ii/
*/
// Approach-1 (Using BFS Topological Sort Concept)
import java.util.*;
class Solution {
// Using Kahn's algorithm
//Credits: https://medium.com/@surajshende247/token-bucket-algorithm-rate-limiting-db4c69502283
import { CronJob } from 'cron';
import express from 'express';
const app = express();
app.use(express.json());
const PORT = process.env.PORT || 5000;
@tarunjain07
tarunjain07 / Locks.java
Created August 26, 2024 08:32
Distributed Lock using Zookeeper
package org.example;
import org.apache.zookeeper.*;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
public class Locks {
static ZooKeeper zooKeeper;
@tarunjain07
tarunjain07 / AWS_ALB_vs_APIGateway
Last active March 27, 2025 05:17
AWS ALB vs API Gateway
| AWS | |
| -------------------------------------------------------------------------------- |-----------------------------------------------------------------------------|
| API Gateway | ALB |
| Manages the routing and processing of API requests from clients | Distributes incoming traffic across multiple instances of service |
| Can implement rate limiting, bursting for APIs | No rate limiting, bursting capability |
| Not possible to get a static IP addresss for endpoint (always a URL) | Possible to get a static IP address for load balancer endpoint |
| Accepts HTTPS traffic
/* Producer Consumer */
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define BUF_SIZE 3 /* Size of shared buffer */
int buffer[BUF_SIZE]; /* shared buffer */
int add = 0; /* place to add next element */
/* PThread Creation Quiz 3 */
#include <stdio.h>
#include <pthread.h>
#define NUM_THREADS 4
void *threadFunc(void *pArg) { /* thread main */
int myNum = *((int*)pArg);
printf("Thread number %d\n", myNum);
/* A Slightly Less Simple PThreads Example */
#include <stdio.h>
#include <pthread.h>
#define NUM_THREADS 4
void *threadFunc(void *pArg) { /* thread main */
int *p = (int*)pArg;
int myNum = *p;
/* PThread Creation Quiz 1 */
#include <stdio.h>
#include <pthread.h>
#define NUM_THREADS 4
void *hello (void *arg) { /* thread main */
printf("Hello Thread\n");
return 0;
/* PThread Creation */
#include <stdio.h>
#include <pthread.h>
void *foo (void *arg) { /* thread main */
printf("Foobar!\n");
pthread_exit(NULL);
}
from __future__ import print_function
from threading import Thread
from datetime import datetime
def sum(results, thread_id, SUM_RANGE):
print(thread_id, SUM_RANGE)
sum = i = 0
start = thread_id * SUM_RANGE