Wednesday, December 24, 2008

Xterm with Truetype font?

I am not kidding. It has been a while, too. Just I knew that now. I simply googled and found this link.
This assumes xterm is compiled with xft library, which will be true for most of decent Linux distro like Fedora Core or Ubuntu. Especially, I am a fan of 'screen' utility, I don't need top menu, icons, tab names, etc. So!!! Try this:

$ xterm -fa 'Monospace-9'

Amazing.
Now, temptation for Enlightenment instead of KDE?

Thursday, December 18, 2008

new process state in linux kernel 2.6.25

I am obviously losing kernel tracking. I can't keep up linux kernel any more due to busy life. Today, while researching on my regular works, I ran into this article.

http://www.ibm.com/developerworks/linux/library/l-task-killable/index.html

In short, linux innovated new process state, called TASK_KILLABLE. Operating system is still evolving. Almost 50 years after its first version of Unix, still finding a way for innovation.

Wednesday, December 17, 2008

Adding unittest in python with TestSuite

Unittest is an important fundamental for solid software development. At the same time, maintaining proper unittests is also a burden. Managing good unittest is always a challenge.

One of the challenge in python comes when unittest.TestSuite is needed. Generally, each class will split out to each of unittest.TestCase class. But, to teach TestSuite what TestCase to load, we have to pass a list of TestCases, and writing a list manually like this isn't fun.

suite = unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(FirstTest),
unittest.TestLoader().loadTestsFromTestCase(SecondTest),
unittest.TestLoader().loadTestsFromTestCase(ThirdTest),
.....
])

It is error prone. More annoyingly, if I add a new test case, I have to modify suite, also. Using this driver will auto discover test classes in the current module.


moduleList = [ globals()[mod] for mod in globals().keys() if mod.endswith('Test') ]
suite = unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(i) for i in moduleList
])
unittest.TextTestRunner(verbosity=1).run(suite)


This uses naming convention of "SomethingTest" as a test case for class "Something".
Keeping this convention will be a keystroke save.

Friday, December 5, 2008

Tools for these days

I adapted two major changes in my tool set.

1. fish instead of zsh/bash
Most linux ships bash. I have used bash mostly. zsh was okay. But after I found fish, settled in fish. It is different but not difficult to migrate from bash. Nice color coding with good completion like zsh. Its script syntax resembles to tcl. I don't like tcl, but I could handle fish okay. Another unusual, but eventually more useful thing is the lack of history expansion. !! or !$ in bash does not exist in fish. Instead of them, fish simplifies all history recall with Up/Down and Alt-Up/Alt-Down. Action oriented :)
fish is very useful in many aspects. One useful thing is its history keeps not only history of the commands, but also keeps the timestamp when it ran.

2. screen instead of multiple xterm
Spreading xterms all around desktop looked sloppy. So, I tried to pack them into one screen session. At first, the environment was not familiar, but later I got used to it and navigated fine. So, mostly my dual screen is one emacs session plus one konsole with screen. These look more elegant than patching desktop with many xterms.

Tuesday, November 18, 2008

Best Python debugger

I don't use pdb often, but today, I needed one. I suspected that there should be a pdb module for emacs. Although GUD requires separate wrapper to PUD, there is a built-in module in Emacs. I just realized that GUD is a wrapper for another process instance. Not a big deal.
Create this file in somewhere PATHable and name it pdb.

#!/bin/sh
exec python2.6 /usr/lib/python2.6/pdb.py $1 $2 $3 $4 $5 $6 $7 $8 $9

And then, you are good to go. Someone mentioned that backtracing does not work across modules. I didn't test that because his/her post was dated long time ago with emacs 21.
With pdb, 'C-x +' (balance-windows) will be very useful.

Friday, November 14, 2008

Emacs pinky problem

I am not talking about L-CTRL sitting on a lower left corner. I already switched CAPS and L-CTRL. However, as Emacs still requires so many CTRL key strokes, my left pinky is getting tired. Now I am using R-CTRL and R-ALT. This works in my work desktop, but several problems await me.

