About

mFabrik Blog is about mobile and web software development, open source and Linux. We tell exciting tales where business, technology, web and mobile convergence.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.

Testing mobile websites with Firefox Mobile for PC (Fennec desktop)

Firefox Mobile (Fennec) has also desktop builds. They are very useful for mobile web site testing as the browser is fast, has real keyboard and is only one mouse click away.

Here are instructions how to run Firefox Mobile on Ubuntu Linux (tested on 32-bit Ubuntu 10.10)

wget http://releases.mozilla.org/pub/mozilla.org/mobile/releases/latest/linux-i686/fennec-5.0.en-US.linux-i686.tar.bz2
tar -xjf fennec-5.0.en-US.linux-i686.tar.bz2
cd fennec
./fennec

.. and thats all you need. It works out of the box! 400x times faster than using Android emulator browser.

There are also OSX and Windows builds available.

Get developers  Subscribe mFabrik blog in a reader Follow me on Twitter

Changing the active Python interpreter on Windows

A lot of Windows Python software use wrapper .exe files which pick the Python interpreter  based on this registry settings. One notable exe is buildout.exe, which is used to run buildout.

If you install multiple Pythons, the latter installations might not become active in the registry automatically, and your Python wrapper still rely on the old version. This leads to version incompatibilities and you are unable to start the Python applications.

Since only one Python interpreter can be activate at a time, it is little bit difficult to develop multi-version Python code Windows.
This kind of situation could be that you develop Plone 3 sites (Python 2.4) and Plone 4 sites (Python 2.6) simultaneously.

Below is regpy.py code which changes the active Python interpreter. The orignal author is unknown, I picked up this code from some paste board long time ago. Just run this code with your Python and the running interpreter becomes active.

Example how to activate alternative Python interpreter:

C:\Plone\python\python.exe regpy.py

regpy.py:

import sys

from _winreg import *

# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix

regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
    installpath, installpath, installpath
)

def RegisterPy():
    try:
        reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
    except EnvironmentError:
        try:
            reg = CreateKey(HKEY_LOCAL_MACHINE, regpath)
            SetValue(reg, installkey, REG_SZ, installpath)
            SetValue(reg, pythonkey, REG_SZ, pythonpath)
            CloseKey(reg)
        except:
            print "*** Unable to register!"
            return
        print "--- Python", version, "is now registered!"
        return
    if (QueryValue(reg, installkey) == installpath and
        QueryValue(reg, pythonkey) == pythonpath):
        CloseKey(reg)
        print "=== Python", version, "is already registered!"
        return
    CloseKey(reg)
    print "*** Unable to register!"
    print "*** You probably have another Python installation!"

if __name__ == "__main__":
    RegisterPy()

Get developers  Subscribe mFabrik blog in a reader Follow me on Twitter

Thoughts about WP7

Now that Nokia made sure most of the energy put on Qt goes down the drain, I took a peek at Windows Phone 7 development and I was disappointed.

I posted a short comment to Future of Qt blog post and I thought I’ll write a bigger rant to make people more aware of an important issue.

The tools for WP7 are probably the best with Visual Studio and GUI editor and what else, I’m pretty sure about that, but the platform itself is disturbing: all code must be C#. You can’t use C/C++ with WP7. And when there can’t be those, there won’t be CPython nor Lua or any scripting language implemented without C# or .NET managing your code, unless you’ll find a C# port for it. And if you did, it most likely lacks in features compared to the original. And then there’s numerous other C/C++ libraries that you can’t use.

Somebody commented on my post saying this is the reason why the platform will fail and nothing except meaningless apps(fart apps,rss readers etc) will be ported. Apps with long history, existing code base and support for multiple platforms can’t be pure C#.  And I agree 100%.

Microsoft wants to avoid fragmentation, well that’s good but not with these restrictions. Lack of “unmanaged code”, as native code is called in .NET land, will be causing fragmentation, not the ability to reuse your code. It’s your code that’s fragmenting so MS doesn’t care. This is even worse than the Apple’s ban on scripting languages, which was removed a while ago. They still allowed reusing old C/C++ libraries, like physics engines in your apps.

