Skip to content

Instantly share code, notes, and snippets.

View ruohola's full-sized avatar

Eero Ruohola ruohola

View GitHub Profile
import asyncio
import random
import time
async def producer(queue):
while True:
await asyncio.sleep(2)
await queue.put(random.randint(1, 100))
use num::{Integer, One};
use std::collections::HashMap;
use std::hash::Hash;
struct CachedFib<T> {
memory: HashMap<T, T>,
}
impl<T> CachedFib<T>
where
use num::{Integer, One};
use std::collections::HashMap;
use std::hash::Hash;
fn fib<T>(n: T) -> T
where
T: std::fmt::Debug + Copy + Hash + Integer,
{
fn fib_memory<T>(n: T, memory: &mut HashMap<T, T>) -> T
where
@ruohola
ruohola / CMakeLists.txt
Created June 8, 2019 18:12
CMakeList for running Qt project in CLion
cmake_minimum_required(VERSION 3.14)
project(projectname)
set(CMAKE_CXX_STANDARD 17)
# Needed for Qt
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
include_directories(.)
@ruohola
ruohola / timer.py
Last active June 3, 2020 15:16
Timer to use as a decorator to time the execution of any Python function
from functools import wraps
from time import perf_counter
from typing import Any, Callable, Optional, TypeVar, cast
F = TypeVar("F", bound=Callable[..., Any])
def timer(prefix: Optional[str] = None, precision: int = 6) -> Callable[[F], F]:
"""Use as a decorator to time the execution of any function.