1. Some machines don't understand R-ALT and R-CTRL.
2. Laptop and Desktop keyboard layout make me confused for these keys.

Intentionally, xmodmaps are turned off these days to remind myself to use Right side.

Friday, November 7, 2008

Nehalem architecture

Intel took a new approach to resolve the bandwidth problem, traditionally Intel suffered. If Intel Core 2 duo was focused on more efficient computation, this is major replacement of architecture design. As a programmer, we can just enjoy more clock cycles on less power consumption :)

Here is an article about a very nice overview.

Friday, October 3, 2008

Like a stone, Audioslave

This morning, I ran a random list in amarok, and this song was played. I purchased this song from Rhapsody several years ago. Once again, I felt touched when listening to this. Another song that I like is Cochise.
Not his song, but he is very special to my life. I loved rock music when I was young. I loved to play guitar. When I was early 20's, Korea was not ready for Rock. There were people who love rock music, but popularity came from dance music mostly. Also, the media didn't carry much of rocks. So, I was thirsty about rock culture. Only way to access was spending money on CD.
The fall of 1994, I came to US. Luckily, I happened to have a chance to watch M-TV. And I enjoyed ROCK music all night long. For the first time in my life in the first night in the US. I remember there were "interstate lovesong" from 'Stone Temple Pilots', something from 'REM', "When I come around" from 'Green day'. But most amazing songs were from Sound Garden. "Spoon man", "Fell on black days", and "Black hole Sun". I think I watched "Fell on black days" on that night and amazed. The vocalist of Sound Garden is the one in Audioslave...

Just a memory, 14 years ago...

Thursday, October 2, 2008

KDE4.1 on Fedora Core 9

It is pretty busy days. I can't find time for a technical post. But, I want to mention that I am happy with new KDE 4.1 update with FC9.
I generally don't follow updating my work desktop. Recently, I did it and required rebooting for kernel 2.6.23 update. After logging in, I found KDE is updated to 4.1. It had enhanced look, and I updated my nvidia card from livna, and OpenGL based theme worked. It looks much cooler.

Thursday, September 25, 2008

Good excuses NOT to use version control

Recent post from stackoverflow.com made me laugh. 'No version control' execuse. I have to reveal my stupid experience for this. It was my first year in career. I developed a replacement of production data feeder. It had a significant improvement, and I was sure it will make other people's life easier. But, suddenly, an accident happened. At that time, neither did I version control, nor backed up a source. The fact that first year professional doesn't know version control system should not be a good execuse, but I didn't know that.

My intention was to clean up test data like this:

$ rm -fr $PRJ_HOME/data

But, actual command was issued like this:

$ rm -fr $PRJ_HOME/ data

With just an extra space, I screw up the $PRJ_HOME. Fortunately, I had spare partition with enough disk space. I dumped /dev/sdaN to a single file. It was too big to open in vim, so chopped in pieces, and went through ugly binary format searching for my piece of code. After recovering all of my sources, I learned CVS and spent a week to learn to setup and manage CVS. Now it became Subversion.

There is no execuse, no good reason not to use VCS(Version Control System).
I can think of one. Temporary project only, which will create noisy commits on main VCS. However, even though the project is temporary, building on my own subversion tree locally and stuff into it before going to main VCS is not a bad idea.

Tuesday, September 23, 2008

Emacs, company-mode

I ran into a company-mode. This is a new completion style, and I like it. I recommend to watch its demo screencast.

company-expand-common function will take your TAB key away. I rebound it to [C-tab].
Very useful and good looking.

Monday, September 22, 2008

Chaining condition

I was reading a python code and discovered this useful feature.

if LOWER < x < UPPER

do_something


I have expressed this "if LOWER < x and x < UPPER" until I discovered chaining expression like this.
Perl and Ruby didn't accept chaining expression. C and C++ will not work because, (let's see the parsing)

1. C replaces expression with result of evaluation. Therefore, '1 < x < 10' expression will be '( (1 < x) < 10 )' and it will be evaluated to non-zero for any x.

