Skip to content

Instantly share code, notes, and snippets.

View tkutcher's full-sized avatar
🤔

Tim Kutcher tkutcher

🤔
View GitHub Profile
@tkutcher
tkutcher / pyproject.toml
Last active January 10, 2024 15:46
Poetry #8866
[tool.poetry]
name = "my_package"
version = "0.13.2"
[[tool.poetry.source]]
name = "custom-1"
url = "some-url-to-gitlab-private-registry"
priority = "default"
#!/usr/bin/env python
import sys
print(sys.argv[1])
@tkutcher
tkutcher / harbaugh-zshrc.zsh
Created March 28, 2022 18:52
harbaugh.zshrc
# where the tkutcher repository is cloned ("installed") to
export TK_LIB_DIR="${HOME}/tk/lib/tkutcher"
# sourcing rc files relevant for this machine
source "${TK_LIB_DIR}/rc/aliases.sh"
source "${TK_LIB_DIR}/rc/env.sh"
source "${TK_LIB_DIR}/rc/funs.sh"
source "${TK_LIB_DIR}/rc/p10k.zsh"
@tkutcher
tkutcher / xnvl.sh
Last active March 28, 2022 18:47
xnvl.sh
# set up basic variables for where things are located
DEVTOOLS_VENV_DIR="${HOME}/tk/lib/devtools/venv"
# activate the virtual environment with the dependencies
source "${DEVTOOLS_VENV_DIR}/bin/activate"
# invoke nvl inside that virtual environment and forward args
nvl "$@"
@tkutcher
tkutcher / test_my_config.py
Created February 19, 2022 18:25
Python File IO Demo 5
def test_writes_config_properly(tmpdir):
dest_path = pathlib.Path(tmpdir) / "example-output.json"
assert not dest_path.exists()
config = MyConfig(x="4", y="18")
write_to_file(config, dest)
assert dest_path.exists()
assert read_from_file(dest_path).x == "4"
@tkutcher
tkutcher / conftest.py
Created February 19, 2022 18:08
Python File IO Demo 4
@pytest.fixture()
def res_dir():
return pathlib.Path(__file__).parent / "res"
@tkutcher
tkutcher / test_my_config.py
Created February 19, 2022 18:01
File IO Demo Test 3
def test_read_from_file_1():
c = read_from_file(pathlib.Path(__file__).parent / "res" / "example-config-001.json")
assert c.x == "3"
def test_read_from_file_2():
c = read_from_file(pathlib.Path(__file__).parent / "res" / "example-config-002.json")
assert c.x == "18"
@tkutcher
tkutcher / my_config.py
Last active February 19, 2022 17:48
Testing File IO demo 2
def read_from_file(src_path="my-config.json") -> MyConfig:
with open(src_path, "r") as f:
d = json.load(f)
return MyConfig(d["x"], d["y"])
def write_to_file(c: MyConfig, dest_path="my-config.json") -> None:
with open(dest_path, "w") as f:
f.write({"x": c.x, "y": c.y})
@tkutcher
tkutcher / my_config.py
Created February 19, 2022 17:45
File IO Demo 1
@dataclasses.dataclass
class MyConfig:
x: str
y: str
def read_from_file() -> MyConfig:
with open("my-config.json", "r") as f:
d = json.load(f)
return MyConfig(d["x"], d["y"])
@tkutcher
tkutcher / buffered_iterator.py
Last active February 9, 2022 17:28
Python BufferedIterator
"""
buffered_iterator - Decorates an iterator with "has_next" by buffering values.
Example use case for this is if you have a base interface/ABC that has methods
`has_next` and `get_next`, and several classes realizing this interface already
would have iterators internally, you wouldn't want them to each have to
implement the logic for `has_next` - so it would be better to decorate an
iterator with some sort of `has_next`.
Inspiration from