Skip to content

Instantly share code, notes, and snippets.

View maksadbek's full-sized avatar
💭
Chilling

maksadbek

💭
Chilling
View GitHub Profile
sets = [[i] for i in range(len(nums))]
parent = [i for i in range(len(nums))]
def union(a, b):
set_a = parent[a]
set_b = parent[b]
if set_a == set_b:
return

Geo sharding

Shard Space

Like redis cluster, we'll use a shard space of 2^14 = 16384. Essentially what this means is that we'll take our entire geo area, and split it into 16384 segments of approximately equal entries.

Each instance will be responsible for any number of segments, typically a cluster of segments that are geographically close.

Searches

@maksadbek
maksadbek / modern_python_dictionaries.py
Created January 19, 2022 17:22 — forked from gerrymanoim/modern_python_dictionaries.py
Code from Modern "Python Dictionaries A confluence of a dozen great ideas - Raymond Hettinger"
import array
import collections
import itertools
# Placeholder constants
FREE = -1
DUMMY = -2
class Dict(collections.MutableMapping):
'Space efficient dictionary with fast iteration and cheap resizes.'
@maksadbek
maksadbek / lisp.cpp
Created August 30, 2021 19:36 — forked from ofan/lisp.cpp
Lisp interpreter in 90 lines of C++
Lisp interpreter in 90 lines of C++
I've enjoyed reading Peter Norvig's recent articles on Lisp. He implements a Scheme interpreter in 90 lines of Python in the first, and develops it further in the second.
Just for fun I wondered if I could write one in C++. My goals would be
1. A Lisp interpreter that would complete Peter's Lis.py test cases correctly...
2. ...in no more than 90 lines of C++.
Although I've been thinking about this for a few weeks, as I write this I have not written a line of the code. I'm pretty sure I will achieve 1, and 2 will be... a piece of cake!
@maksadbek
maksadbek / primes.go
Created March 13, 2021 23:46
Calculate primes using Doug McIlroy's idea: http://swtch.com/~rsc/thread/
package main
import "sync"
func primes() {
var recur func(ch chan int)
wg := sync.WaitGroup{}
recur = func(ch chan int) {
p := <-ch
package main
import (
"time"
"fmt"
"context"
"sync"
)
func web() string {
@maksadbek
maksadbek / 1.srp.py
Created December 12, 2020 03:25 — forked from dmmeteo/1.srp.py
SOLID Principles explained in Python with examples.
"""
Single Responsibility Principle
“…You had one job” — Loki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
"""
class Animal:
def __init__(self, name: str):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
create table model(
id serial primary key,
name text,
tags text[]
);
insert into model(name, tags) values ('a', array['a', 'b', 'c']);
insert into model(name, tags) values ('b', array['b', 'b', 'c']);
select unnest(tags) as tag, count(*) from model group by tag;
def tushar(string, pattern):
dp = [[False] * (len(pattern) + 1) for _ in range(len(string) + 1)]
dp[0][0] = True
for i in range(1, len(pattern)+1):
if pattern[i-1] == "*":
dp[0][i] = dp[0][i-2]
for i in range(1, len(string)+1):
for j in range(1, len(pattern)+1):