If WP7 ever gains popularity among major app/game makers, I believe and wish they’ll make this issue clear to Microsoft as they (I assume) did to Apple. Well, first they need to gain popularity among consumers ;)

Without knowing much about the internal workings of WP7, I don’t see reason to block native libraries. Sure, it’s harder to avoid dll hell with C/C++ as the problem is well known on desktop. But if my app doesn’t use any system libraries but only its own? How many system libraries do you think a physics library might need? How many system libraries does a Lua interpreter need? I can think of one: libc for allocating and freeing memory. All those libraries do is reserve some memory and do some math and give some results back. Sure scripting languages may allow file access etc., but that’s not necessary. I just want to script some logic of the app, not the whole app. Anyhow, I don’t see the point, somebody, please enlighten me. Google & Apple can do this without getting in your way, why not Microsoft?

I have been reading discussions about Nokia-Windows deal, and only fraction seems to think that the whole Nokia-WP7 thing is a good thing. And those who do seem to be… less informed. The only good thing here is that we are finally getting rid of Symbian, but the price is too high.

So what’s the main reason that I’m worried about: to force people use .NET and me to write only C#. We have now witnessed what happened to people skilled with Symbian C++, the fear that I heard soon after Nokia started using Symbian. So don’t try to get us stuck with a single way of doing things. Sure there’s monotouch and monodroid to reuse your code on iPhone and Android. Not sure about them though, not free and they add another layer of complexity to your app. Easier to just learn the platform’s own way. I have no trouble using C#, but that’s not the point: I want to reuse my old code and the other libraries out there. Apple is good boy compared to MS.

And my opinion about C#? Nice, but Qt Quick rules. Sadly, now I can only think that it should rule. *sigh*… back to the drawing board.

Perfect dual boot crypted hard disk setup with Truecrypt and LUKS

I have a work laptop used in Symbian and web development. I need to be able to boot both Vista and Linux. Due to client privacy, both operating systems must be crypted for the case of lost laptop. Even if I do not use Windows actively, its web browser data may contain stored password for client systems and it would be catastrophic to leak them accidentally.

Here are instructions how to encrypt your hard disk in safely but performance effective manner with Ubuntu 8.04 Hardy Heron and Windows Vista. These instructions can be applied for any version of Vista, since we use third party open source Truecrypt suite to encrypt the Windows partition. The instructions also give priority for Grub boot loader, so that the computer will boot to Linux if there is no user interaction during the boot.

  1. Install Windows Vista from the factory first boot installer
  2. Download Ubuntu 8.04 alternative install CD. The alternative install CD contains installer menus to encrypt your HD using LVM and LUKS.
  3. For the sake of performance, we only crypt /home directory on Linux partition which contains all user editable files. All other files in Linux, maybe excluding configuration files in /etc, are open source and encrypting them only slows your application start-up times. It is possible to encrypt /home after install, but it is much easier during the install time. Here are instructions how to set up encrypted home partition with alternative install CD.
  4. After this comes the exciting part. You must encrypt the Windows system partition using Truecrypt. Since Truecrypt is going to overwrite Ubuntu’s Grub bootloader on Master Boot Record (MBR), some magic is needed (detailed instructions).
    1. Install Truecrypt and overwrite MBR.
    2. Boot Ubuntu from live CD. Alternative install CD doesn’t work as it does not have grub binary. You could also try to boot from your Linux partition by giving out manual kernel root file system parameters for the CD boot loader.
    3. Back-up Truecrypt’s MBR to a file on /boot partition using dd
    4. Add Truecrypt’s MBR as a chain boot loader in Grub
    5. Rewrite MBR using Grub

For foreigners: You might want to keep the US keymap in hand, since the installer environment has not necessarily keymap set up correctly.

Note: Since my HP Pavilion dv9000 laptop has two 250 GB hds, the actual setup is following: windows system partition, windows data partition, rest is set up for Linux using LVM in stripe RAID containing the root partition and the crypted home. This effectively gives near 100 MB/s read speed from two 5400 RPM hds.