2. C++ also replaces expression, but it knows boolean (true/false). Therefore, '1 < x < 10' expression will be either 'true < 10' or 'false < 10'. Since C++ is strong-typed language, this expression requires support of additional function like "boolean operator<(bool&, int&)". If it is supported, it should also support "boolean operator<(int&, bool&)". Now, int is not the only comparable. Beginning with float and double, signed/unsigned char, etc. It gets ugly very easily. Another approach will be replace true to (int)1 and false to (int)0 so that it can leverage existing framework. Anyway, end result is not related to the result of '1 < x < 10'

3. Due to this nature, supporting this expression in dynamic language isn't simple problem. For example of '( (1 < x) < 10)' case, inner expr can be any type based on 'what x is', the interpreter should be able to handle this fine.

Anyway, "1 < x < 10" is more elegant than " (1 < x) and (x < 10)".

Sunday, August 10, 2008

Howto install Emacs snapshot (v23.x)

It's another 3:00am.
I am an emacs advocate. I used vim enough, and still use vim for certain circumstances. However, I use emacs mainly for development.
Stable version of Emacs is v22. v23 is development tree. There is one big advantage compiling emacs v23. "xft" support. So, if you want to use 'Consolas' font in emacs, using v23 will simplify a lot. Configure switch is:

# ./configure --with-x-toolkit=gtk --enable-font-backend --with-xft \
--prefix=/usr/local/emacs-snapshot --with-tiff=no

It requires gtk.h. So, you need gtk2-devel package for Fedora Core. (Other distro like Ubuntu should not be a problem to find equivalent package. ) Then,

# make bootstrap
# make install

Then, add following line to use Consolas font.
(set-default-font "Consolas-11")

Simple enough. :)

Now, for people who didn't read README, like me, here is some quarks.
If you happened to execute 'make' before 'make bootstrap', you may run into a problem. (might be different problems, depending on revision). In my case, I cvs up and just issued "make" assuming that previous config information would be transparent. Not really. The top most error was:

"faces.el:29:13:Error: Symbol's function definition is void: cl-compile-time-init"

That line is (require 'cl). If you open Makefile, you will see that "make" and "make bootstrap" targets are different. In this case, somehow cl(common lisp) package was not ready when faces.el was compiling. According to Makefile, make bootstrap will 'force clean and bootstrap from a clean state' My assumption was partially right, but Makefile case did not cover my case, yet. Went through several seg-fault and compiled on my own and made it to work.

I believe that the easiest way was to "make clean" and start from scratch :)

Thursday, July 31, 2008

Shell, recall last argument

This is also very good shell feature, but many times I failed to use. I will encourage myself by posting this. Here we go.

Suppose I created a temp dir, and move to it.

$ pushd .
$ mkdir /tmp/lalala
$ cd /tmp/lalala

The last command can be easily made by, recall by arrow-up, ctrl-A, remove 'mkdir', and type cd. Not bad, but bash has better option.

$ pushd .
$ mkdir /tmp/lalala
$ cd !$

Confused or frowned for another cryptic symbol memorization? That was my first impression. But, actually not. It is very elegant usage.

! is history recall. As we usually do "$ !510" - recall command number 510 in history.
$ is regex. End of line. Then, we can think usage of '!^'.

$ cat a b c d e
$ cat !^
cat a

So, each run will remember previous argv vector, and we can call by placer(^,$).
Another nice feature. I am interested in middle one, like c in previous example.

$ cat a b c d e
$ cat !:3
cat c

Not bad. Here is another interesting one.

$ cat a b c d e
$ cat !:1-
cat a b c d
$ cat !:1-
cat a b c

Popping every argument..
In my opinion, this is a gift from bash for who think before hand. Someone who lavishes meaningless 'ls', like me, wouldn't get benefit. :)

Tuesday, July 15, 2008

Transaction in MySQL

Personally, I use PostgreSQL. PostgreSQL is the most advanced open-source database. I am bravely saying that it is more advanced than MySQL is at the time of this writing. However, my department is running MySQL 5.0. I feel lucky that it is not MySQL 4.1. I have to migrate my current works stored in my desktop in postgresql to mysql. It is anticipated from the beginning, but I just didn't prepare.
The migration will not be hard, though. It is easy to convert postgres dump to mysql dump for import. I searched my favorite function, Transaction. To make transaction work, InnoDB must be used, which implies mysql should be compiled with support of InnoDB. Mostly it is true.
Here is one additional change to apply for postgres dump. Any create table statement should have something like this.

create table table_name ( ...description... ) TYPE=InnoDB;

Simple, but just wonder why InnoDB is not a default type, and who wants some table type without transaction support. Transaction on mysql is relatively new feature, on the other hand, PostgreSQL already supported long time ago. Oh well.. It is what it is. We use mysql, so be it.

Tuesday, June 24, 2008

Going back to Fedora Core

My recent Fedora Core 9 can be said successful. I still like Gentoo so much. But, in the work place, running gentoo may risk me to stay longer in the office. My choice of alternative is "Fedora Core 9".
I began this with Ubuntu 7.04 which was the left over from the previous. And switched to Kubuntu 8.04 with KDE4 three or four months later. Disappointed so much and tried Fedora Core 9. Thought about Open Suse, but FC was the next.

I tried Fedora Core just once about two years ago for a couple months. I guess it was FC6 or FC7. I switched to Gentoo when RedHat 9 became Fedora Core. So basically, I left RedHat world long time. I don't even remember how it was.

In short, Fedora Core changed a lot from where I stopped using. The biggest advantage of FC9 is very considerate default. Different from Ubuntu policy (literally enabling everything regardless of system resource for ease of use), FC focused more on lower level stability such as kernel API compatibility across the versions. Hibernate works very nice. Good for laptop. So, in kernel level, Fedora Core opens flexibility more, and it is stable more.
But don't get wrong with X11 crashes. That's not due to unstable kernel. That's because the gap between distro's open end and user failure to provide suitable driver. I believe this has been and will be the endless fight for Linux kernel and X11 driver.

Friday, June 13, 2008

KDE4: Gentoo, Kubuntu, and Fedora Core 9

I am okay with KDE4. There are still some quarks in KDE4, but generally I like how it is now. I can't explain detail of KDE4 in each distribution. In short, I dropped Kubuntu for KDE4. I agree that Ubuntu linux is doing a great work, but with KDE4, they need to catch up.

With Gentoo, things are smooth. Sure!! I pay huge compile time for this. In my work place, things are moving in fast phase. So, having gentoo isn't quite suitable. I chose Kubuntu when I had a chance to refresh my work desktop. Kubuntu KDE4 was pretty disappointing. One of most annoying example is that I couldn't move widgets in panel. Right click did not even offer "Move" option which I remembered it was there on Gentoo. So, I had to find another time to refresh my desktop. My desktop didn't find time to kick out Kubuntu, yet. I could flush and rebuild my laptop during the last weekend with Fedora Core 9. Still some issues, but much better than Kubuntu.

When I get a chance, I will compare rpm vs. deb. In short, deb is more convinent, but rpm is more flexible. dpkg(deb package) mainly uses package based dependancy and extends out to file based integrity check if it needs to. RPM, on the other hand, takes file based, but yum wraps these into package level and group level ( collection of packages ).

Thursday, May 29, 2008

to filter .svn view

find is a great tool. But, find treats all files and all directories equally including .svn dirs. Suppose we need to see the directory structure of a certain directory and issue this command:

$ find . -type d

If the current directory is under svn version control, find will show many .svn directories, too. Well, since find is a great tool, it will have some filtering functions, too. 'man find' and we can come up with this to filter out .svn.

$ find . -name .svn -prune -o -print

Hmmm.. We select non-.svn by inverting the result. But, we don't know it is a file or directory. Unix has another great tool called egrep.

$ find . -type d | egrep -iv ".svn"

We used invert matching not in find, but in egrep. Inspecting a directory will be much easier with these two tools. For svn specific, we can use 'ls' command on svn.

$ svn ls -R

But, ls isn't good for distinguish file or diectory.

Thursday, May 8, 2008

Python and DB2

We have a DB2 backend and I started to test it with PyDB2. Here is a tutorial link. In short, nothing is surprising. It uses standard python DBAPI interface with some good utility in DB2.db2util package.
Initially, I thought this client package would give different usage because DB2 client is different than postgres, mysql, or Oracle. However, PyDB2 is written well by supporting standard API.

Monday, May 5, 2008

Shell, Brace expansion

I found that I research this whenever I think of this function.
If I have to select file a,b,c only in /tmp, brace expansion is the answer. /tmp may have bunch of other files. Also repeating /tmp/a, /tmp/b, /tmp/c is annoying.

$ ls /tmp/{a,b,c}

Brace expansion is not used often, but when it is needed, it is super useful. I have to leave this note hoping that I have a place to lookup at least.

Sunday, April 27, 2008

KDE 4

I am a little late to install KDE 4 since it was out in the last year. One of my biggest woe was 'what if it is not fully compatible to KDE 3?' It didn't happen, yet. I enabled OpenGL. After I lost interests about compiz-fusion, it's been a long time to work with visual effects.
KDE4 looked nice. At first, I was confused from reorganized menu. But once used to it, it was useful. I liked tab with recent items. KDE4 has zoom feature. I am not sure if it is from OpenGL because it responds pretty fast.
Migration is generally successful. Now, I have to find a time for my work desktop.

Wednesday, April 16, 2008

Another 2:00am wakeup

This happens quite often, these days. I used to sleep through the night. Usually I enjoy doing things in early morning, like 5:00am. 2 isn't good time to wake up. This happens especially I get to sleep with some thoughts. Last night, I was thinking about 'How to generalize test directories'. I collected good number of test cases. My solution is providing default callback handlers, and specific handlers will override if specified. Loading/Unloading/Reloading modules at runtime isn't fun, but better than introspect.
If someone asks 'why is introspect bad?', I don't want to say it is bad. It isn't suitable for callback handler. The code is half open, and the rest half will be provided at runtime. Thanks to duck typing, traceback will byte me way later. With introspect, class name doesn't need to be fixed. I need to grab class name on the fly. But, other than this benefit, whole chain of responsibility comes after that. It is very difficult problem to figure out "Is this the callback handler for event A or B, or is it really a call back handler??" C++ compiler will be useful in this case ;)
If constraining class name by fixing it, I know what I am binding. Much simpler and yeah.. I am lazy.

Tuesday, April 15, 2008

Drawing Chart options.

Pretty chart drawing is a very attractive feature in any software. Why chart is nice? Human perceives 3D space, but human communication is 1D space (Linear!) We speak in just one direction. We read in one direction. But, mixing one segment of information with another is not natural communication method. Remember your history class. For comparative topics between other nations along side with time line, it requires some table. Primitive 2D communication. And if table can be quantified, Chart can come into play for visualizing the quantity. Enhanced 2D communication.

Okay, my tool of choice is python.
First option. Raw rendering using Xlib or GTK or Qt4. Unless they support widgets to play with, rendering with fundamental components (Point, Line, Rectangle, Circle) is painful. It is not an option but making life painful.
Next option. PyChart. Free library to generate image of a chart. Eh~~ okay to use, but not pretty. If I am drawing something, the fancier the better!
Then, Chart Director from advsofteng.com. Prettier, and free if their credit lable can be bearable. To remove this label, I need to purchase the license. Fortunately, their pricing makes very sense. However, not free.
ReportLab can be another option. ReportLab is a perfect tool for PDF generation, but not very good for rendering sophisticated graphs. And its output format is only PDF.
Gnuplot is another good one. Especially, for time series, gnuplot is one of the best. But, it is a mathematical graph. If I am drawing certain shape, and it does not meet mathematical property, it is not good. And gnuplot speaks its own language. Need to learn it from the documentation.

Google Chart API is my choice. And they begin to support geographical map chart. How nice is it. Limitation of map chart is the size. I can not create bigger map than size of 440x220. Other than that, Google Chart API wins all other options. Wait... Other libraries don't even mention map support. Google API already won on it.

