Music

April 22nd, 2010 subogero 1 comment

One needs music for healthy hacking, especially in a noisy office. Monotonous, repetitive tunes are especially well suited for this kind of activity. Electronic genres like drum&bass, downtempo, dub and deep house spring to the mind. And the very kings of these are non other than the “Wiener Klassiker” who’ve just turned 16 years old:

Peter Kruder & Richard Dorfmeister

In true Free and Open Source fashion, they have released not one but two albums, freely and legally downloadable in mp3 format from G-Stoned’s website until 16 May. The CDs are in the shops from 17 May:

  • 13 F**king New Tracks
  • 12 F**king Classics

I’ve just started listening them, they rock… erm… downtemo.

Categories: Uncategorized Tags:

Linux Credits

April 9th, 2010 subogero Comments off

I happened to activate the “Source” repos in Synaptic today and then downloaded the Linux 2.6.28 source code. Just for fun.

I also happened to have a look into CREDITS. It turned out to be an interesting read. It seems Linux comes from the happier parts of the world. Let’s see:

++ I'm proud to announce four Hungarian kernel hackers
++ But the happiest part of the Eastern Block seems to be the Czech Republic
++ The North rocks, or rather hacks (Finland, Sweden, Denmark, Canada)
++ The bulk comes from the West (USA, UK, Germany, Netherlands, France, Italy)
++ Eric S. Raymond is there (a.k.a. Master Foo)
++ Japan in da house
++ The Republic of China (Taiwan) beats ...
-- ... the People's Republic of China (only one hacker for 1 billion people)
-- India, just one? Come on! (Even he is Malaysian)
-- Same for Israel. Although I always knew Haifa is the best place there
-- Absolutely zero from Islamic countries.

I have a theory about the effects the “Religion of Peace” has on the human brain. It seems to be confirmed.

Perl 3

April 6th, 2010 subogero Comments off

The Camel Book has arrived. It does not reach P. G. Wodehouse’s joke density (3 per word), but it’s close. And it’s 1000 pages. So Larry may have beaten Pelham Grenville in the overall joke count.

Perl 2

April 2nd, 2010 subogero Comments off

I’ve ordered the Camel Book. Can’t wait…

Categories: Uncategorized Tags: , ,

Perl

March 27th, 2010 subogero Comments off

I love Perl. The beautiful friendship started blossoming recently. I remember a few years ago, before I got infected with Unix, I was always scared to death when confronted with Perl. But after half a year of meddling with Bash, GNU coreutils and regular expressions, I happened to look into an occasional Camel-smelling script and, much to my surprise, I was literally shocked by its beauty. Let me list my personal highlights.

Perl is like human languages.

open(FILE, "< $filename") or die "$filename could not be opened for reading.";

In Perl, there are many ways to express yourself to stress different things, like in human languages. Not like in German.

if ($foo) { print "Foo!"; }
print "Foo!" if ($foo);
print "Foo!" unless (!$foo);

Perl is very terse, like good slang.

Ever heard of Perl Golf?

Perl comes with batteries included.

With everything from Bash and coreutils, without using any extra modules. In the little Hungarian calendar below, I open a filehandle for a pipe from another program, I use the command line arguments, I do string substitutions.

#!/usr/bin/perl
open CAL, "cal -m @ARGV |";
while (<CAL>) {
  s/January/ Január/;
  # translations for other months and days ...
  print;
}
close CAL;

I forget, where did I hear this “batteries included” last time?

Default variable $_, especially when it’s not even written. Just like ogc (or vice versa).

Look at the code above. Guess what the s/// substitution is working on? Guess what is printed? Exactly. The hidden $_ variable, the result of the previous operation.

Variable substitution within regular expressions.

In my first ever Perl-script I came across some substitution problem where a part of the pattern to change was stored in a variable. I thought: How nice it would be to be able to put the variable into the regexp. I googled it. Of course it works.

