Skip to content

Instantly share code, notes, and snippets.

View smetam's full-sized avatar
🐳

Aleksandr Smetanin smetam

🐳
  • @PicnicSupremarket
  • Amsterdam
  • LinkedIn in/smetam
View GitHub Profile
@smetam
smetam / ttl_cache.py
Created March 1, 2023 17:29
How to use lru_cache with time to live with any function in pure python
import datetime
import time
from functools import lru_cache, wraps
def get_ttl_hash():
"""Return the same value withing time period"""
now = datetime.datetime.now()
# Here value changes every minute, but it can be anything: day, 5 hours, etc.
return now.minute
@smetam
smetam / plane_reservations.sc
Created November 29, 2021 11:21
Plane Seats Reservations (Scala)
case class Seat(row: Int, letter: Char)
object Seat {
def from_string(s: String): Seat = {
val split_position = s.length - 1
val (row, letter) = s.splitAt(split_position)
Seat(row.toInt, letter.head)
}
}