Skip to content

Instantly share code, notes, and snippets.

View maksadbek's full-sized avatar
💭
Chilling

Maksadbek 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
@maksadbek
maksadbek / nginx.conf
Created January 3, 2017 17:51
nginx configuration for HLS live video streaming
worker_processes 1;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
allow play all;

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 / golang-linked-list.go
Created April 27, 2016 21:43
golang linked list implementation
package main
import "fmt"
type Node struct {
prev *Node
next *Node
key interface{}
}
@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>