$foo =~ s/(^.* )$variable$/$1$bar/;

And don’t tell me it’s unreadable…

Perl is available for Windows.

At the slightly brain-damaged company I work for, I can write small programs for slightly brain-damaged users. They don’t have to install Cygwin to run them, but Perl gives me the full arsenal of Unix.

The Perl style guide.

Compactness. Readability. No bullshit.

The Camel book.

I keep laughing out loud reading it.

Larry Wall is a Bible guy.

Remember, Perl comes from a linguist who originally wanted to translate the Bible into exotic languages.

Larry Wall is always right.

Even when he is not.

Categories: Uncategorized Tags: , ,

Jaunty Keyboard Layout Settings 2

March 18th, 2010 subogero Comments off

Finally. I’ve picked up my US keyboard for the ASUS UL20A today. Installation was surprisingly easy, with no warranty-void-if-removed stickers anywhere. Time to play again with keyboard settings. Default layout became US International (with dead keys). I kept Hungarian (qwerty) as well for the occasional őŐűŰ. And now to the most interesting part, the Layout Options.

Ctrl Key Position, Make CapsLock an additional Ctrl.
Hurraaaaah!!!! The bloody CapsLock is eliminated at last!

Key(s) to Change Layout, Both Shift keys together.
A combination of keys far away from each other, never normally used together.

Use keyboard LED to show alternative layout. CapsLock.
Of course. As the bastard is dead, I can use its LED to indicate if the Hungarian layout is active.

This incredible abundance of keyboard settings is amazing. A good reason alone to choose Linux over Windows.

Old Stuff Forever

March 3rd, 2010 gergo Comments off

I just read a quite interesting article full with pictures, that blow my mind. What can take 5 or 10 second to load a page. That was the last kick to try lynx.
First of all I checked it, maybe I already have it, so just type lynx, and I got:

The program ‘lynx’ can be found in the following packages:
* lynx-cur
* lynx-cur-wrapper
Try: sudo apt-get install
lynx: command not found

That’s the spirit that I like, respect for the parents. So after 5 minutes I have been a happy user of lynx.
The first test was the article itself:

$ lynx http://belsoseg.blog.hu/2010/02/28/hogyan_nem_vettem_svedorszagbol_ven_mercit

and I got my first suprise:

belsoseg.blog.hu cookie: PHPSESSIDv2=3fc04fea2eef22ad919e54d9b45e3066 Allow? (Y/N/Always/neVer)

then just put a v and you are out of the watching eyes of the big brother, free like at the dawn of the net. After it an another cookie try to watch my activity but I just laugh in her face.

Of course there are dark sides of lynx: in case of Hungarian text the accents can cause some ugly stuff. But this is my own problem to stick to my mother language. So guys if want to break down your monitor because of slow internet I can say there are other options.

Categories: Uncategorized Tags: ,

Bash – Check if Directory Writable

February 28th, 2010 subogero 2 comments

Back to the basics, a.k.a. the Bourne Again Shell.

How to check in a script whether a directory is writable? Many would suggest the

if [ -w $DIR ]; then echo Do semething; fi

way, but it just checks the writable flag, which may be set on something on a read-only-mounted device. It’s much better to effectively try it.

Do something if $DIR is not writable

touch ${DIR}/foo && rm -f ${DIR}/foo || echo Do something

Do something if $DIR is writable

touch ${DIR}/foo && rm -f ${DIR}/foo && echo Do something

Do something if $DIR is writable, otherwise suppress the error message

touch ${DIR}/foo 2>/dev/null && rm -f ${DIR}/foo && echo Do something

Do something if $DIR is writable, otherwise print a custom diagnostic message

touch ${DIR}/foo 2>foo && rm -f ${DIR}/foo && echo Do something
cat foo | sed 's/.*/Directory not writable!/' && rm -f foo

The above case is a bit special. Let’s see what happens:

  • touch attempts to create file “foo” in $DIR
  • it’s potential error message is redirected to file “foo” in currect dir
  • the commands afters “&&” are only executed if touch has succeeded
  • if so, file “foo” in $DIR is removed and we “Do something”
  • the error message stored in “foo” is replaced by our own, using sed
  • file “foo” with the original error message is removed.

Note: the sed-pipeline cannot be integrated into the first line, because pipelines only fail if their last command does, so we would forget whether “touch” has failed or not.

Categories: Uncategorized Tags: , ,

Apple vs Ubuntu

February 11th, 2010 subogero Comments off

Apple’s products are simply beautiful. Mac mini, iPod Nano, MacBook or iPhone: anything they do, they do it with style.

Except, they don’t always work, apparently. During the weekend’s skiing/snowboarding trip, one of us wanted to transfer some important photos (showing just-about-to-fall snowboarders) from her iPhone (gorgeous pink cover) to her MacBook (gorgeous flat chassis). No way.

So we connected the iPhone to my Ubuntu-driven notebook, the “Apple Inc. iPhone” icon promptly appeared on the desktop, and in a few minutes time the compromising pictures were transferred to the MacBook travelling on board of a carefree pendrive.

Categories: Uncategorized Tags: , , , ,

Dive into Python

January 5th, 2010 subogero Comments off

Literally.

I am very interested in the chronology of Biblical events (anything in the Bible, actually).
Problem: the Bible refers to the time of events always relative to other events. When was the Big Flood relative to Adam’s creation? All we are told is it happened when Noah was 600 years old.

The goal:

  • Create a program that calculates the time of biblical events relative to a single event.
  • The events shall be entered as specified in the Bible, that is, relative to other events.
  • Events should have an optional duration (e.g. the life of Methuselah).
  • Print the result in a nice table-like format
  • Create a timeline diagram

The means: Python

Events are entered into an xml-file, specifying a reference event and a start-time relative to that, and an optional duration. There must be a root event without a reference event, obviously. It looks like this:

<data>
  <event name="Adam" duration="930"/>
  <event name="Seth" ref="Adam" start="130" duration="912"/>
  <event name="Enos" ref="Seth" start="105" duration="905"/>
  <event name="Kenan" ref="Enos" start="90" duration="910"/>
  <event name="Mahalalel" ref="Kenan" start="70" duration="895"/>
  <event name="Jared" ref="Mahalalel" start="65" duration="962"/>
  <event name="Enoch" ref="Jared" start="162" duration="365"/>
  <event name="Methuselah" ref="Enoch" start="65" duration="969"/>
  <event name="Lamech" ref="Methuselah" start="187" duration="777"/>
  <event name="Noah" ref="Lamech" start="182" duration="950"/>
  <event name="Shem" ref="Noah" start="502" duration="600"/>
  <event name="Ham" ref="Noah" start="502"/>
  <event name="Japhet" ref="Noah" start="502"/>
  <event name="Flood" ref="Noah" start="600" duration="1"/>
  ...

The xml file is passed to the Python program as an argument, which parses it using the xml.dom.minidom package. An optional argument specifies the name of the event at zero years, otherwise everything is calculated from the root event (Adam).

$ ./tline.py BibleTime.xml Adam

We get this on the console:

       Adam     0   930
       Seth   130  1042
       Enos   235  1140
      Kenan   325  1235
  Mahalalel   395  1290
      Jared   460  1422
      Enoch   622   987
 Methuselah   687  1656
     Lamech   874  1651
       Noah  1056  2006
       Shem  1558  2158
        Ham  1558
     Japhet  1558
      Flood  1656  1657

If you call tkline.py, you also get a timeline window using the Tk-binding of Python, the Tkinter package:

Timeline

Timeline

Before, I did not know Python, never made GUI programs and never used XML. This program took me less than one day to develop. Any questions?

The source code: bible.7z