Keynote at PyCon Lithuania 2024
Daniel Feldroy
by Daniel Roy Greenfeld
1M ago
From April 2nd to April 6th I'll be at PyCon Lithuania 2024 in Vilnius to present a keynote about 25 years of glorious coding mistakes (mostly in Python). Audrey and Uma will be accompanying me, making us the first members of the Lithuanian side of my family to return there in over 100 years! At the conference I'll be joined by my old friend Tom Christie, author of HTTPX, Starlette, and Django REST Framework. I hope to meet many new friends, specifically everyone there. At the sprints I'll be joined by my awesome wife, Audrey, author of Cookiecutter. Come and join us ..read more
Visit website
TIL: Writing decorators for classes
Daniel Feldroy
by Daniel Roy Greenfeld
3M ago
To my surprise writing decorators for classes is easier than for functions. Here's how to do it in annotated fashion with an unnecessary decorator that doesn't accept any additional arguments. # Write a callable that accepts a cls as an argument def tools(cls): # Write functions that accept "self: object" as an argument. def simplistic_attribute_count(self: object) -> int: """Returns the number of attributes.""" return len(self.__dict__) def docs(self: object) -> str: """Returns the docstring for the class.""" return self.__doc__ # Atta ..read more
Visit website
TIL: Change older git commit
Daniel Feldroy
by Daniel Roy Greenfeld
4M ago
Typically I try to avoid changing older commits in a pull request. My reasoning has a tiny bit to do with preserving history and lots to do with being resistant to trying new things. Finally I got around to looking this up today, it is easy to do. WARNING: Do this on branches of main, not on the main branch itself. More on that at the end. Find the commit In our example the change we want to amend is 3 commits back, do this to find it: git rebase -i HEAD~3 That will bring up a screen that looks like this in your text editor: pick ec0fb5e0333c Configure omnitron galactic retroverter pick 6e7 ..read more
Visit website
TIL: Forcing pip to use virtualenv
Daniel Feldroy
by Daniel Roy Greenfeld
5M ago
Necessary because installing things into your base python causes false positives, true negatives, and other head bangers. Set this environment variable, preferably in your rc file: # ~/.zshrc export PIP_REQUIRE_VIRTUALENV=true Now if I try to use pip outside a virtualenv: dj-notebook on  main [$] is ? v0.6.1 via ? v3.10.6 ❯ pip install ruff ERROR: Could not find an activated virtualenv (required). This TIL is thanks to David Winterbottom ..read more
Visit website
Three Years at Kraken Tech
Daniel Feldroy
by Daniel Roy Greenfeld
5M ago
A summary of the past year as I finish my third year working for Kraken Tech, an Octopus Energy Group subsidiary. Note: As I write this I'm recovering from a sprained shoulder I received in a bicycle accident that makes it hard to type. I'm mostly using voice-to-text, so the text might not be in my normal "writing voice". I changed roles I transitioned from leading the tech team for Kraken Tech USA to being an individual contributor for the global team. I do this periodically, cycling between writing code to leading teams, and back again. It is never easy to transition between roles but this t ..read more
Visit website
Minimal CSS libraries
Daniel Feldroy
by Daniel Roy Greenfeld
5M ago
Minimal CSS frameworks do not use classes, rather modifying the look of HTML components. That means that any CSS classes added are easier to discover and read. I'm someone who struggles with CSS and the custom CSS of this site combined with complex non-obvious HTML (example being <ul> and <li> for content sections) partially obscured by React components has been hard on me. I've wanted to make changes but kept running into walls when I wanted to do things like add dark mode. I tried bringing in heavy CSS frameworks, but having to fix/change hundreds of tags was not someting I wante ..read more
Visit website
Splitting Git Commits
Daniel Feldroy
by Daniel Roy Greenfeld
5M ago
Something I periodically do and need to document here where I can find it fast. To reset the most recent commit: git reset HEAD~ This reverts the commit. Then you can commit individual or groups of files in multiple commits What if your commit isn't the most recent one? Use an interactive rebase to commit things further back. Follow these steps Find the commit hash with either git log or git reflog Start a rebase with the commit hash replacing HASH below git rebase -i HASH In the rebase edit screen that comes up, find the line with the commit you want to split. Replace pick with ed ..read more
Visit website
TIL: Autoloading on Filechange using Watchdog
Daniel Feldroy
by Daniel Roy Greenfeld
5M ago
Using Watchdog to monitor changes to a directory so we can alter what we serve out as HTTP. Each segment is the evolution towards getting it to work. Serving HTTP from a directory I've done this for ages: python -m http.server 8000 -d /path/to/files Using http.server in a function The Python docs aren't very clear on this, and rather than think hard about it I did this fun hack: # cli.py from pathlib import Path from subprocess import check_call def server(site: Path) -> None: check_call(['python', '-m', 'http.server', '8000', '-d', site]) Autoreloading on filechanges A bit more in ..read more
Visit website
TIL: Skipping git pre-commit
Daniel Feldroy
by Daniel Roy Greenfeld
6M ago
For saving WIP commits to a remote repo. You really don't want to know what I was doing before. Just add --no-verify to whatever you are doing: git commit -am "Fun code noodling" --no-verify git commit --amend --no-verify Thanks to Fabio da Luz, I found you can also shorten that to just -n. git commit -am "Fun code noodling" -n git commit --amend -n ..read more
Visit website
TIL: Capture stdout & stderr with pytest
Daniel Feldroy
by Daniel Roy Greenfeld
7M ago
I wish I knew this earlier, but I know it now thanks to Cody Antunez. Here it is: import sys def test_myoutput(capsys): # or use "capfd" for fd-level # Write some text print("hello") sys.stderr.write("world\n") # Capture the text captured = capsys.readouterr() # Test the captured output, both std and err assert captured.out == "hello\n" assert captured.err == "world\n" In the pytest docs it describes the fixtures to capture binary and more ..read more
Visit website

Follow Daniel Feldroy on FeedSpot

Continue with Google
Continue with Apple
OR