Skip to content

Instantly share code, notes, and snippets.

View Akuma-U1's full-sized avatar
:octocat:
When is my coffee break

Johan Langenhoven Akuma-U1

:octocat:
When is my coffee break
  • Bob Group
  • Pretoria, South Africa
View GitHub Profile
@Akuma-U1
Akuma-U1 / db_listener.py
Last active September 13, 2023 13:15
Postgres DB Listener in Python with exponential backoff - asyncpg and asyncio
import asyncio
import asyncpg
async def listen_for_notifications():
backoff_times = [1, 2, 4, 8, 16] # Backoff times in seconds
backoff_counter = 0
while True:
try:
conn: asyncpg.Connection = await asyncpg.connect(
@Akuma-U1
Akuma-U1 / lru_cache.ts
Last active February 10, 2023 13:27
LRU Cache implementation in Typescript
class LRU_Cache<T> extends Map<string,T> {
private _limit: number;
constructor(limit: number, entries?: [string, T][]) {
super(entries);
this._limit = limit;
}
get(key: string) {
const hasKey = this.has(key);
if (!hasKey) return;