Antena

Illustration

Another issue of scratching-an-itch with new application is my newest Android application. I had to mount my terrestrial TV antenna and I figured that there should be easier way to align it with DVB-T signal towers.

Result of that “one night stand” is Antena. Application that will show you all towers in 100 km radius and signal you when alignment is made. For that purpose it needs something to give it location (GPS?) and compass.

Unfortunately it is usable only in Croatia. There are no plans to make it work in others countries.

P.S. If someone is really interested in making it work somewhere else, all that is needed are GPS coordinates of towers and a beer. With those two items we can make it work anywhere.

Private Mercury

Illustration

Sharing source with Mercurial is not hard. There is quite a good guide at Martin’s Blog and, indeed, first part of this post will mostly follow his setup.

Sharing sources with password authentication is still not hard but (at least from my perspective) is not obvious. This post will document my efforts of creating private and password protected Mercurial storage.

This procedure is tested on Ubuntu 10.04.1 LTS but I would expect it to work on older versions as well.

First we need to install it’s package.

sudo apt-get install mercurial
 Reading package lists... Done
 Building dependency tree       
 Reading state information... Done
 The following extra packages will be installed:
   mercurial-common
 Suggested packages:
   qct vim emacs kdiff3 tkdiff meld xxdiff python-mysqldb python-pygments
 The following NEW packages will be installed:
   mercurial mercurial-common
 0 upgraded, 2 newly installed, 0 to remove and 63 not upgraded.
 Need to get 1,182kB of archives.
 After this operation, 4,956kB of additional disk space will be used.
 Do you want to continue [Y/n]? Y
 Get:1 http://hr.archive.ubuntu.com/ubuntu/ lucid/universe mercurial-common 1.4.3-1 [1,131kB]
 Get:2 http://hr.archive.ubuntu.com/ubuntu/ lucid/universe mercurial 1.4.3-1 [50.7kB]
 Fetched 1,182kB in 3s (388kB/s)
 Selecting previously deselected package mercurial-common.
 (Reading database ... 124142 files and directories currently installed.)
 Unpacking mercurial-common (from .../mercurial-common_1.4.3-1_all.deb) ...
 Selecting previously deselected package mercurial.
 Unpacking mercurial (from .../mercurial_1.4.3-1_i386.deb) ...
 Processing triggers for man-db ...
 Setting up mercurial-common (1.4.3-1) ...
 Setting up mercurial (1.4.3-1) ...
 Creating config file /etc/mercurial/hgrc.d/hgext.rc with new version
 Processing triggers for python-support ...

Create location for Mercurial repositories at /srv/hg with cgi-bin at subdirectory:

sudo mkdir -p /srv/hg/cgi-bin
sudo cp /usr/share/doc/mercurial-common/examples/hgweb.cgi /srv/hg/cgi-bin/

Additionally we need “/srv/hg/cgi-bin/hgweb.config” (do not forget to sudo) with following lines:

[collections]
/srv/hg/ = /srv/hg/

In newer Mercurial installations you also need to edit “/srv/hg/cgi-bin/hgweb.cgi” in order to fix config parameter. Just change example config line with:

config = "/srv/hg/cgi-bin/hgweb.config"

Next thing to do is installing apache web server:

