Tuesday, May 24, 2011

Could not drop a folder onto TextMate's project drawer

I was trying to create a new project in Textmate in the usual way - New Project from the File menu, then drag a folder on to the project drawer in TextMate - but TextMate refused to act as a drop target for the folder. I had a closer look at the folder and its contents and saw that some files in the folder had the Quarantine attribute set. Use
ls -l@
to list the extended attributes.

OS/X sets this attribute when a file is saved from the Browser or an Email. This is what causes the "This file was downloaded from the Internet" prompt that you see the first time you try to open such a file.

I wondered if that was the problem, so I ran xattr command with the recurse flag
xattr -d -r com.apple.quarantine <folder name>
to delete the quarantine attribute from all files in that folder. Thereafter TextMate was happy to act as a drop target for the folder.

Saturday, March 5, 2011

BlackBerry PlayBook and Sketchpad Sample App

I was trying to compile the sample WebWorks application for the BlackBerry Playbook and immediately ran into a problem:-
[INFO] Parsing command line options
[INFO] Parsing bbwp.properties
[INFO] Validating WebWorks archive
[INFO] Parsing config.xml
[WARNING] Failed to find a element
[INFO] Populating application source
[INFO] Compiling WebWorks application
Error loading: c:\Program Files\Java\jdk1.6.0_22\jre\bin\server\jvm.dll
[INFO] Packaging the bar file
java.io.FileNotFoundException: C:\Users\ABDULR~1\AppData\Local\Temp\widgetGen.15
125699001299362608489.tmp\sketchPadStandard.swf (The system cannot find the file
specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(Unknown Source)
at net.rim.tumbler.file.FileManager.copyFile(Unknown Source)
at net.rim.tumbler.airpackager.AirPackager.run(Unknown Source)
at net.rim.tumbler.WidgetPackager.go(Unknown Source)
at net.rim.tumbler.WidgetPackager.main(Unknown Source)
[ERROR] Air Packager exception occurred
The problem turned out to be the JDK being used. Instead of using the one within the WebWorks SDK, the system JDK was being used. The correct JDK can be specified using the JAVA_HOME environment variable:-
bbwp>set JAVA_HOME="c:\Program Files (x86)\Research In Motion\BlackBerry Web
Works Packager for PlayBook\jre"

Tuesday, February 8, 2011

Ubuntu in VirtualBox

I use Ubuntu Server in VirtualBox for all sorts of development and testing and two items that always bug me with new installs is the slow frame buffer updates and a warning on startup that piix4_smbus ... SMBus base address in uninitialized. Both can be fixed by updating /etc/modprobe.d/blacklist.conf. Add the following to the end of that file:-
# don't use vga16 framebuffer
blacklist vga16fb

# don't probe for i2c_piix4
blacklist i2c_piix4

Monday, January 31, 2011

Enabling SSL in Python

After installing Python 2.5 for use with Google's AppEngine I discovered that SSL had not been compiled in. I use Ubuntu 10.10 as the test server. First install the SSL headers:-
$ sudo apt-get install libssl-dev
Then rebuild Python to include SSL:-
$ cd /usr/local/src/Python-2.5.5/
$ sudo rm Modules/Setup
$ sudo joe Modules/Setup.dist
Uncomment lines 206-209 and set line 206 to:-
SSL=/usr
Save and exit, then:-
$ sudo ./configure --prefix=/usr/local/python2.5
$ sudo make clean
$ sudo make
$ sudo make install
Finally, remove the virtualenv already created and create a new one so that the new python executable and libraries are copied in.

Configuring virtualenv and appengine

Google's AppEngine requires a Python 2.5 environment. I created this by first installing Python 2.5 on my system, then installing virtualenv:-
$ cd /usr/local/src
$ sudo tar -zxf virtualenv-1.5.1.tar.gz
$ cd virtualenv-1.5.1
$ sudo python setup.py install
Install AppEngine into your project folder:-
$ cd ~/appengineproject
$ unzip google_appengine_1.4.1.zip
$ sudo ln -s ~/appengineproject/google_appengine/ /usr/local/google_appengine
And finally create a virtualenv for AppEngine
$ virtualenv --python=python2.5 pythonenv
and configure it by adding the following lines to pythonenv/lib/python2.5/site-packages/gae.pth:
~/appengineproject/google_appengine
~/appengineproject/google_appengine/lib/yaml/lib
~/appengineproject/google_appengine/lib/antlr
~/appengineproject/google_appengine/lib/ipaddr
~/appengineproject/google_appengine/lib/webob
~/appengineproject/google_appengine/lib/django
~/appengineproject/google_appengine/lib/fancy_urllib
~/appengineproject/google_appengine/lib/simplejson
~/appengineproject/google_appengine/lib/graphy

Sunday, January 30, 2011

python 2.5, zlib 1.2.5 and failing make test

I needed to have Python 2.5 for an App Engine project. My test virtual machine is running Ubuntu 10.10 with Python 2.6.5 so I decided to install Python 2.5 and use virtualenv to manage different development projects. Obviously this wasn't going to be that simple. Firstly I installed Python 2.5 using a convenient staging area. I prefer /usr/local/src:-
$ cd /usr/local/src
$ sudo wget http://www.python.org/ftp/python/2.5.5/Python-2.5.5.tgz
$ sudo tar -xzf Python-2.5.5.tgz
$ cd Python-2.5.5
$ sudo ./configure --prefix=/usr/local/python2.5
$ sudo make
$ sudo make test
And I saw the first problem:-
test_zlib skipped -- No module named zlib
This meant I also had to install zlib:-
$ cd /usr/local/src
$ sudo wget http://zlib.net/zlib-1.2.5.tar.gz
$ sudo tar -zxf zlib-1.2.5.tar.gz
$ cd zlib-1.2.5
$ sudo ./configure
$ sudo make
$ sudo make install
This improved things a bit, but I still had a failure with the zlib test:-
test test_zlib failed -- Traceback (most recent call last):
File "/usr/local/src/Python-2.5.5/Lib/test/test_zlib.py", line 72, in test_baddecompressobj
self.assertRaises(ValueError, zlib.decompressobj, 0)
AssertionError: ValueError not raised
A bit more research showed that changes in zlib after 1.2.3 caused the zlib test to fail. Sadly the fix was not being backported to 2.5, meaning that I had to change the test manually:-
$ cd/usr/local/src/Python-2.5.5/Lib/test
$ sudo joe test_zlib.py
Go to line 72, change 0 to -1 on that line, save and exit.

Now the zlib test passed, and Python 2.5 can be installed:-
$ cd /usr/local/src/Python-2.5.5
$ sudo make install

Saturday, January 29, 2011

OS/X 10.6 LC_CTYPE

On OS/X 10.6, Apple have defined the LC_CTYPE environment variable as 'UTF-8'.
$ locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
LC_CTYPE is meant to specify the encoding for the locale as well as the character properties, yet UTF-8 defines only the encoding. This can lead to problems with internationalisation in software, like Python's Babel module which throws a ValueError exception:-
ValueError: expected only letters, got 'utf-8'
This can be fixed by changing the LC_CTYPE value to include the character properties by specifying the country/language portion as well:-
export LC_CTYPE="en_CA.utf-8"
You may want to add it to your .profile to make the change permanent:-
echo "LC_CTYPE='en_CA.utf-8'" >> ~/.profile
Ideally Apple are the ones who need to fix this.

Saturday, January 22, 2011

Amin Maalouf

"Many are so angry or bewildered that they give up trying to understand what is going on. Many refuse to make a contribution to the emerging universal culture because at some point they decided once and for all that the world around them was incomprehensible, hostile, bloodthirsty, demented, or diabolical. Many are tempted to see themselves as mere victims - victims of America, of the West, of capitalism or liberalism, of the new technologies, of the media, of change, and so on. It cannot be denied that such people really do feel wronged and suffer accordingly, but their reaction seems to me inappropriate. To imprison oneself in a victim mentality can do the injured party even more harm than the aggression itself. And this is as true of societies as of individuals. They huddle themselves away, they close their minds, they ruminate, they give up looking for anything new, they don't explore any more, they don't make any more progress, they are afraid of the future, of the present and of everyone else."
Amin Maalouf, "On Identity" (p. 102)

Friday, January 21, 2011

Directory sharing between Apache and a user

There are times when a user needs to maintain files in a directory managed by Apache. This would usually be a folder created via the web server and is therefore owned by that web server, the www-data or nobody user.

There is more than one way to allow another user access to that directory and the one I prefer is to ensure that the Apache user has a umask of 002 and to add the user to the Apache group.

These are the steps I took on Ubuntu 10.4 LTS:-

sudo echo 'umask 002' >> /etc/apache2/envvars
sudo usermod -a -G www-data username
sudo apache2ctl restart

The location of the envvars file can be found by inspecting /etc/init.d/apache2 (or maybe /etc/init.d/httpd).

These are the steps I took on a Virtual Private Server at Servint (as root):-

echo 002 > /var/cpanel/easy/apache/rawenv/umask
echo 'umask 002' >> /usr/local/apache/bin/envvars
usermod -a -G nobody username
/etc/init.d/httpd stop
/etc/init.d/httpd start

As this is a managed server and the envvars file is recreated by a script when Apache is rebuilt, I had to update both /var/cpanel/easy/apache/rawenv/umask and /usr/local/apache/bin/envvars. The first is to include the umask setting in the automated creation of envvars and the second was to do a manual insert before restarting the web server.