Skip to content

Instantly share code, notes, and snippets.

View anilpai's full-sized avatar
:octocat:
Coding

Anil Pai anilpai

:octocat:
Coding
View GitHub Profile
@anilpai
anilpai / references.txt
Last active March 22, 2024 16:28
Grokking Advanced System Design LInks
Dynamo: How to Design a Key-value Store?
Amazon’s Dynamo : https://www.allthingsdistributed.com/2007/10/amazons_dynamo.html
Eventually Consistent : https://www.allthingsdistributed.com/2007/12/eventually_consistent.html
Bigtable : https://research.google/pubs/pub27898/
DynamoDB : https://www.allthingsdistributed.com/2012/01/amazon-dynamodb.html
CRDT : https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type
A Decade of Dynamo : https://www.allthingsdistributed.com/2017/10/a-decade-of-dynamo.html
Riak : https://docs.riak.com/riak/kv/2.2.0/learn/dynamo/
Dynamo Architecture : https://www.youtube.com/watch?v=w96lLsbI1q8
@anilpai
anilpai / currency_arbitrage.py
Created September 18, 2019 06:33
Currency Arbitrage using Bellman Ford Algorithm
from typing import Tuple, List
from math import log
rates = [
[1, 0.23, 0.25, 16.43, 18.21, 4.94],
[4.34, 1, 1.11, 71.40, 79.09, 21.44],
[3.93, 0.90, 1, 64.52, 71.48, 19.37],
[0.061, 0.014, 0.015, 1, 1.11, 0.30],
[0.055, 0.013, 0.014, 0.90, 1, 0.27],
[0.20, 0.047, 0.052, 3.33, 3.69, 1],
@anilpai
anilpai / currency_arbitrage.py
Created June 3, 2019 17:12
Currency Arbitrage using Bellman Ford Algorithm
from typing import Tuple, List
from math import log
rates = [
[1, 0.23, 0.26, 17.41],
[4.31, 1, 1.14, 75.01],
[3.79, 0.88, 1, 65.93],
[0.057, 0.013, 0.015, 1],
]
/* Priority Queue based Heap implementation in TypeScript */
class BinaryHeap<T> {
private heapArray: T[] = [];
constructor(private lessThan: (a:T, b:T) => boolean) {
}
size() {
return this.heapArray.length;
@anilpai
anilpai / time_series.py
Last active June 26, 2023 12:07
Generate Time Series based on trip intervals data
import heapq as hq
def generate_time_series(trips):
trips.sort(key=lambda x: (x[0], x[1]))
series = {}
minStartTime = []
for trip in trips:
if minStartTime and minStartTime[0] <= trip[0]:
@anilpai
anilpai / ldap.py
Created March 19, 2018 19:27
Python code to connect to LDAP server and authenticate a user.
import ldap3
class Ldap:
"""Class for LDAP related connections/operations."""
def __init__(self, server_uri, ldap_user, ldap_pass):
self.server = ldap3.Server(server_uri, get_info=ldap3.ALL)
self.conn = ldap3.Connection(self.server, user=ldap_user, password=ldap_pass, auto_bind=True)
def who_am_i(self):
@anilpai
anilpai / node_rank.py
Last active May 1, 2021 01:59
Compute current rank of a node in a stream
# Computing current rank of a node in a stream
class Node:
def __init__(self, val, left=None, right=None, left_size=0):
self.val = val
self.left = left
self.right = right
self.left_size = left_size
class Solution:
@anilpai
anilpai / rank_node_2.py
Created April 28, 2021 19:42
Computing Rank of a node in a stream
# Computing Rank of a node in a stream
"""Source: https://www.geeksforgeeks.org/rank-element-stream """
class Node:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
self.left_size = 0
@anilpai
anilpai / klarna.js
Created March 30, 2021 07:06
Find Duplicate transactions
function findDuplicateTransactions (transactions = []) {
transactions.sort((a, b) => new Date(a.time) - new Date(b.time));
let duplicates = []
let match = []
let src, dst;
while(transactions.length > 1){
src = 0
dst = 1
match = [src]
@anilpai
anilpai / index.ts
Created March 27, 2021 08:08
TypeScript
type Salutation = {greeting: string, name: string}
/**
* @param {Salutation}
* @return {string}
*/
function greet1({greeting, name}: Salutation):string{
return `${greeting}, ${name}`
}