sudo apt-get install apache2
 Reading package lists... Done
 Building dependency tree       
 Reading state information... Done
 The following extra packages will be installed:
   apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1
   libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libssl0.9.8
 Suggested packages:
   apache2-doc apache2-suexec apache2-suexec-custom
 The following NEW packages will be installed:
   apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common
   libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
 The following packages will be upgraded:
   libssl0.9.8
 1 upgraded, 9 newly installed, 0 to remove and 62 not upgraded.
 Need to get 6,343kB of archives.
 After this operation, 10.2MB of additional disk space will be used.
 Do you want to continue [Y/n]? Y
 Get:1 http://hr.archive.ubuntu.com/ubuntu/ lucid-updates/main libssl0.9.8 0.9.8k-7ubuntu8.1 [3,015kB]
 Get:2 http://hr.archive.ubuntu.com/ubuntu/ lucid/main libapr1 1.3.8-1build1 [116kB]
 Get:3 http://hr.archive.ubuntu.com/ubuntu/ lucid/main libaprutil1 1.3.9+dfsg-3build1 [85.4kB]
 Get:4 http://hr.archive.ubuntu.com/ubuntu/ lucid/main libaprutil1-dbd-sqlite3 1.3.9+dfsg-3build1 [27.1kB]
 Get:5 http://hr.archive.ubuntu.com/ubuntu/ lucid/main libaprutil1-ldap 1.3.9+dfsg-3build1 [25.1kB]
 Get:6 http://hr.archive.ubuntu.com/ubuntu/ lucid-updates/main apache2.2-bin 2.2.14-5ubuntu8.2 [2,622kB]
 Get:7 http://hr.archive.ubuntu.com/ubuntu/ lucid-updates/main apache2-utils 2.2.14-5ubuntu8.2 [159kB]
 Get:8 http://hr.archive.ubuntu.com/ubuntu/ lucid-updates/main apache2.2-common 2.2.14-5ubuntu8.2 [290kB]
 Get:9 http://hr.archive.ubuntu.com/ubuntu/ lucid-updates/main apache2-mpm-worker 2.2.14-5ubuntu8.2 [2,366B]
 Get:10 http://hr.archive.ubuntu.com/ubuntu/ lucid-updates/main apache2 2.2.14-5ubuntu8.2 [1,484B]
 Fetched 6,343kB in 14s (440kB/s)                                               
 Preconfiguring packages ...
 (Reading database ... 124530 files and directories currently installed.)
 Preparing to replace libssl0.9.8 0.9.8k-7ubuntu8 (using .../libssl0.9.8_0.9.8k-7ubuntu8.1_i386.deb) ...
 Unpacking replacement libssl0.9.8 ...
 Setting up libssl0.9.8 (0.9.8k-7ubuntu8.1) ...
 Processing triggers for libc-bin ...
 ldconfig deferred processing now taking place
 Selecting previously deselected package libapr1.
 (Reading database ... 124530 files and directories currently installed.)
 Unpacking libapr1 (from .../libapr1_1.3.8-1build1_i386.deb) ...
 Selecting previously deselected package libaprutil1.
 Unpacking libaprutil1 (from .../libaprutil1_1.3.9+dfsg-3build1_i386.deb) ...
 Selecting previously deselected package libaprutil1-dbd-sqlite3.
 Unpacking libaprutil1-dbd-sqlite3 (from .../libaprutil1-dbd-sqlite3_1.3.9+dfsg-3build1_i386.deb) ...
 Selecting previously deselected package libaprutil1-ldap.
 Unpacking libaprutil1-ldap (from .../libaprutil1-ldap_1.3.9+dfsg-3build1_i386.deb) ...
 Selecting previously deselected package apache2.2-bin.
 Unpacking apache2.2-bin (from .../apache2.2-bin_2.2.14-5ubuntu8.2_i386.deb) ...
 Selecting previously deselected package apache2-utils.
 Unpacking apache2-utils (from .../apache2-utils_2.2.14-5ubuntu8.2_i386.deb) ...
 Selecting previously deselected package apache2.2-common.
 Unpacking apache2.2-common (from .../apache2.2-common_2.2.14-5ubuntu8.2_i386.deb) ...
 Selecting previously deselected package apache2-mpm-worker.
 Unpacking apache2-mpm-worker (from .../apache2-mpm-worker_2.2.14-5ubuntu8.2_i386.deb) ...
 Selecting previously deselected package apache2.
 Unpacking apache2 (from .../apache2_2.2.14-5ubuntu8.2_i386.deb) ...
 Processing triggers for man-db ...
 Processing triggers for ufw ...
 Processing triggers for ureadahead ...
 ureadahead will be reprofiled on next reboot
 Setting up libapr1 (1.3.8-1build1) ...
 Setting up libaprutil1 (1.3.9+dfsg-3build1) ...
 Setting up libaprutil1-dbd-sqlite3 (1.3.9+dfsg-3build1) ...
 Setting up libaprutil1-ldap (1.3.9+dfsg-3build1) ...
 Setting up apache2.2-bin (2.2.14-5ubuntu8.2) ...
 Setting up apache2-utils (2.2.14-5ubuntu8.2) ...
 Setting up apache2.2-common (2.2.14-5ubuntu8.2) ...
 Enabling site default.
 Enabling module alias.
 Enabling module autoindex.
 Enabling module dir.
 Enabling module env.
 Enabling module mime.
 Enabling module negotiation.
 Enabling module setenvif.
 Enabling module status.
 Enabling module auth_basic.
 Enabling module deflate.
 Enabling module authz_default.
 Enabling module authz_user.
 Enabling module authz_groupfile.
 Enabling module authn_file.
 Enabling module authz_host.
 Enabling module reqtimeout.
 Setting up apache2-mpm-worker (2.2.14-5ubuntu8.2) ...
  * Starting web server apache2
 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
 Setting up apache2 (2.2.14-5ubuntu8.2) ...
 Processing triggers for libc-bin ...
 ldconfig deferred processing now taking place

