Skip to content

Instantly share code, notes, and snippets.

View ktbarrett's full-sized avatar

Kaleb Barrett ktbarrett

  • Hudson River Trading
  • Boulder, CO
View GitHub Profile
@ktbarrett
ktbarrett / channel.py
Last active October 26, 2021 15:32
Broadcasting channels with inline stream processing and events in Python
from abc import ABCMeta, abstractmethod, abstractproperty
from asyncio import QueueEmpty
from collections import deque
from typing import (
Callable,
Deque,
Generic,
Protocol,
Set,
Type,
@ktbarrett
ktbarrett / alert.py
Created October 25, 2021 04:10
recurring event type
from typing import Awaitable
from cocotb.triggers import Trigger, _Event
class Alert(Awaitable[None]):
def __init__(self) -> None:
self._pending = []
def set(self) -> None:
* simulator control (enums or separate functions?)
* SHUTDOWN
* RESTART (new addition)
* logging
* levels
* TRACE
* DEBUG
* INFO
@ktbarrett
ktbarrett / generic_FF.vhd
Last active December 13, 2021 16:33
VHDL type-generic entities and subprograms
-- package containing a type-generic D Flip Flop
-- may not be 100% valid VHDL code, contact ktbarrett on gitter
-- non-generic version does synthesize correctly
package generic_pkg is
procedure generic_FF
generic (
constant T: type)
paramater (
signal q : out T;
@ktbarrett
ktbarrett / main.py
Created February 24, 2022 03:33 — forked from mypy-play/main.py
Shared via mypy Playground
from typing import *
K_contra = TypeVar("K_contra", contravariant=True)
K_co = TypeVar("K_co", covariant=True)
V_co = TypeVar("V_co", covariant=True)
V = TypeVar("V")
T = TypeVar("T")
class ContravariantMapping(Protocol[K_contra, V_co]):
def __getitem__(self, __key: K_contra) -> V_co: ...
from collections import deque
from typing import Deque, Generic, Optional, TypeVar
from cocotb.triggers import Event
T = TypeVar("T")
class RecvFailed(Exception):
...
from typing import Awaitable, Generic, TypeVar
from cocotb.triggers import Event
T = TypeVar("T")
class Signal(Generic[T]):
def __init__(self, __init_value: T) -> None:
@ktbarrett
ktbarrett / example1.py
Last active April 10, 2023 19:48
Join blocks
async def test(dut):
with TaskManager() as tm:
@tm.fork
async def stimulate():
pass # stimulate an interface
@tm.fork
@ktbarrett
ktbarrett / example.vhd
Created July 22, 2022 16:11
Example initial block
entity piecewise_function is
generic (
NODE_MAP : NodeMapType;
NODE_ID : string;
NUM_SEGMENTS : natural;
THRESHOLD_SIZE_RES : sfixed;
BIAS_SIZE_RES : sfixed;
GAIN_SIZE_RES : sfixed);
port (
@ktbarrett
ktbarrett / generic_ff_pack.vhd
Created July 26, 2022 16:43
Generic FF procedure
library ieee;
use ieee.std_logic_1164.all;
package generic_ff_pack is
procedure FF
generic (
type T)
parameter (
signal q : out T;
constant d : in T;