This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import random | |
import time | |
async def producer(queue): | |
while True: | |
await asyncio.sleep(2) | |
await queue.put(random.randint(1, 100)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use num::{Integer, One}; | |
use std::collections::HashMap; | |
use std::hash::Hash; | |
struct CachedFib<T> { | |
memory: HashMap<T, T>, | |
} | |
impl<T> CachedFib<T> | |
where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |