Monday, December 21, 2009

Saint Perl 2009: Zhuravlev about Regular Expressions

I go on telling about Saint Perl 2009 conference. This time it is a story about Nikolay Zhuravlev and power of Perl regular expressions. I looked forward to this presentation the worst, and it may be the reason, why it appeared to be the worst disappointment.

I expected an interesting story about recursive regular expressions and how they give Perl the power of context-free grammars. (BTW, ask me how. In fact, we should call them Perl context-free grammar expressions, not Perl regular expressions.) But instead the presentation was about boring benchmark graphs for various randomly — well, almost randomly — assembled regular expressions and without any sane resume. (Though he is totally exonerated by the fact, that he is yet a student.)

Thank Darwin, my perverted imagination saved me from deadly bore, since I had been hypnotized by regular expressions the speaker was showing, that resembled.

/(.*)(.*)\2\1/; # a girl
/(.*)(.*)(.*)\3\2\1/; # a mutant girl from Total Recall movie
/(.*)(.*)(.*)(.*)\4\3\2\1/; # a girl with a friend
/(.*)(.*)(.*)(.*)(.*)\5\4\3\2\1/; # a mutant girl from Total Recall movie with a friend

And so on. Ok, you've got the idea. This is what I meant when I wrote about power of Perl regular expressions.

Now I like regular expressions even more.

P. S. I asked Nikolay Zhuravlev if he had read Mastering Regular Expressions by Jeffrey Friedl — the best book about regular expressions I know of — and he answered that he had tried, but it hadn't appeared mathematically precise enough for him. All issues could be avoided if Nikolay had taken this book more seriously.

Saint Perl 2009: Sharifulin about Mojo

On 18. of December I attended the first Perl conference in Saint Petersburg, Russia, Saint Perl 2009. I will tell about my there experience in the next few posts. By the way, on 18. of December 2009 Perl had its 22th anniversary.

In the first post dedicated to Saint Perl 2009 I would like to appreciate the most interesting (in my humble opinion) presentation by Anatoly Sharifulin about Mojo, Mojolicious and Mojolicious::Lite. Mojo and its descendants are convenient Web frameworks for Perl and in Perl. I won't retell the whole Anatoly's story, but Russian-speaking girls (as well as guys) may have a look at his slideshow.

In his presentation Anatoly mentioned the codex of coding guidelines for Mojo, established by Sebastian Riedel, the Mojo developer. Among some stupid and useless statements, such as "It's not a feature without a test" or "No spaghetti code" there is a profound truth there, that burned my brain out: "Every file should contain at least one quote from The Simpsons or Futurama."

Being highly motivated by Anatoly's presentation though not particularly by this guideline, I went to read the Mojo's source code, not to mention that there's no decent documentation for Mojo. And when I found no original quote in one of the source files, I immediately opened a bug. Yes, I'm a bore, that's me all over. Kudos to Sebastian, he fixed the bug in just half an hour! It's the fastest fix for a bug I have ever submitted for a CPAN module :)

Monday, December 07, 2009

PunBB/FluxBB Extension for Private Message Announcements

I have a hobby. I'm an administrator of the forum for Plantarium, a site dedicated to plants of Russia and its neighbors. It's powered by PunBB 1.3.

Someone told me it is hard to notice if there are unread private messages. So I've written an extension to display an announcement, when a new private message arrives. That's how it looks:

Private Message Announcements screenshot

Source Code

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

blah blah blah

Download the source code at Gitorious.

Tuesday, December 01, 2009

IdeaPad S9/S10 WiFi Ubuntu Voodoo

On Sunday I finally got my demicrosofted Lenovo IdeaPad S9 back. I installed Ubuntu Netbook Remix 9.10 (Karmic Koala) on it. Alas! WiFi didn't work. But I compiled a powerful voodoo spell to manage this issue and I am happy to share this magic with you.

First recite this verse.

sudo apt-get update
sudo apt-get install ndiswrapper-utils-1.9
mkdir ~/bcm43xx; cd ~/bcm43xx

wget http://myspamb8.googlepages.com/R174291-pruned.zip
unzip R174291-pruned.zip

sudo ndiswrapper -i bcmwl5.inf
ndiswrapper -l
sudo depmod -a
sudo modprobe ndiswrapper
sudo cp /etc/network/interfaces /etc/network/interfaces.orig
echo -e 'auto lo\niface lo inet loopback\n' | sudo tee /etc/network/interfaces
sudo ndiswrapper -m
echo 'ndiswrapper' | sudo tee -a /etc/modules
echo 'ENABLED=0' | sudo tee -a /etc/default/wpasupplicant

Then use this verse, but slightly modified to avoid warnings about deprecated filenames.

mkdir fixinitrd
cd fixinitrd
cp /boot/initrd.img-`uname -r` ./initrd.gz
mkdir initrd
cd initrd
gunzip < ../initrd.gz | cpio -i --make-directories
echo blacklist b43 >> ./etc/modprobe.d/blacklist.conf
echo blacklist ssb >> ./etc/modprobe.d/blacklist.conf
cd ..
find ./ | cpio -H newc -o > ../initrdfixed
cd ..
gzip initrdfixed
sudo cp ./initrdfixed.gz /boot/initrd.img-`uname -r`

Please backup your /boot/initrd.img-`uname -r` before casting the spell, for it is dangerous kernel magic that can backfire.

Wednesday, November 18, 2009

Free As a Font

I love free software without patents, I love free art without royalties. And I am falling in love with Gentium font. There are a bunch of free fonts, but most of them don't have Cyrillic letters. Gentium has. I like serif fonts, and Gentium is a serif. And it's stylish.

The phrase "This is my favourite font", written in English and Russian with Gentium font.

Oh my Darwin, I love it. There are no words to describe how much I do. But there is a Beatles' song which tells how I feel about Gentium.

Whatever happened to
the life that we once knew?
Always made me feel so free.

Free as a bird.
It's the next best thing to be.

Return To Innocence

Last Saturday my wife and I finally decided, that one computer is not enough for us two. We went to MediaMarkt and bought a Lenovo S9 netbook. I don't know, if it is a problem in your country, but in Russia you cannot easily buy a notebook, which wouldn't have Microsoft Windows installed on it.

Kudos to Lenovo for it is one of those few manufacturers, that has a Microsoft Windows return policy. That was one of the reasons why I chose Lenovo. But still it can take up to 10 days to get your money back, and you should give your computer away for that period. That wasn't an option for me, because that day I had to do some free-lance work I got and that was what I bought the computer for that very day.

So I took it home to boot from live USB, since you cannot neither activate Microsoft Windows, nor sweep it away before you give it to a service center, if you want your money back for it. I asked my wife if she got 1 Gb USB flash drive to boot Ubuntu Netbook Remix, and she said she had.

Alas. The only USB flash drives we got were all 512 Mb. I googled, but found nothing about if I can run UNR from 512 Mb flash drive. Aardvark didn't help me either.

Then I downloaded Debian Live USB. The image with XFCE flavour didn't fit on 512 Mb flash drive, though the file is less than that. So I booted my netbook with LXDE-flavoured Debian Live USB.

They give only 300 roubles (about $10) for the Microsoft Windows XP installed on the netbook, but it would be just enough to buy 2 Gb flash drive (299 roubles) to install Ubuntu Netbook Remix. It's somewhat symbolic, I think. Ten bucks is not much, but I adhere to the principle.

Today I finally gave my netbook to the service center. Now I'm waiting ten days to get my netbook with COA brand removed, innocent, pure and free as a baby. The music will better tell how I feel now.

Be yourself don't hide
Just believe in destiny

Don't care what people say
Just follow your own way
Don't give up and use the chance
To return to innocence

That's not the beginning of the end
That's the return to yourself
The return to innocence

Sunday, November 15, 2009

'Cannot allocate memory' Error When Ungzipping 03modlist.data.gz

If you've got the following error:

Going to read /root/.cpan/sources/modules/03modlist.data.gz
Could not pipe[/bin/gzip --decompress --stdout /root/.cpan/sources/modules/03modlist.data.gz |]: Cannot allocate memory at /usr/share/perl/5.8/CPAN.pm line 5728.

you are likely using VPS (Virtual Private Server) with little RAM. Fortunately, last versions of CPAN.pm handle this problem better, though CPAN.pm will likely go to swap anyway, so get prepared to wait. Unfortunately, you cannot use CPAN.pm to upgrade your CPAN.pm because of this error.

What you need to do is to install CPAN.pm manually. Go to http://search.cpan.org/dist/CPAN/ and download the latest stable version, e. g.

wget http://search.cpan.org/CPAN/authors/id/A/AN/ANDK/CPAN-1.9402.tar.gz
tar -xzf CPAN-1.9402.tar.gz
cd CPAN-1.9402/
perl Makefile.PL
make
make test
sudo make install

Stop as many daemons as possible, particularly those requiring much memory, such as Apache and MySQL. Then proceed with

sudo perl -MCPAN -eshell

Enjoy!

Wednesday, October 28, 2009

PunBB/FluxBB Extension for Showing Most Subscribed Topics

Hello, this is another piece of code of mine. It is an extension for PunBB/FluxBB 1.3 forum engine, that adds a link in the header to a page, that shows most subscribed topics. Available languages are English and Russian. You can see demonstration here (sorry, the site is in Russian).

I decided to put all my code to Gitorious, step by step. You may ask, why not SourceForge, freshmeat.net, Google Code, GitHub or your favorite source hosting site, not listed above? The answer is: Gitorious is the only source hosting webapp, that distributes its own source code under the terms of GNU AGPL.

GNU AGPL is like GNU GPL on steroids. Basically, it extends the definition of software use to match the webapp concept. So, if you're using a webapp that is distributed under the terms of GNU AGPL, you should be able to get its source code. I believe, that free software should be served by free software, hence I chose Gitorious.

You can get the source code of the extension here. The code is distributed under the terms of GNU GPL version 3 or later.

Update: Hmmm... Lauchpad Suite, which powers Launchpad, is a GNU AGPL project too. But have you heard of Bazaar before? I haven't :-/ Have you heard of Git? Well, nevermind, it's a rhetoric question.