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
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
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)
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.
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.
Sometimes however, you just want a quick, simple and small way to get from A to B without a lot of overhead and overkill. Below I'll show you a quick and simple Python trick for command line handling by directly mapping the command line arguments to function arguments.
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), but this is only a subset with the higher level commands.
For the saxophone music classes I'm taking, I have some exercises to play along with Charlie Parker records. Because that Bird plays pretty fast, it helps to slow things down a bit. I started with manually slowing down the tempo with Audacity, but soon I couldn't suppress the itch to automate things as I needed several slow down factors and also wanted the slow down factor in the MP3 ID3 title tag.
When programming, lint checking your source code can be useful to detect low level issues like syntax errors, undefined or unused variables. The PHP command line interpreter has an option -l/--syntax-check to do a syntax check of the provided PHP file, instead of executing it:
$ php -l file_with_syntax_error.php PHP Parse error: syntax error, unexpected T_VARIABLE in file_with_syntax_error.php on line 5 Errors parsing file_with_syntax_error.php
Unfortunately, it only allows to check one file at a time. For example, the following does not work as expected:
$ php -l file1.php file2.php file_with_syntax_error.php No syntax errors detected in file1.php
If you want to lint-check (a complete tree of) multiple PHP files, you have to use some kind of loop (e.g. in Bash) to check them one by one.
I recently was faced with this issue, but also wanted to have some parallelism, to speed up the process by putting multiple cores a work, instead of checking one file at a time. After googling a bit I found the following (command line) solutions.
I recently had this strange problem with running a 32 bit executable on a 64 bit machine. It executed just fine on 32 bit machines and some other 64 bit machine. But on this particular machine I got the strange error message:
bash: some32bitexecutable: No such file or directory
which is confusing because bash seems to complain that it does not find the executable, while I knew it was there. Using absolute paths and double checking the permissions didn't help.
The problem was however that the 32 bit runtime libraries were not available.
The fix on Ubuntu is to install the ia32-libs package, described as:
ia32 shared libraries for use on amd64 and ia64 systems.
This package contains runtime libraries for the ia32/i386 architecture, configured for use on an amd64 or ia64 Debian system running a 64-bit kernel.
(FYI: it will pull down some other packages too, like lib32gcc1, libc6-i386 and lib32stdc++6.)
I finally found some time to upload the slides of my public PhD defense to SlideShare. It's all in Dutch, but if that's Chinese to you, you still can watch a lot of pretty pictures.
I already tried to upload my slides more than a year ago, but slideshare had troubles with converting my slides. There is still a problem with missing math notation around slide 75, but all the rest seems okay.