Notes and code snippets for quick reference.
Things I had to find out at some point. Hopefully I can save people some time by making them accessible here. This is not really an article or project, but I hope that people can find the solution they are looking for here when they are searching online.
PlantUML notes have a separate page.
On this page:
Shell commands, environment specific
- Languages and formats
- Operating system specific
Shell commands, environment specific
Recursively finding and removing all files based on name
find . -type f -name ".DS_Store" -delete
Finding only in the current directory, or any number of directories deep
find . -maxdepth 1 -type f -name ".DS_Store"
Specifying a list of filenames
find . \( -name "*.jpg" -o -name "*.JPG" -o -name "*.jpeg" -o -name "*.JPEG" \)
Let LFTP remove files from the target that are not present in the source
Let LFTP remove the source files after the command is finished
Example LFTP command to mirror from local source to remote target
lftp sftp://$(FTP_USER)@$(FTP_HOST) -e "mirror --verbose=3 --delete -R $(OUTPUTDIR) $(FTP_TARGET_DIR) ; quit"
This call will pause to ask for the password.
Script name, directory, present working directory
1 2 3 4 5 6 7 8 9 10 11 12
when we call the script like
, but not when calling as
Get the present working directory from inside a make script
echo "Current working directory of the make process: $(shell pwd)"
calls out to the shell.
Call another target from inside a target
Sometimes we can't call another target from a prerequisite because that would result in the wrong order of operations.
One way to call another target from inside make is
. This will spawn another make process.
Perhaps in your case spawning another make process adds too much overhead. In that case you might want to create a higher-level target that contains the original target as a prerequisite. This will not work if make runs in parallel mode because then the order of operations is not guaranteed. This StackOverflow answer shows how it can be done without creating a new make instance and still guaranteeing the order of operations. If we turn the other target into a variable instead of a target, we can use the call method to execute it:
OTHER_TARGET = echo "Executing other_target" initial_target: echo "Executing initial_target" $(call OTHER_TARGET)
awk - pattern-directed scanning and processing language
Example script to make a <ul> of files found by find
1 2 3 4 5 6 7
Languages and formats
How to combine incoming byte chunks
I asked about this on StackOverflow , and then I had to look up the answer again on another occasion. So I'll list it here :). To safe you some clicks, there are two options for the byte storage:
Instantiating an empty byte string,
b'', and appending / concatenating. This incurs a bit of string copy overhead.
- Instantiating a new empty byte array, and then extending it (appending to it).
The code might look as follows:
def process_incoming_connection(conn, addr): byte_array = bytearray() while 1: chunk = conn.recv(1024) if not chunk: break byte_array.extend(chunk) message = byte_array.decode(encoding='utf-8'); conn.close() # Now we can do something with the message
How to manually update or patch an official Python package
Sometimes we might need to do a bugfix on a Python package, or we need to use the latest version from the repository that is not yet packaged for our platform. How can we install this new version? This is very simple, we only need to copy the source files.
For example, if we want to update our system version of a package 'anyplugin' that lives in the 'pelican plugins' namespace, we simply overwrite the system version with our source files.
cp -r anyplugin /usr/local/lib/python3.8/site-packages/pelican/plugins/
The directory we copy is the actual python source file directory, this is not necessarily the directory root.
Operating system specific
Show hidden files in Finder
defaults write com.apple.finder AppleShowAllFiles YES
- Open the 'Force Quit' menu from the 'Apple' menu, or with the 'meta+option+escape' key combination (also known as 'command+option+escape').
- Locate 'Finder' in the list, click on it to select it, and then click the 'Relaunch' button.
Now hidden files will be shown.
I assume the same procedure with
will undo it.