Sunday, November 25, 2012

I don't live here anymore

My new blog address is oz123.github.com.

My new blog has feeds for each category, so If you are only interested in following a certain topic that occupies me, and you don't want to hear about my radical opinions about cycling or politics, subscribe to the appropriate feeds:

http://oz123.github.com/tags/python/atom.xml
http://oz123.github.com/tags/debian/atom.xml

etc.

You are also welcomed to subscribe to my main feed:
http://oz123.github.com/atom.xml

Oz.

Thursday, August 09, 2012

GNU vs Canon

Linux does not exist in American conusmer market. At least not for Canon.


Fuck Canon USA
America is sometimes a very weired place.

Praise Canon Europe. Are they the same company???

Ich liebe Deutschland :D.

If you happen to use Canon products on Linux, look for their drivers for GNU\Linux in www.canon-europe.com.

Saturday, July 28, 2012

Working With Binary Data in Python

This puzzled me for quite a time, so here is a post explaining some of my findings.
First we define a bytes array:
 s = bytearray(b"Hello World")
 for i in s: 
     print i
 ...
 72
 101
 108
 108
 111
 32
 87
 111
 114
 108
 100

now, let's write this data to a file:
 f = open('helloword.bin','wb')
 for i in s:                                                                                                                                       
    f.write(struct.pack("I",i))
 f.close()

Let's inspect the file created:
 
 $ du -h points.bin
 4.0K    points.bin
 $ file points.bin
 points.bin: data
 $ less points.bin
 "points.bin" may be a binary file.  See it anyway?

Binary file sizes

let's us write "hello world" into a text file in a text form:

 f = open('helloword.txt")
 f.write("hello world")
 f.close()

Once again we can inspect the file:

$ du -h   helloworld.txt
 4.0K    helloworld.txt


Now, what happens if we make a longer binary array?


 s.split()
 s.append(33)
 bytearray(b'Hello World!')
 for i in range(10000): s.append(33)
 f = open('longhelloword.bin', 'wb')
 import struct      
 for i in s: f.write(struct.pack("I",i))
 f.close()
 f = open('longhelloword.txt', 'w')
 hello = "Hello World!"
 for i in range(10000): hello = hello+"!"
In a shell, examaining the file sizes:
 
 $ du -h longhelloword.bin
 40K     longhelloword.bin
 $ du -h longhelloword.txt
 12K     longhelloword.txt

Wait a minute ! Why is the binary file almost 4 times bigger?

The answer is: it depends on the format specifier in struct.pack.
Namely, we used an unsigned int, for each character we then reserved 4 bytes!.
When we saved the text, every character was assigned to the file exactly as a char which takes one byte only.

If we repeat the above with struct.pack("b",i) the sizes of the file won't differ:

 f = open('longhellowordwithchar.bin', 'w')
 for i in s: f.write(struct.pack('b',i))
 f.close()

and in the shell:

 $ du  longhellowordwithchar.bin
 12      longhellowordwithchar.bin
 $ du  longhelloword.txt       
 12      longhelloword.txt

Credits:
http://dabeaz.blogspot.de/2010/01/few-useful-bytearray-tricks.html
http://docs.python.org/library/struct.html#module-struct

Thursday, May 24, 2012

Why does the Billlion Dollar OpenSource Company does not matter or should not matter

Once in a while I bump into posts praising Red Hat for the fact that its Financial Worth in the Stock Market has crossed the 1 Billion Dollar. Every time I read these posts I shiver. And let me explain why.
It's not that I have something against the technical merits of Red Hat. In my daily work, I support mostly CentOS and Red Hat servers, and I enjoy using them. However, at home I use Debian almost exclusively. But my point is not that Debian is better or worse. I just want to use Debian as an example of how Open Source drives new economic models, while counting the stock market worth of Red Hat is old style economy. So let's see what I mean.
First, I shiver when I think "oh god, how short is people's memory". Just two years ago, the stock market collapsed and literally vaporized many many people's savings, but the same people who were "managing" this stock market industry went home without losing a cent, and today? The stock market is alive, and people keep buying stocks - and if the worthy of Red Hat is increasing, it's because people are willing to pay more for a tiny piece of Red Hat. But what is a Stock worth if the company has no real holdings - besides it's office buildings ?  Not much, unless you are promised that the company will pay you dividends, or that the stock price will go up. Unfortunately, the current stock market does not promise any of them. Red Hat directorate can decide to give you dividends, but you are not promised, and if you are living in California or Paris, I am not sure it's worth traveling to Virginia to stock holders public meeting and vote on giving dividends to yourself and other share holders.
Now, I am asking myself, what is the interest of all these technology writers promoting Red Had by yelling "Look, Red Hat is worth a billion dollar" besides making other people buy a Red Had stock, and making sure the price goes up. They, Technology writers, just promote what I call the Red Hat Bubble.

Tuesday, May 08, 2012

Ubuntu 12.04 Intrusive OS

I installed Ubuntu 12.04 on two laptops by now. and I must rant. Ubuntu developers are assuming two many things about me. First, there is this bug, which the 'migration-assitant' mounts existing partitions in READ-WRITE mode. I find it dangerous and not necessary for migration.
Then, today I installed Ubuntu 12.04 on IBM x121e and found out that my Bluetooth chip is disabled. After about 20 min of looking I discovered, it is because of a bug in the installer which messes around with the BIOS. So if you have IBM x120e with Intel Chipset, you need to reboot, restore the BIOS defaults and then Bluetooth works. 
That's all the ranting for now ...

Monday, May 07, 2012

GCC 4.7 Breaks 169 Packages in Debian ... my weired hobby ...

I have a weired hobby, checking very frequently the Release-Critical Bugs in Debian.
It's kind of a magic window to all this wonderful packages found in Debian. Sometimes I'm horrified to see so many bugs opened at once. Like now ... 169 FTBS introduced by GCC-4.7...



It's no reason to panic, but it's been a while since I've seen such a huge bump up...


Thursday, May 03, 2012

Ubuntu Rant! You need Ubuntu to install Ubuntu

Ubuntu "engineers" are probably dumber than that Enterprise Linux OS. I got a laptop from a friend who asked me to install the latest Ubuntu on it. My usual technique of make a live bootable usb faild.
So, I googled and found this evidence that Ubuntu engineers are retarded.
You need Ubuntu to install Ubuntu.
This reminds me a bit that Redmond company. What if I have another OS ? NOT Mac or Windows ? For example, Debian? can't you just write how to obtain that package ???

Wednesday, May 02, 2012

New Entry in the Linux laptop list !

I am looking for a new laptop. 14" is a bit hard to fit in the bag sometimes.
While search for a new 12" laptop, I found garlac.eu. Their 14" laptop is exactly the Clevo I have, the 13.3" version I bought to my girlfriend under the brand name Belina in Germany. It's a good laptop. But the one in Garlac comes either with equiped with old AMD version or newer with Intel but equipped with NVIDIA.

Sorry, I DON'T buy AMD. Until someone here or in AMD convinces me that they do a better job with Linux. The second option, NVIDIA is an  utter crap. NVIDIA drivers is the biggest piece of s$#% I ever saw, and in my work place, I curse a lot when I need to mess with NVIDIA card on a CAE workstation or some cluster.

But... if you are looking for a good 14.1" laptop and you are in Europe... The Rush 14.1 seems like a good choice.

Monday, April 02, 2012

Command Line Posting to Blogger

Oh man, I'm really becoming a geek. I spend so much time staring at VIM that writing a Blog post using the Web interface seems cumbersome to me. I know about Google command line interface and I even wrote my own little script to upload images to Picasa directly from Nautilus (good times are gone, I don't use GNOME anymore).

 

Basic setup

So, in this post I will explore how post to Blogspot from the command line in an elegant way. First we need to install Google's CLI tool, let's grab it:
wget http://code.google.com/p/googlecl/downloads/detail?name=googlecl_0.9.13-1_all.deb
Now, let's install it:
dpkg -i googlecl_0.9.13-1_all.deb
OK, basically, now you are good to go. The documentation is fairly easy to understand. Except maybe one note. The first time you will run the command you will need to configure your client. The config files are found in:
~/.config/googlecl/config
Well done by googleres who put the stuff where I expected it. Do note, when you run the config you will be asked for the name of your Blog. This is NOT the subdomain, e.g. in my case:
linuxpixies.blogspot.com
Rather to correct answer is the title of the Blog:
Linux Pixies and Stuff
Spaces are digested very well.

 

Making things Fancy

Until now you can post simple text files, or manually edit HTML (YUCK!). Here comes the fun part. Editing simple text files and automagically converting them to HTML. Enter markdown.

 

Markdown

Markdown is a sweet little thing I discovered using stackexchange.com. The more I use it I want more. This thing is addicting, and even worse, it makes me hate all other Wiki syntax! Especially TkWiki, which we use in my workplace. Markdown has many many converters. I use python-markdown2, so let's install it:
pip install markdown2
Now, if you are a pedant, you could make a Debian package, which is actually better than just dumping Python packages. But pip can also remove Python packages, so it's now that bad, after all.
Anyway, at this point, you have python-markdown2 installed, and the command markdown is at your finger tips. You can start writing your post with your favorite editor, be it Nano, EMACS, Ed or VIM, when your done, save it with an appropriate title and md suffix so you know later it's Markdown. Now comes the fun part.

 

Converting to HTML

/usr/local/bin/markdown2  YourCoolPost.md > Title\ of\ Your\ Cool\ Post.html
Now, you can view it with:
firefox Title\ of\ Your\ Cool\ Post.html
It will be bare naked HTML, without any styling, but you will get a good feeling how your post will look like. When your satisfied, go the next step, publishing.

 

 Publishing your Post

Easy as:
google blogger post Title\ of\ Your\ Cool\ Post.html
Done.

 

Final Remarks

I am writing these final remarks from Google's own web interface to Blogger. I wanted to see how my post looks like in real life. I was amazed to find a plague of break elements. elements in my post. Apparently, Blogger's engine parses the HTML once again when it's submitted. Everywhere I had a line break in VIM using enter, I had inside Blogger a break element. Quite upsetting, but just remember, don't use to many of them inside VIM, and your post should look good.

Tuesday, March 20, 2012

Good Bye Latex ? Hello WeasyPrint ...

Latex, is my main way of producing reports and scientific works. Usually these are formed as PDF before being actually printed. Latex is AWESOME. I love writing documents with latex. That said, although I am not a beginner with latex, when I want to deviate from normal good old latex patterns things become a bit rough.
Despite using the Latex language for almost 5 years, I still don't fully understand the syntax of writing packages, although mostly a long enough search will yield some solution which does not require me to hack on my own. Never the less this is a bit tiresome sometimes.
Enter WeasyPrint. This project seems really cool because it allows anyone with basic knowledge of HTML and CSS to produce good looking PDFs. Further more, I can really think of a simple work flow once a template is made:
Write your documents  with Markdown, use something like Jekyll to convert your easy to understand Markdown to HTML with some Jinja or CSS and finally convert your pages to good looking PDF's.
I think this is more or less what Sphinx does (except that Sphinx uses RST instead of Markdown). I never really mastered CSS or HTML, but this seems like a good opportunity to start mastering both

Besides, consider this:

MarkDown + Convert to HTML +  WeasyPrint  = Sphinx from Scratch.

Besides being a very cool educational project, a project like this can allow people with CSS + HTML knowledge to produce some great looking PDF. It also allowed a lot of flexibility if you are good at both. 

Never the less, Latex has still one big advantage: Latex is well designed to produce good looking documents even though you are not an expert on typography and page layout. Additionally it is thousands of ready made packages and kind community that can help solving many existing problems. So maybe after all, Latex is not going away so fast!

Friday, March 16, 2012

The weired Indexing in Perl

I am learning Perl. I am doing it with a lot of a resentment, but I am slowly learning it.
Normal people count from 1. Computer Scientist count from 0. Perl developers count from -1?

WTF?

oz@server ~ $ test.pl test
num of args 0 
oz@server ~ $ test.pl test test
num of args 1 
0
test
1
test
oz@server ~ $ test.pl          
num of args -1 
No arguments!
oz@server ~ $ 
My Code, just in case I am totally wrong about this here, :
$ cat test.pl 
#!/usr/local/bin/perl -w


print "num of args $#ARGV \n";
if ( $#ARGV > 0   ){

   for ( my $i = 0 ; $i <= $#ARGV  ; ++$i  ) {

   print "$i\n";
   print "$ARGV[$i]\n";
   }
}
if ( @ARGV > 0 )
{
  print "Number of arguments: " . scalar @ARGV . "\n";
}
else
{
print "No arguments!\n";
}

Friday, February 24, 2012

VIM Quicky: set tabs and spaces behaviour for different files

Never really bothered me before, because I only used Python and C, so I always replaces tabs with spaces.
However, with more C programming lately, I needed to start working with Makefiles. These require tabs instead of spaces.
So here is how to. In the end of my .vimrc file I put:

" python python pyhton
" convert tabs to spaces before writing python files or C files
autocmd! bufwritepre *.py,*.c,*.h set expandtab | retab! 4

" convert spaces to tabs when reading python file or C files
autocmd! bufreadpost *.py,*.c,*.h set noexpandtab | retab! 4


Et viola, not so complicated!

Wednesday, February 22, 2012

Open Hardware - a short list of alternatives

I have been waiting quite a while to write this post. I think it's about time that people who want to write FOSS and support FOSS will also buy hardware from manufacturers that support it. One good way is to buy directly hardware which is designed like that.

So here is a list of stuff I can really recommend or I'd like to buy:

1. Portable Music Player with rockbox:

Sansa Clip+, by itself this little player is not open source or open hardware. However, it is cheap and reliable and runs rockbox. And that is really the best thing about this player. The original firmware comes with pretty limited and dumb interface, it does not support playing OGG or FLAC files, for example. Installing rockbox on this player enables that, further more, rockbox has many cool plugins. A favorite of mine is the simple Stopwatch which allows me to measure times when I jog.
I wish someone in Sandisk would realize how redundant it is to make their own firmware, and they would just adopt rockbox officially. After all, another cool thing about this player is its expansion slot for reading Mini-SD cards.
Rockbox has made me more satisfied with this player, and left me astonished when I saw the user manual, it is maybe the user manual I've seen for an open source project (except maybe the FreeBSD handbook).

2. Router+File Server

I think I am not very wrong, if I say that most people I know has a home wireless network. Good chances that this W-LAN router is running some kind of Linux based OS with a web interface. The advanced users can try and replace this OS with a user friendlier and more capable OS like OpenWRT or DD-WRT.
But what is better than buying a device which is already pre-installed with one? Here is a Linux Friendly router, the Buffalo WZR-HP-G300NH, this is the Wiki page dedicated to this little router, and there is a very good blog documenting that router what you can do with it.
Right now, my Buffalo is running a File server, and of course the W-Lan and I am very happy with this  40 USD embedded computer. I'm so happy with it, that I might get another one, and install full blown Debian on it.

3. Tablets

It's been a while that I am thinking of buying my own tablet or an e-book reader. However, I'm late to join the crowds and I don't want to pay money for computer that I need to break into to get a root password. There for this rules out 99% of the Android tablets and others.
I just ordered 2 spark devices. These little machines are pure Linux (not Linux with Handcuffs.)
But there are other devices which have Linux on them, such the Smartbook or WeTab.

4. Laptops

Well, there are  many by now. And it's good, I've compiled a small list of laptops sold with Linux.

If you have suggestions to this list please let me know!


Wednesday, January 18, 2012

UEFI Secure booting is good for Linux

Microsoft will block non Windows on the ARM platform. Big deal. It is if installing Linux on any other Laptop is easy. Sure you can install Linux on most Laptops today. But does it really work? Do you get the same battery time with Linux as with Windows? Nope. Do your multimedia Keys work? In 90% of the cases only partially. Does your computer suspend or hibernates as in Windows? in about 50% of the cases the answer is no. Does your Graphics Card works the same as under Windows ? NOPE.

So, the situation is like this: OEM A makes a deal with M$ and writes proper drivers to the hardware and SomeUser Joe gets a hardware which works perfect with Windows 7. Later, SomeUser Joe, installs SomeCrack for SomeCoolSoftware which contains a Trojan which he can't get rid of. After some frustration, he decides to quit with this M$ thingi and give Ubuntu a try, because he heard it's cool. He than tries Ubuntu and discovers some things don't work. Here our little story splits.

First possibility, the Linux Sucks possibility. SomeUser Joe, is frustrated, his computer will freeze every time he resumes it from suspend. Or the graphics card is slow, or the Fan always works loudly. Linux Sucks. Period. SomeUser Joe, bites it, and installs Windows 7. His next computer will be Apple.

Second possibility, the Linux has a cool community, SomeUser Joe, heard about it and wants to join. So, he files another bug, which might be taken seriously, or not, in Ubuntu's bugzilla. This bug might find it's way upstream to the Kernel developers and they might solve it, but the patch will only be in the next release of Ubuntu maybe in 6 months from now. Damn speculations. But Linux works at most. So, in 3 years from now SomeUser Joe, might look for a new Laptop, without the Windows Tax, and will save a scrap of 50 bucks, which he will spend 100 times more money in working hours value digging through forums and IRC channels trying to get he's M$ free Laptop to work.

Third Possibility, SomeUser Joe buy his next Laptop with Linux pre-installed. Hell yes! UEFI is a great thing. I wish all M$ devices would never run Linux. It will force Linux fan boys to see that by saving $50 to $100 dollars buying a Laptop from OEM's which sell Windows, they sleep with the Devil. UEFI is a great opportunity to Linux and FOSS, because we have a great OS in our hands and now we have also Free Hardware like the BeagleBoard, PandaBoard, RaspberryPi and even the GTA04.

There are some small companies the sell Linux laptops which have the latest trends in hardware. If there are just 1 Million Linux users and just one third of them will buy a new device this year, that is about 300,000 laptops sold with Linux. I think this is a huge jump in sales for a small company like ZaReason or System76. They would be then more then able to go out on a broad campaign putting Linux on the main stream student Laptop.

So, please, stop whining about UEFI. Just don't buy laptop from OEM like Dell or Lenovo or Acer or Asus. There are ENOUGH alternatives for Preinstalled Linux Laptops. Here is a short list:

If you happen to know of others, please let me know through a comment!

(P.S. Dell don't count! Dell's Ubuntu offering mock Linux users, offering a free OS with lousy hardware which costs more than the Windows installed laptops with cost cheaper for better hardware. Just because of this mockery, I will never recommend any customer of mine or buy myself any product of Dell).

Sunday, January 08, 2012

Saving Karo: making a 6 years old laptop alive again...

Karo is the second laptop I got, I bought in my second year of Uni, in 2005. Karo, diamond in Turkish, is an HP Compaq nx6110 business Laptop. I have used it through my Bachelor and my Master studies. During these 5 years, I upgraded its memory from 512MB to 2GB, and replaced the Harddrive a few times from 40GB to 80GB and then to 120GB and finally to 160GB.
On the last year of its business warranty the laptop had problems with the CD-ROM and one of the USB ports died as a result of bad wiring. So, HP took the laptop and installed a whole new motherboard on their expense.
About a year later, when I was between my Master and Bachelor, I was on a very shaky bus ride and Karo fell off the luggage compartment 2m down. Although it was in a special case, the screen splintered and was not readable anymore.
Just going out of school, I was not able to replace the laptop  so quickly, so for about 130 Euro, I bought a compatible LCD screen and replaced it myself. To my surprise it worked very nicely. HP have a very nice service manual which accompanied me since then.
So now Karo, had many new parts, and it was not worth buying a new laptop. I started studying a Master, and karo served me well. Until 4 months before I graduated, while I was writing my thesis, karo became extremely noisy.
It's fan was working non stop, and it was never able to cool itself down once it went over 65C degrees. I didn't feel like experimenting so much, and the only thing that bother me about Karo besides the noise was it's damn heavy weight. So I bought yenikaro, a new light weight 14" laptop which was nice and quiet with a weigh of 1.4 Kg.
Karo, moved away from the table, and was seldom turned on. However,  this weekend, I decided to revive karo, and see if I can fix the noise problem. I followed HP excellent guide on how to access the fan. Once I open the laptop, lo and behold, karo had between it's fan and the vent I found a huge bulk of fibers and dust, it was so big, I just had to take a photo of it:


I removed the fan, and than carefully cleaned all the insides of the laptop from dust and fibers and other fine particles. Then, I closed it, and rebooted into my Debian again. Karo, is silent again. Now it just needs a new Harddrive replacement for the 3 years old hard drive and it can be used again ...