Yuce's Blog

Cognitive dissonance is yoga for the brain.*

ReportLab on OSX


It's easy to compile ReportLab on OSX (in my case, 10.8). The only problem is, you'll get the following warning:

# installing without freetype no ttf, sorry!
# You need to install a static library version of the freetype2 software

Don't try to brew it yet. OSX already has freetype2 installed on versions before 10.7. For 10.7 and later make sure you install XQuartz. Then we just need to help ReportLab installer to help find it.

Download ReportLab, and insert the following lines around after line 104 (after # attempt to make sure we pick freetype2 over other versions):

aDir(I, "/usr/X11/include") 
aDir(L, "/usr/X11/lib")

Remove the build continue.


python, reportlab, freetype2, osx, tricks

Prometheus - The Movie


Scenario: a grocery store

A WOMAN approaches you as you carefully appreciate the sodium content of a can of beans.

WOMAN: That can of beans is going to kill Earth!

YOU: My God!

(you proceed to bludgeon your forehead with the can of beans until you knock yourself un­con­scious.)

— This is a parody of a scene from #Prometheus, source: IMDB comment.


prometheus, failure, movie, parody

Compiling Python Extension Modules on Mac OSX 10.6


If you get the following error when you are compiling a Python C extension module in Mac OSX 10.6:

/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
spammodule.c:63: fatal error: error writing to -: Broken pipe compilation terminated.

Run setup.py as follows:

ARCHFLAGS="-arch i386 -arch x86_64" python setup.py build

python, osx, tricks

Go Sample: Link Checker


You should have heard about Go, Google's new language. To be honest, it is one of the ugliest languages I've ever used (I mean among the ones not designed to be ugly); but it's in­ter­est­ing enough, and I decided to teach myself some.

Here's the result of a few hrs of reading, searching, coding, reading again and coding: an (almost) port of Josh Marshall's Python URL Link Checker. It doesn't support checking local files, but has a nice -v switch which lets you see all processed URLs. So far, pro­gram­ming Go felt a bit like pro­gram­ming C++. Also, Go links the code statically at the continue.


go, link checker

Getting the Current Module in Python


Say, you want to insert a function, class or any other object into the current module dy­nam­i­cal­ly. How can you do that? Of course, you start with getting the module name:

myName = globals()['__name__']

Then, get the module itself:

import sys
me = sys.modules[myName]

OK, you got the module, now insert something in it:

setattr(me, 'hello', lambda x: 'Hello %s'%x)

We can call hello in our module from now on:

print hello('World')

python, tips

Merging PDF Files Using Ghostscript


If you have to merge PDF files, you need no other than Ghost­script (which is installed by default with many Linux dis­tri­b­u­tions). Here's the command line:

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=firstANDsecond.pdf -dBATCH first.pdf second.pdf

pdf, ghostscript, tips

Web Application Testing with Selenium: Basics and Setup



It's always hard to ensure an ap­pli­ca­tion works up to a spec­i­fi­ca­tion and continue keeping up to the specs in the course of de­vel­op­ment. Testing web ap­pli­ca­tions is even harder, since they are composed of more components, and usually at least some of the components of the ap­pli­ca­tion are not directly controlled by the developers, such as links to other internet resources or mashups.

Luckily, there's a great tool for easing the pain of web ap­pli­ca­tion testing: Selenium. Selenium simulates a human user, by con­trol­ling a web browser using Javascript through a system called Selenium Core. The simulated behaviour includes clicking on links, form continue.


python, selenium, testing, web