We need new configuration for web interface of our repositories (“/etc/apache2/sites-available/hg”) with following content:

NameVirtualHost *
<VirtualHost *>
    ServerAdmin webmaster@localhost
    DocumentRoot /srv/hg/cgi-bin/
    <Directory "/srv/hg/cgi-bin/">
        SetHandler cgi-script
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog /var/log/apache2/hg.log
    <Location />
        AuthType Basic
        AuthName "Mercurial"
        AuthUserFile  /srv/hg/.htpasswd
        Require valid-user
    </Location>
</VirtualHost>

Lines under Location are ones that ensure privacy of our repository.

We can now disable default web site and enable new one (and we can ignore all warnings) together with changes of ownership and rights:

sudo chown -R www-data /srv/hg

sudo chmod a+x /srv/hg/cgi-bin/hgweb.cgi

sudo a2dissite default
 Site default disabled.
 Run '/etc/init.d/apache2 reload' to activate new configuration!

sudo a2ensite hg
 Enabling site hg.
 Run '/etc/init.d/apache2 reload' to activate new configuration!

sudo /etc/init.d/apache2 reload
  * Reloading web server config apache2
 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
 [warn] NameVirtualHost *:80 has no VirtualHosts

If we try to access “http://localhost” now, we should be greeting with password prompt.

Thing that we are missing is “/srv/hg/.htpasswd” file. We can create all users we need with htpasswd command:

sudo htpasswd -c /srv/hg/.htpasswd testuser
 New password: 
 Re-type new password: 
 Adding password for user testuser

All further users are then added with slightly modified command (notice that -c is missing):

sudo htpasswd /srv/hg/.htpasswd testuser2
 New password: 
 Re-type new password: 
 Adding password for user testuser2

After creating repository itself

sudo hg init /srv/hg/TestRepo

we must also create “/srv/hg/TestRepo/.hg/hgrc” file with following content:

[web]
push_ssl=false
allow_push=testuser

This allows for using http (instead of https) and allows access to our “testuser” (if there are no restricturons, just put * for user name). Very last step in setup is actually allowing apache to use our repository for writing. Easiest thing to do here is just transferring ownership to it:

sudo chown -R www-data /srv/hg/TestRepo

Finally we can use “http://192.168.0.2/hgweb.cgi/TestRepo/” for pushing and pulling data from any Mercurial client.

P.S. To use https, check second post of a series.

What a Loop!

As I tried to install Ubuntu 10.04 inside of Windows Virtual PC, I kept getting message:

(initramfs)mount:mounting/dev/loop0 on //filesystem.squashfs failed: Input/output error
can not mount/dev/loop0 (/cdrom/casper/filesystem.squashfs) on//filesystem.squashfs

Since I knew that anything with *nix in it’s name will be a problem for Virtual PC, I tried every switch there is and result was either this message or machine would turn itself off.

It took me a while to notice that my ISO file was only 200 MB. Since Ubuntu CD should be almost 700 MB, culprit was found. It was simple case of corrupt CD.

It always amazes me how quick I am to search for deeper issues without checking simplest reason for failure first.

P.S. Great guide on installing Ubuntu can be found at Scott Hanselman’s blog.

Visual Basic and Windows Phone 7

One thing that C# could do and Visual Basic could not was development for Windows Phone 7. I will not get too much into whether this is even an issue, but I will notice that it is no longer true.

Visual Basic developers can now download Microsoft Visual Basic CTP for Windows® Phone Developer Tools.

CTP stands for Community Technical Preview and it is closest to something in alpha stage. It will not be usable for production environment and it will take a while for final version to come. However, it is a big step forward.

Extracting Part of Mercurial Repository

As I started to work with Mercurial, I added almost everything in single repository. Time passed and I wanted to move some data to separate one. And this became a problem. There is no obvious way to split repository. However, there is something almost as good - exporting it.

Since I am Windows user, I will give instructions for Windows here. All things should work on Linux also but configuring it to work properly might (and will) differ. I will also assume that you have Mercurial already installed. I tested this with TortoiseHg but other clients should work also.

First step is to enable ConvertExtension on our computer. Just editing “mercurial.ini” under home folder and adding two lines will do:

[extensions]
convert =

If there is “[extensions]” sections inside already, just add “convert =” under it instead of creating new one. Home folder on Windows Vista and 7 is probably located at “C:\Users\YourName”. XP users should look under “C:\Documents and settings\YourName”. If you moved it somewhere else, search for it yourself. :)

Another file that we need to prepare is one used for filtering out things we do not need. Lets store it at “C:\map.txt” and add following text to it:

include &quot;Electronics/Elsidi&quot;
rename &quot;Electronics/Elsidi&quot; &quot;.&quot;

Text in quotes is location of directory in original repository. First line includes only files at directory we wish to extract and second one moves those files to root directory (.) of new repository. Do notice that we use paths relative to root of repository and that path IS case sensitive.

I will assume here that “hg.exe” is somewhere in path so you can execute it without problem. In other cases, just write full path to it every time I write “hg”. In my case this is “C:\Program Files (x86)\TortoiseHg\hg”.

Last thing to do is executing conversion itself and update of new repository afterward:

hg convert C:\OriginalRepository C:\NewRepository C:\revmap.txt --filemap C:\map.txt
scanning source...
sorting...
converting...
18 Adding initial Android applications.
17 Initial push.
16 Elsidi rev3.
15 Moving Elsidi directories.
14 Elsidi rev6
13 Elsidi rev G.
12 Power (rev B).
11 Last version of UTF8.
10 Added As.
9 Adding Encoded.
8 Adding World.
7 Adding Unicode.
6 Adding In.
5 Adding Joint.
4 Adding Smokes.
3 Adding Device.
2 Adding Android.
1 Added Test.
0 Adding QText

cd C:\NewRepository

hg update
31 files updated, 0 files merged, 0 files removed, 0 files unresolved

With this you should have your new repository ready. Only files under desired path will be there (moved to root) and all history will be preserved.

Revmap.txt is here just so you can continue interrupted process. If you want to start whole process from start just delete both it (revmap.txt) and new repository’s directory (C:\NewRepository).

Hope this works for you.

P.S. If you see “C:\NewRepository” with just “.hg” folder inside and nothing else, you probably forgot to execute “hg update” command.

P.P.S. This procedure will leave exported data in original repository. You might remove it yourself but do notice that you will not recover any disk space - nothing is really deleted with Mercurial.