But~~ it is web-request. No problem. Python has great urllib2 library.
Here is my sample code.

#!/usr/bin/python
import urllib2

# If you are behind proxy to go through,
my_proxy = urllib2.ProxyHandler( {"http" : "http://proxy_host:proxy_port"} )
opener = urllib2.build_opener(my_proxy)

api_url = 'http://chart.apis.google.com/chart'
chart_property = dict(cht='p3', chd='t:30,20,50', chs='250x100', chl='Hello|World|Raymond')

def make_request( api_url, chart_property ):
  return api_url + "?" + '&'.join( [ "%s=%s" % (k,v) for k,v in chart_property.items() ] )

png = urllib2.urlopen(make_request(api_url, chart_property)).read()
fh = open('test.png','w')
print >> fh, png
fh.close()

Monday, April 14, 2008

Nice python interactive: ipython

ipython can be replaced with default command line python interpreter. One obvious add on from default python is readline capability. [TAB] will look up locals() and filenames at the same time. NICE! Noah Gift, the organizer of PyAtl introduced this in the presentation, and the very night, I tried and liked it.

Friday, April 11, 2008

PyAtl

Last month, I joined Python users group in Atlanta. Yesterday was my second attendance. Before the meet up, some members had dinner together in a restaurant. People are very nice, but more importantly, the presentations are great. Here is our group page

Thursday, April 10, 2008

Find glibc version.

This morning, one of my co-worker asked me how to find the version of glibc on the system. I never thought about this problem. Generally, if version number is not specified in the .so name, we just hope that it is defined in the program that can be accessed. Version number is totally man made, and nothing to do with the program by itself.
Eh~~ I will be short this time. gnu_get_libc_version() returns a char pointer. I guessed it from the symbol table of /usr/lib/libc.a. I actually began that this would be a variable (hoped not to be static variable.) It was a function.

Wednesday, April 9, 2008

ping

I am alive... Just too busy for blogging. No active project is going on. Well, it's been a long time I activated my own project. Recently, I draw some basic shapes for my son like triangles, squares, circles, and put them on OpenGL using python-opengl. Some pyramids, boxes, spheres, etc. Thanks to my son, I refreshed some opengl stuff that I haven't touched since undergrad.
Then, he wanted a car on screen. Okay, I thought it was easy. Just find a free 3D model and import in my python script. Wrong! It depends how the model is represented. If it is written in 3D-Max, it needs some other script to convert for opengl to understand. What if my son wants something like 'Mickey Mouse'? He will recognize fake Mickey. He will want REAL Mickey which is really expensive.
I better learn some drawing skill :)

Wednesday, March 19, 2008

collecting dmidecode information

dmidecode is very useful to look into system bios information. However, dmidecode -s requires long parameter. Since I prefer dump all information on one screen, I wrote this simple tool.

#!/usr/bin/python
import os, sys, commands, re
for p in commands.getoutput('dmidecode -s').split('\n'):
  if re.search('^ ',p):
    print '%-25s: %s' % (p.strip(), \
        commands.getoutput('dmidecode -s %s' % p) )


Use this with 'sudo'. Especially this is useful for 'DELL service TAG' information. Service tag text can be copy and pasted. :)

Anyone wants to challenge stuffing this into one line? One line bash with pipes are welcome, too.

Thursday, March 13, 2008

Calculating Weekdays in Python

Calculating weekdays is simple for human being. But, it isn't for a computer. The task requires that the logic understands calendar due to adding/subtracting dates. Doomsday algorithm is needed to get which weekday for a given day.
Python has two time packages. time and datetime. time package works like standard C library package except its basic representation is so called time-tuple rather than epoch. ( it knows how to convert to epoch ) datetime provides 1) higher level interface, 2) capability to manipulate dates, and 3) compatibility to time package. So, working with datetime is the most cases.
Hey, let's just see the code.

from datetime import timedelta, date
def weekdays(givenDate):
  start = givenDate if givenDate else date.today()
  start = start - timedelta(start.weekday())
  end = start + timedelta(days=5)
  return start, end

Pretty simple. Now, we can use some decorator to make it useful. For example, to provide postgresql where clause, we can write like this.

