Skip to content

Instantly share code, notes, and snippets.

View PaulisMatrix's full-sized avatar
🏠
Working from home

rushikesh PaulisMatrix

🏠
Working from home
View GitHub Profile
@ceberly
ceberly / Makefile
Last active November 13, 2023 17:31
Row vs. Column access patterns
default:
gcc -O0 -g3 -Wall -Wextra -Wconversion -Wdouble-promotion \
-Wno-unused-parameter -Wno-unused-function -Wno-sign-conversion \
main.c
format:
clang-format -i main.c
@sancar
sancar / README.md
Last active May 23, 2024 09:33
An upgradable read write lock for go

And upgradable read write lock for go

UpgradableRWMutex is an enhanced version of the standard sync.RWMutex. It has the all methods sync.RWMutex with exact same semantics. It gives more methods to give upgradable-read feature.

The new semantics for upgradable-read are as follows:

  • Multiple goroutines can get read-lock together with a single upgradable-read-lock.
  • Only one goroutine can have a write-lock and no read-lock/upgradable-read-lock can be acquired in this state.
@debasishg
debasishg / cache-oblivious.md
Last active July 8, 2024 16:19
Papers related to cache oblivious data structures

Cache Oblivious and Cache Aware Data Structure and Algorithms

  1. Cache-Oblivious Algorithms and Data Structures - Erik Demaine (One of the earliest papers in cache oblivious data structures and algorithms that introduces the cache oblivious model in detail and examines static and dynamic cache oblivious data structures built between 2000-2003)

  2. Cache Oblivious B-Trees - Bender, Demaine, Farch-Colton (This paper presents two dynamic search trees attaining near-optimal performance on any hierarchical memory. One of the fundamental papers in the field where both search trees discussed match the optimal search bound of Θ(1+log (B+1)N) memory transfers)

  3. Cache Oblivious Search Trees via Binary Trees of Small Height - Brodal, Fagerberg, Jacob (The data structure discussed in this paper works on the version of [2] but avoids the use o

@IshaanAdarsh
IshaanAdarsh / GSoC ’23 Project-Report.md
Last active March 18, 2024 09:19
Google Summer of Code 2023 (PostgreSQL)

Google Summer of Code 2023 Final Work Product


gsoc


Introduction

@Jarmos-san
Jarmos-san / Dockerfile
Last active April 15, 2024 02:21
An example multi-stage Dockerfile for use Python's poetry package manager
# Set the working directory globally
ARG SOURCEDIR="app"
# Pin the Python version to use
# See the following article to learn more about choosing the right base image
# https://pythonspeed.com/articles/base-image-python-docker-images
ARG PYTHONVERSION="3.11-slim-bookworm"
# Createh the base image for generating the requirements file
FROM python:${PYTHONVERSION} AS builder
@francbartoli
francbartoli / demo.py
Created June 2, 2019 12:48 — forked from wshayes/demo.py
[Websocket demo for fastapi] example of broadcast using websockets for fastapi #fastapi #websockets
# From https://github.com/tiangolo/fastapi/issues/258
from typing import List
from fastapi import FastAPI
from starlette.responses import HTMLResponse
from starlette.websockets import WebSocket, WebSocketDisconnect
app = FastAPI()
@antirez
antirez / lmdb.tcl
Created April 28, 2017 15:40
LMDB -- First version of Redis written in Tcl
# LVDB - LLOOGG Memory DB
# Copyriht (C) 2009 Salvatore Sanfilippo <antirez@gmail.com>
# All Rights Reserved
# TODO
# - cron with cleanup of timedout clients, automatic dump
# - the dump should use array startsearch to write it line by line
# and may just use gets to read element by element and load the whole state.
# - 'help','stopserver','saveandstopserver','save','load','reset','keys' commands.
# - ttl with milliseconds resolution 'ttl a 1000'. Check ttl in dump!

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.