A colleague of mine at work has set up his IDE to clean up all trailing whitespace on save. Nothing wrong with that, except that he is the only one, which very often means in practice that his commits are sprinkled with fixes of other people's whitespace mixups. Because of …
-
-
Get stacktrace in Python catch body
So you have some Python code in a try-catch, and you want the typical Python stacktrace (aka traceback, aka backtrace) in a way you can manipulate?
Here are some ways to handle it:
import traceback import logging try: stuff() except Exception: # Just print traceback print "something went wrong, here is …
-
Check iTunes library for inexistent files and broken links with Python and PyObjC
Music files come, music files go. And after some time your iTunes library is sprinkled with cases of
The song “Monsieur Cannibale” could not be used because the original file could not be found. Would you like to locate it?
Being annoyed by this and having no idea how "healthy …
-
Unicode Fun in Python
Here is some Python powered unicode fun (command line oneliner version):
python -c 'for c in range(0x1F410, 0x1F4f0): print (r"\U%08x"%c).decode("unicode-escape"),'
result:
-
Git: resolve conflict after stash pop in working directory (no staging/index)
In git, when you do
git stash pop
of unfinished code after upstream merges, you might get a conflict between the stash and the upstream changes you pulled in.You git clone now has "unmerged paths" aka is in conflict state. For example,
git status
shows:# Unmerged paths: # (use "git …
-
Python: determine installation prefix
Here's a simple bash oneliner to determine the installation prefix (and more) of a python interpreter:
python -c 'import sys;print("\n".join("{0:16s}: {1!r}".format(x, getattr(sys, x)) for x in ["executable", "version", "prefix", "exec_prefix"]))'
(Replace "python" with the actual python executable you want to …
-
Python trick: asynchronously reading subprocess pipes
Update: I reworked the code below a bit and put it on github and pypi to make it pip installable
As its name suggests, the Python subprocess allows you to spawn a child/sub process and keep an eye on its standard output through a pipe for example. Very handy …
-
Duviz: command line tool for disk usage visualization
duviz.py is a simple UNIX command line utility written in Python to visualize disk space usage. See it in action here:
I started writing it a couple of years ago (2009 according to the git commit log), but I just recently decided to make it more public. As a …
-
Simple and quick command line argument handling in Python
When creating a command line tool, you quickly are faced with the burden of handling command line arguments (parsing options, arguments, flags, etc). In Python, the optparse module or, its newer version, the argparse module are very nice solutions to build powerful command line interfaces, completely with automatically generated help …
-
List of available git commands
Git comes with a massive bunch of (sub)commands and even if you're dealing with git on a daily basis, you might not always remember every single one you need along the way. Having bash completion for git is already a good start (type
git
, a space and then tab …