def pgsqlRangeWks(givenDate=None):
  fmt = '%Y-%m-%d %H:%M'
  start, end = weekdays(givenDate)
  return "ts > '%s' and ts < '%s'" % \
    ( start.strftime(fmt), end.strftime(fmt))

Again, python is well balanced language in performance and robustness.

Tuesday, March 11, 2008

eject command to close CD tray

I happen to find 'eject' command today, and I found that I can close CD tray without bending my back to reach to CD. :)

eject [device] will open,
eject -t [device] will close.

man eject. This is interesting.

Wednesday, March 5, 2008

FreeBSD 7.0

After one line qsort() craziness, I still didn't get back to sleep. I read about FreeBSD 7.0. FreeBSD has been proud of making better codes in the kernel than Linux evolves. They heavily used asynchronous IO before Linux introduced asynch layer. epoll() in Linux still needs more work. This time, FreeBSD proved their superiority once again. Linearly scalable SMP. According to their history, it took seven years to complete the solution. They staged into sub-solution for each releases (5.x, 6.x), and the war was over at 7.0. When I looked at the graph, it was definitely attractive.
They added more stable wireless support. But, my stupid BCM943xx card is not supported. Due to lack of my wireless support, I lost interest about FBSD 7. I am not good at BSD system, anyway. But, I swear that I wouldn't buy Dell laptop anymore. If I am buying a Dell once again ( I doubt this may happen ), the wireless should be Intel. PERIOD!

1 line qsort() in python

quick sort is very simple, but generally fast algorithm. If it is implemented in python, seeing the simplicity is obvious. Thanks to ease of boundary check, code will look like this:

def qsort(lst):
    if len(lst) <= 1: return lst
    left = [ e for e in lst[1:] if e <= lst[0] ]
    right = [ e for e in lst[1:] if e > lst[0] ]
    return qsort(left) + [lst[0]] + qsort(right)

Now, if evil lambda comes into play, we express this in one line.

qs = lambda lst: qs([ e for e in lst[1:] if e<=lst[0] ]) + \
    [lst[0]] + qs([ e for e in lst[1:] if e>lst[0]]) \
    if len(lst) > 1 else lst

hehe.. Okay, I admit that it is not simple one line. I am insisting this to be one line.
I appologize for trolling :) Maybe I am going wierd at 3:30 in the morning.

Thursday, February 28, 2008

OpenOffice compile on Gentoo

http://forums.gentoo.org/viewtopic-t-529291-postdays-0-postorder-asc-highlight-openoffice-start-75.html

44 minutes and 6 seconds! This is incredible. I remember when I compile it for the first time on mmy old P4 with 512 Mb. It didn't finish for long time, so I went to sleep to see it working the next day. 44 minutes is not a short time, but big improvement. New intel quad core with 4G ram must be cranking up.

Friday, February 22, 2008

b43-fwcutter-011

I should not be the only one thirsty for this package, and now it is available! Combined with the recent kernel (2.6.24-r2), now I am free from ndiswrapper for my wireless. Without Gentoo linux, this should be harder. Once again, I appreciate Gentoo linux. In short, I used this wiki. But I had to compile b43-fwcutter version 011 myself because it was not on portage, yet.

I have waited for this to happen for around two years. My previous Dell E1505 and current Dell 1521 had both Dell 1390 wireless, which has bcm43xx type chip. Older kernel called this bcm4311 or Dell 1390 in lspci, but from 2.6.20 (I guess...) it is called bcm94311. Whenever I had spare time, I tried different method but to fail.
bcm43xx series were broken to work with me always. And it is a black box system. I just cut out the firmware file from tarball without knowing who made how. I tried windows version, openwrt version, etc. Since I am not a hardware expert, I could only use things available by other people. Once it is installed on my /lib/firmware, I always hoped to 'Please work...' Interfacing this with Linux kernel was even more tricky. But no kernel module were co-operating on my side. I tried wireless debug on and tried to trace where things were broken. But, failed point I found was always beyond my capability :( And went back to ndiswrapper with rough riding on wireless.
I used to succeed by using Ubuntu. Their bcm43xx somehow knew what combination worked. I bear with this for a while but gave up Ubuntu for my laptop. First, hibernate was broken on me. So I had to wait 3 minutes after turn-on. My battery lost about 5% of its capacity just for booting. Second, their solution pulled out only 5.5 Mbps. No duplex communication. Third, LCD brightness control was broken with Ubuntu. When I was working in my dark room, this 100% bright LCD not only ruined my eyes, but also sucked up my battery.

From kernel 2.6.24, broadcom wireless chip is introduced under network device driver as CONFIG_B43. In hand in hand, b43-fwcutter released new version (011) in February this year. Kernel interfacing is officially resolved, and if new b43-fwcutter-011 knows about this, my long fight would be over.
I was right and now my 'dhcpcd wlan0' smoothly loaded my wireless. Full bandwidth of 11Mbps. I was so happy and tried from reboot. Still working :) Bye rough ndiswrapper.

Thursday, January 24, 2008

Easy solution on complex problem.

We call this "elegant solution". It is obviously very hard to achieve. One example of "Do things easy way" will be a book "The C programming Language by Ritchie and Kernighan." Reading this book several times is recommended. This thin book brought me new things each of three readings so far.
I admit that I used to be a spoiled programmer. "Jump on to the code without thorough thinking, busy in applying modern buzz worded technologies, proud of solving problems harder way than it supposed to be. Threaded, J2EE chasing, Fancy message passing methodology over MQ systems, Application Servers,.." Name it! I have tried many things on a lot of topics. Right, buzz words make my solution look fancier.
I remember a team when I was in AOL. It was my favorite team in my career so far. The team was handling 5000 servers directly, more than 15000 indirectly. To tell the truth, the best people that I remember are all them. Their solutions were very elegant. Berkeley DB was used for distributed storage. Socket was used, but home grown message router is involved in. No wonder that message router does not use any buzz word. Non-blocking IO is essential because of massive data size. But, most technical topics were pretty simple and basic. Only exception was Java WebStart. Grapher for analyzing data was written in Java Swing and it is distributed by webstart. That was convenient.

Elegant solution comes from thorough understanding of 1)nature of the problem, and 2)considering permutation of many possible subsolutions. Sloppy engineer doesn't have room to think alternatives. But, real guru can draw a complete solution in brain without touching a keyboard. And he enjoys several pictures of solutions and choose what will be the best. In this case, when he is using "global variable" (ah.. inevitable evil...), this really brings more convenience than complexity, with complete control. One example will be main() and PostmasterMain() of postgresql. It is beautiful piece of code.

Again, architecture is the key thing to make solution elegant. Do not just rush for a solution. Prepare a big chunk of brain for a complete solution. Key capability will be memory... Yeah. This is the train that I need to go for near future. Either I become a code monkey or I grow up as an architect. Things are not impossible. The best people that I remember are also 'human beings'.

Friday, January 4, 2008

simplest way for "ALT" key in xterm

After relocating to new place, Atlanta, with new work, my tasks are involved in many systems at the same time. In this case, using xterm is more useful than konsole. My konsole and emacs pair is generally one desktop, but multiple konsole or tabbed konsole for concurrent monitoring is annoying. So, working with many xterms on one desktop. xterm sucks when I need 'ALT' key. The easiest way is to replace xterm with rxvt. Here is my rxvt options:
rxvt -mod alt -bg black -fg white -vb +sb -fn 6x13

Bind this command with 'WIN'+x, then it is easy to bring up Xterm-like terminal emulator with 'ALT' enabled. If you are a fan of transparent background, Aterm is another good choice. I don't use aterm any more. First, transparency is obsolete since modern 3D based desktop manager(compiz-fusion/beryl) supports transparency for any type of win-frame. Second, more importantly, I am not a fan of transparency anymore.

One cool thing that I remember about transparent term is this. I made no-frame 100% transparent terminal with enough width. It is spawned with command "sudo tail -f /var/log/messages". It fakes like log messages flowing on Desktop directly.