I am a huge believer in practicing your craft. Professional athletes
spend most of their time honing their skills and making themsleves
better. In Engineering many spend nearly 0 time practicing. I am not
saying that you need to spend all your free time practicing, but a few
minutes trying new things can go a long way in how you understand what
you are doing and make a hue impact on your long term productivity.
What is Kedro [1]
Start practicing # [2]
practice building pipelines with #kedro today
Go to your playground directory, and if you don’t have one, make one.
cd ~/playground
get pipx # [3]
Install pipx in your system python. This is one of the very few, and
possibly the only python library that deserves to be installed in your
system directory, primarily because its used to sanbox clis in their own
virtual environment [4] automatically for you.
pip install pipx
make a new project # [5]
From inside your playground directory, start your new kedro project.
This is quite simple and painless. So much so that if you mess this one
up doing something wild, it might be easier to make a new one that
fixing the wild one.
pipx run kedro new
# answer the questions it asks
I u...
Publishing rhythm
If you’re into interesting projects, don’t miss out on jupyterlite [1], created by jupyterlite [2].
Wasm powered Jupyter running in the browser 💡
References:
[1]: https://github.com/jupyterlite/jupyterlite
[2]: https://github.com/jupyterlite
I’m really excited about nbterm [1], an amazing project by davidbrochart [2]. It’s worth exploring!
Jupyter Notebooks in the terminal.
References:
[1]: https://github.com/davidbrochart/nbterm
[2]: https://github.com/davidbrochart
I came across stylish.nvim [1] from sunjon [2], and it’s packed with great features and ideas.
Stylish UI components for Neovim
References:
[1]: https://github.com/sunjon/stylish.nvim
[2]: https://github.com/sunjon
One of the first things I noticed broken in my terminal based workflow moving
from Windows wsl to ubuntu was that my clipboard was all messed up and not
working with my terminal apps. Luckily setting tmux and neovim to work with
the system clipboard was much easier than it was on windows.
First off you need to get xclip if you don’t already have it provided by your
distro. I found it in the apt repositories. I have used it between Ubuntu
18.04 and 21.10 and they all work flawlessly for me.
I have tmux setup to automatically copy any selection I make to the clipboard
by setting the following in my ~/.tmux.conf. While I have neovim open I need
to be in insert mode for this to pick up.
# ~/tmux.conf
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -selection clipboard -i"
To get my yanks to go to the system clipboard in neovim, I just added
unnamedplus to my existing clipboard variable.
# ~/.config/nvim/init.vim
set clipboard+=unnamedplus
If you need to copy something right from the terminal you can use xclip
directly. ...
With the latest version of minecraft it requires a very new, possibly
the latest, version of java. Lately we have been getting into modded
minecraft and I maintain the server for us. It’s been tricky to say the
least. One hurdle I recently hit involves having the wrong version of
java.
I was getting this error trying to get a 1.12.2 forge server running.
Caused by: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader ‘bootstrap’)
In researching our errors, I found this on a forum.
Pre-1.13 Forge only works with Java 8.
I don’t write java, or really know how to manage different versions of
java, but I have nixpkgs installed and it has a ton of odd stuff like
this readily available, so
searching nixpkgs [1]
landed me with this.
nix-env -iA nixpkgs.jdk8
once I had this installed I then just changed out java for the full path
to my new nixpkgs.jdk8 java and it worked.
/home/walkers/.nix-profile/bin/java -server -Xms${MIN_RAM} -Xmx${MAX_RAM} ${JAVA_PARAMETERS} -jar ${SERVER_JAR} nogui
I don...
I have added a hotkey to my copier template setup to quickly access all my
templates at any time from tmux. At any point I can hit <c-b><c-b>, thats
holding control and hitting bb, and I will get a popup list of all of my
templates directory names. Its an fzf list, which means that I can fuzzy
search through it for the template I want, or arrow key to the one I want if I
am feeling insane. I even setup it up so that the preview is a list of the
files that come with the template in tree view.
bind-key c-b popup -E -w 80% -d '#{pane_current_path}' "\
pipx run copier copy ~/.copier-templates/`ls ~/.copier-templates |\
fzf --header $(pwd) --preview='tree ~/.copier-templates/{} |\
lolcat'` . \
"
I’ve had this on my systems for a few weeks now and I am constantly using it
for my tils [1],
blogs [2], and my .envrc file that goes into
all of my projects to make sure that I have a virtual environment [3] installed and
running any time I open it.
[4]
References:
[1]: https://waylonwalker.com/til/
[2]: https://waylonwalker.com/archive/
[3]: /virtual-environment/
[4]: https://dropper.waylonwalker.com/file/5e97af0a-f305-4480-b1bf-51c7fd33286c.webp
I often pop into my blog from neovim with the intent to look at just a
single series of posts, til, gratitude, or just see todays posts.
Markata [1] has a great way of mapping over posts
and returning their path that is designe exactly for this use case.
[2]
To tie these into a Telescope picker you add the command as the
find_command, and comma separate the words of the command, with no
spaces. I did also --sort,date,--reverse in there so that the newest
posts are closest to the cursor.
nnoremap geit <cmd>Telescope find_files find_command=markata,list,--map,path,--filter,date==today<cr>
nnoremap geil <cmd>Telescope find_files find_command=markata,list,--map,path,--filter,templateKey=='til',--sort,date,--reverse<cr>
nnoremap geig <cmd>Telescope find_files find_command=markata,list,--map,path,--filter,templateKey=='gratitude',--sort,date,--reverse<cr>
NOTE telescope treates each word as a string, do not wrap an extra
layer of quotes around your words, it gets messy.
[3]
References:
[1]: https://markata.dev/
[2]: https://dropper.waylonwalker.com/file/3be6dada-a62d-4710-82b8-8a2c195cd36b.webp
[3]: https://dropper.waylonwalker.com/file/9bbbc269-d5c3-48c9-9ac9-730002e8b2b1.webp
If you’re into interesting projects, don’t miss out on dynaconf [1], created by dynaconf [2].
Configuration Management for Python ⚙
References:
[1]: https://github.com/dynaconf/dynaconf
[2]: https://github.com/dynaconf
Copier allows you to run post render tasks, just like cookiecutter. These are
defined as a list of tasks in your copier.yml. They are simply shell
commands to run.
The example I have below runs an update-gratitude bash script after the
copier template has been rendered.
# copier.yml
num: 128
_answers_file: .gratitude-copier-answers.yml
_tasks:
- "update-gratitude"
I have put the script in ~/.local/bin so that I know it’s always on my
$PATH. It will reach back into the copier.yml and update the default
number.
#!/bin/bash
# ~/.local/bin/update-gratitude
current=`awk '{print $2}' ~/.copier-templates/gratitude/copier.yml | head -n 1`
new=`expr $current + 1`
echo $current
echo $new
sed -i "s/$current/$new/g" ~/.copier-templates/gratitude/copier.yml
I’ve referenced a video from Anthony Sotile in passing conversation several
times. Walking through his gradual typing process has really helped me
understand typing better, and has helped me make some projects better over time
rather than getting slammed with typing errors.
https://youtu.be/Rk-Y71P_9KE
Step 1
Run Mypy as is, don’t get fancy yet. This will not reach into any functions
unless they are alreay explicitly typed. It will not enforce you to type them
either.
pip install mypy
mypy .
# or your specific project to avoid .venvs
mypy src
# or a single file
mypy my-script.py
Step 2 # [1]
Next we will add check-untyped-defs, this will start checking inside
functions that are not typed. To add this to your config create a
setup.cfg with the following.
[mypy]
check_untyped_defs = True
Step 3 # [2]
The final stage to this series is to add disallow_untyped_defs. This will
start requiring all of your functions to be type hinted. This one is probably
the toughest, because as you type functions mypy can uncover more issues for
you to fix. Often times the list of errors grows before it shrinks.
[mypy]
check_untyped_defs = True
disallow_untyped_defs = True
Anthony’s video # [3...
In order to make an auto title plugin for markata I needed to come up
with a way to reverse the slug of a post to create a title for one that
does not explicitly have a title.
slugs
a slug is generally all lowercase and free of spaces, and is a way to
make website routes (urls)
Here I have a path available that gives me the articles path, ex.
python-reverse-sluggify.md. An easy way to get rid of the file
extension, is to pass it into pathlib.Path and ask for the stem, which
returns python-reverse-sluggify. Then from There I chose to replace
- and _ with a space.
article["title"] = (
Path(article["path"]).stem.replace("-", " ").replace("_", " ").title()
)
To turn this into a markata plugin I put it into a pre_render hook.
from pathlib import Path
from markata.hookspec import hook_impl, register_attr
@hook_impl
@register_attr("articles")
def pre_render(markata) -> None:
for article in markata.filter('title==""'):
article["title"] = (
Path(article["path"]).stem.replace("-", " ").replace("_", " ").title()
)
I really appreciate that in linux anything can be scripted, including
setting the wallpaper. So everytime I disconnect a monitor I can just
rerun my script and fix my wallpaper without digging deep into the ui
and fussing through a bunch of settings.
feh --bg-scale ~/.config/awesome/wallpaper/my_wallpaper.png
I set my default wallpaper with feh using the command above.
Leaning in on feh, we can use fzf to pick a wallpaper from a directory
full of wallpapers with very few keystrokes.
alias wallpaper='ls ~/.config/awesome/wallpaper | fzf --preview="feh --bg-scale ~/.config/awesome/wallpaper/{}" | xargs -I {} feh --bg-scale ~/.config/awesome/wallpaper/{}'
I have mine alias’d to wallpaper so that I can quickly run it from
my terminal.
Getting docstrings from python’s ast is far simpler and more reliable than any
method of regex or brute force searching. It’s also much less intimidating
than I originally thought.
Parsing # [1]
First you need to load in some python code as a string, and parse it with
ast.parse. This gives you a tree like object, like an html [2] dom.
py_file = Path("plugins/auto_publish.py")
raw_tree = py_file.read_text()
tree = ast.parse(raw_tree)
Getting the Docstring # [3]
You can then use ast.get_docstring to get the docstring of the node you are
currently looking at. In the case of freshly loading in a file, this will be
the module level doctring that is at the very top of a file.
module_docstring = ast.get_docstring(tree)
Walking for all functions # [4]
To get all of the functions docstrings we can use ast.walk to look for nodes
that are an instance of ast.FunctionDef, then run get_docstring on those
nodes.
functions = [f for f in ast.walk(tree) if isinstance(f, ast.FunctionDef)]
function_docs = [ast.get_docstring(f) for f in functions]
ast.walk docs: Recursively yield all descendant nodes in the tree starting at node
(including node itself), in no specified order. This is useful ...
Many tools such as ripgrep respect the .gitignore file in the directory
it’s searching in. This helps make it incredibly faster and generally
more intuitive for the user as it just searches files that are part of
thier project and not things like their virtual environments, node
modules, or compiled builds.
Editors like vscode often do not include files that are .gitignored in
their search either.
pathspec is a pattern matching library that implements git [1]’s wildmatch
pattern so that you can ignore files included in your .gitignore
patterns. You might want this to help make your libraries more
performant, or more intuitive for you users.
import pathspec
from pathlib import Path
markdown_files = Path().glob('**/*.md')
if (Path(".gitignore").exists():
lines = Path(".gitignore").read_text().splitlines()
spec = pathspec.PathSpec.from_lines("gitwildmatch", lines)
markdown_files = [
file for file in markdown_files if not spec.match_file(str(file))
]
pathspec home page [2]
References:
[1]: /glossary/git/
[2]: https://github.com/cpburnz/python-path-specification
I don’t use refactoring tools as much as I probably should. mostly
because I work with small functions with unique names, but I recently
had a case where a variable name m was everywhere and I wanted it
named better. This was not possible with find and replace, because
there were other m’s in this region.
I first tried the nvim lsp rename, and it failed, Then I pip installed
rope, a refactoring tool for python, and it just worked!
pip install rope
Once you have rope installed you can call rename on the variable.
:lua vim.lsp.buf.rename()
When running a python process that requires a port it’s handy if there is an
option for it to just run on the next avaialble port. To do this we can use
the socket module to determine if the port is in use or not before starting our
process.
import socket
def find_port(port=8000):
"""Find a port not in ues starting at given port"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
if s.connect_ex(("localhost", port)) == 0:
return find_port(port=port + 1)
else:
return port
Check out neovim-grimoire [1] by alanwsmith [2]. It’s a well-crafted project with great potential.
No description available.
References:
[1]: https://github.com/alanwsmith/neovim-grimoire
[2]: https://github.com/alanwsmith
functools.total_ordering makes adding all of six of the rich comparison
operators to your custom classes much easier, and more likely that you
remember all of them.
From the Docs: The class must define one of __lt__(), __le__(),
__gt__(), or __ge__ In addition, the class should supply an
__eq__() method.
one of these
- lt()
- le()
- gt()
- ge()
and required to have this one
- eq()
Total Ordering Docs [1]
Here is an example using the Enum I was working on the other day.
from enum import Enum, auto
from functools import total_ordering
@total_ordering
class LifeCycle(Enum):
configure = auto()
glob = auto()
load = auto()
pre_render = auto()
render = auto()
post_render = auto()
save = auto()
def __lt__(self, other):
try:
return self.value < other.value
except AttributeError:
return self.value < other
def __eq__(self, other):
try:
return self.value == other.value
except AttributeError:
return self.value == other
References:
[1]: https://docs.python.org/3/library/functools.html#functools.total_ordering
Check out ipython [1] and their project ipython [2].
Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
References:
[1]: https://github.com/ipython
[2]: https://github.com/ipython/ipython