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
`timescale 1ns / 1ps | |
`default_nettype none | |
module fifo #( | |
parameter WIDTH = 32, | |
parameter DEPTH = 1024, | |
parameter SKID = 0, | |
parameter GEN_EXCEPTIONS = 1, | |
parameter GEN_CONSENTS = 1 |
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 collections import Counter as Multiset | |
def multiset_combinations(ms, n): | |
assert sum(ms.values()) >= n | |
def f(ms_res, curr_val, ms_rem): | |
nonlocal n | |
if sum(ms_res.values()) == n: #ideally len would return the number of total elements | |
yield ms_res | |
else: |
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
def Parameterize(cls, *mixins, **attributes): | |
mixin_prefix = ''.join((mixin.__name__ for mixin in mixins)) | |
parameterize = (f"{k}={v}" for k,v in attributes.items()) | |
parameter_suffix = f"({', '.join(parameterize)})" | |
bases = tuple((*mixins, cls)) | |
base_types = tuple(frozenset(type(t) for t in bases)) | |
base_typename = ''.join((t.__name__ for t in base_types)) | |
base_type = type(base_typename, base_types, {}) | |
return base_type(f"{mixin_prefix}{cls.__name__}{parameter_suffix}", bases, attributes) |
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 itertools | |
def load_pyconf_file(filename, env=None): | |
f = '\t'.join(itertools.chain(("def __func():\n",), open(filename).readlines())) | |
if env: | |
exec(f, env) | |
return env['__func']() | |
else: | |
exec(f) | |
return __func() |
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 monad import Monad | |
class Computation(Monad): | |
__category = True | |
@staticmethod | |
def pure(value): | |
return Continue(value) | |
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
struct no_delete { | |
template <typename T> | |
void operator() (T*) {} | |
}; | |
template <typename T> | |
using unique_handle = std::unique_ptr<T, no_delete>; | |
template <typename T> | |
auto get_handle_to(T& a) { |
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
// Library code | |
#include <stdexcept> | |
#include <type_traits> | |
#include <utility> | |
namespace library { | |
template <typename T> | |
struct to_positive { |
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 asyncio import QueueEmpty, QueueFull | |
from typing import Deque, Generic, TypeVar | |
from cocotb.triggers import Event | |
T = TypeVar("T") | |
class SendFailed(QueueFull): | |
... |
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
def build_table( | |
field_spec: List[Tuple[str, str, Optional[int]]], | |
table: List[Dict[str, str]], | |
) -> str: | |
field_fmts = [] | |
sep_line_fields = [] | |
field_names = [] | |
for name, alignment, width in field_spec: | |
if width is None: | |
width = max(len(name), *(len(row[name]) for row in table)) |
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
#include <stdnoreturn.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
typedef enum { | |
PUSH, | |
POP, | |
ADD, | |
SUB, |
OlderNewer