Welcome

10 December, 2009 - 16:17

Hello, welcome to my blog, a stream of random ramblings, mostly about technical stuff, including (but not limited too): programming, Linux, OS X, Drupal, ...

Happy clicking around,
Stefaan

PhantomJS script to capture Reveal.js slideshow slides

1 October, 2013 - 23:02

Just a quick note that I whipped up a PhantomJS script to capture screenshots of Reveal.js powered slideshow slides.

The script is available as GitHub Gist:

Spidering JavaScript-manipulated HTML with PhantomJS

14 April, 2013 - 23:52

Even if you are in an automated context, not using a typical browser, fetching the data/webpage from an URL is easy. There are command line tools like wget and curl, and every programming library has its share of libraries to build on.

But what if you need the HTML markup of page after it has been manipulated with JavaScript?

Git cherry-pick without whitespace

14 April, 2013 - 21:46
Categories:

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 these unrelated line changes, you easily get in conflict situations when cherry-picking or merging.

Here is a trick I use to cherry-pick this kind of commits, without the whitespace parts.

For example, say his commit SHA1 is "abc123".

Get stacktrace/traceback/backtrace in Python catch body

14 February, 2013 - 00:40
Categories:

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 clues:

import traceback
import logging
 
try:
     stuff()
except Exception:
 
     # Just print traceback
     print "something went wrong, here is some info:"
     traceback.print_exc()
 
     # Get traceback as a string and do something with it
     error = traceback.format_exc()
     print error.upper()
 
     # Log it through logging channel
     logging.error('Something went wrong', exc_info=True)

Check iTunes library for inexistent files and broken links with Python and PyObjC

24 January, 2013 - 00:35
Categories:

Music files come, music files go. And after some time your iTunes library is sprinkled with cases of The song “Jajazazalala” could not be used because the original file could not be found. Would you like to locate it?

Unicode Fun in Python

30 December, 2012 - 23:46
Categories:

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:
Unicode fun

Git: resolve conflict after stash pop in working directory (no staging/index)

20 November, 2012 - 14:45
Categories:

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 reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#	both modified:      src/some/file.txt
#	both modified:      src/some/other/file.txt

After you fix the conflicts manually in the files, you normally want to tell git that the conflict has been resolved. If you google for how to do this, you typically find solutions that suggest to git add the files and commit. But what if your (stashed) work is not ready for commit/staging yet?

Python: determine installation prefix

17 April, 2012 - 23:27
Categories:

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 investigate of course)

Python trick: asynchronously reading subprocess pipes

9 March, 2012 - 00:19
Categories:

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 to glue together external systems/processes. A tricky issue with having parallel "flows" this way (your python process and the child process in this case), is the risk on deadlocks if you are not careful with the order things are done.