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.
Wednesday, March 19, 2008
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.
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.
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!
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.
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.
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.
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.
Subscribe to:
Posts (Atom)
