Unicode Fun in Python

30 December, 2012 - 23:46

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"),'

Unicode fun

List of available git commands

21 December, 2011 - 21:55

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.

Slow down Charlie Parker with SoX

16 December, 2011 - 00:57

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.

PHP lint checking multiple files in parallel

2 November, 2011 - 00:11

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.

My bashrc, bash aliases, profile and other files

19 October, 2009 - 15:30

I spend a lot of time on the (bash) command line in (Linux and OS x) and it's always good for productivity to have your favorite set of shortcuts, aliases, perferences, predefined (environment) variables and such at your fingertips. You know, all the stuff that lives in .bashrc, .profile, .vimrc, .git, etc.

I have access to several systems (at home, at work, remote servers, etc) and from time to time I'm sitting behind a system that doesn't know my preferences yet. I considered using some sort of version control system to "synchronize" these preference files between my setups, but (apart from the practical hurdles) it generally seemed overkill, especially since each setup can have its own peculiarities and customizations.

So, mainly for my own reference, I'm keeping an list of the most important general stuff here. Be welcome to cherry-pick (or suggest additions).


9 September, 2009 - 11:07

For some small tools or jobs I use Jython so I can (re)use some existing Java code, while still writing in Python. I also have various custom Python modules, of which I put the paths in my PYTHONPATH environment variable, so those modules are easily available in Python scripts and interactive sessions.

However, Jython does not automatically pick up the PYTHONPATH information, for reasons that seem to be discussed in this Jython development mailing list thread.

Jython 2.5 introduced the JYTHONPATH environmental variable as Jython-equivalent of PYTHONPATH, so setting both to the same value should do the trick for most use cases (unless you're working in a setup with incompatible Python an Jython versions).

For Jython versions prior to 2.5 (like 2.2.1 in my case), there is an easy "workaround", by invoking Jython with the appropriate -Dpython.path=foo/path:bar/path option. For example as follows:

Showing the running command in a bash script with "set -x"

29 May, 2009 - 09:03

Bash scripts are handy for putting a bunch of longer running jobs in one batch. In some occasions it can be useful to know which command is running at the moment, especially when the commands do not generate output themselves or this output is redirected to files.

Bash has a simple setting to achieve this:

set -x

which, according to help set, enables the following feature:

-x Print commands and their arguments as they are executed.

Disabling it just takes a mere

set +x

You can play with it from the bash command line itself, or put it in a bash script of course.

Bash: the difference between $* and $@ and what that means for working with filenames containing spaces

29 November, 2005 - 19:39

Lets's start with a citation about the special parameters $* and $@ from the bash manual:

cat with rot13 encoding

27 November, 2005 - 17:46

If you're familiar with the Unix or Linux commandline you probably know cat for printing files to standard output. Rot13 is a simple text encryption/cyphering/obfuscation (or whatever you want to call it) technique. It replaces each letter with the letter 13 places further in the alphabet. For example: 'a' becomes 'n', 'z' becomes 'm' and 'n' becomes 'a' (which illustrates the fact that the rot13 operation and its inverse are the same).

shell redirection of standard output and standard error to the same file

22 November, 2005 - 11:49

Consider a program hello_and_error that writes to both stdout and to stderr. To redirect both to stdout:

hello_and_error 2>&1

If you want to redirect both to the same file hello.txt you can do in bash the following:

hello_and_error &> hello.txt

If you want to do this in a more obvious (but longer) way you should do

hello_and_error 1>hello.txt 2>&1

and not

hello_and_error 2>&1 1>hello.txt