Skip to content

Instantly share code, notes, and snippets.

View maksadbek's full-sized avatar
💭
Chilling

Maksadbek maksadbek

💭
Chilling
View GitHub Profile
View Geo Based Sharding.md

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"
View modern_python_dictionaries.py
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++
View lisp.cpp
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/
View primes.go
package main
import "sync"
func primes() {
var recur func(ch chan int)
wg := sync.WaitGroup{}
recur = func(ch chan int) {
p := <-ch
View reddit.go
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.
View 1.srp.py
"""
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):
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
View postgresql.sql
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;
View gist:a687c9f4cd8ef496b45b05ebb070d92a
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):
View stack.go
package main
import (
"fmt"
)
type item struct {
value interface{} //value as interface type to hold any data type
next *item
}