This file contains hidden or 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
#!/usr/bin/python | |
def shift(buf, offset, length): | |
assert length > 0 | |
left_extra = offset % 8 | |
right_extra = 8 - (offset + length) % 8 | |
start_offset = offset // 8 | |
end_offset = (offset + length - 1) // 8 |
This file contains hidden or 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 solid import * | |
from solid.utils import * | |
SEGMENTS = 200 | |
def tube(inner, outer, height): | |
assert inner < outer | |
return cylinder(d=outer, h=height) - cylinder(d=inner, h=height) |
This file contains hidden or 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
# nothing |
This file contains hidden or 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 importlib | |
import types | |
from typing import Any, Callable | |
class _staticproperty(): | |
def __init__(self, fget=None, fset=None, fdel=None, doc=None): | |
self.fget = fget | |
self.fset = fset |
This file contains hidden or 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
class cached_property(object): # type: ignore | |
def __init__(self, func): | |
self._func = func | |
def __get__(self, instance, owner): | |
attr = self._func(instance) | |
setattr(instance, self._func.__name__, attr) | |
return attr |
This file contains hidden or 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 inspect | |
def get_caller(level=1): | |
return inspect.stack()[level+1][3] | |
def log_call(func): | |
parameter_names = [ | |
parameter.name for parameter in inspect.signature(func).parameters.values() | |
] | |
def small_repr(value): |
This file contains hidden or 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 escape_error_handler(func): | |
def new_func(*args, **kwargs): | |
try: | |
return func(*args, **kwargs) | |
except: | |
import traceback | |
print() | |
traceback.print_exc() | |
import os | |
os._exit(1) |
This file contains hidden or 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
class Memory(): | |
@dataclasses.dataclass | |
class Pool(): | |
offset: int | |
size: int | |
def __contains__(self, other: Any) -> bool: | |
return isinstance(other, int) and self.offset <= other <= (self.offset + self.size) | |
def __init__(self, default_align: int = 0) -> None: |
This file contains hidden or 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 typing | |
from typing import Generic, List, Optional, Set | |
T = typing.TypeVar('T') | |
class Grouper(Generic[T]): | |
def __init__(self) -> None: |
This file contains hidden or 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
#!/usr/bin/env python | |
import pathlib | |
import subprocess | |
import time | |
# paired with fan speed (0-255) and temp (degrees C) | |
f_low_speed = 40 | |
f_low_temp = 35 |