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.
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 :)
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.
#!/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.
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!
Subscribe to:
Posts (Atom)
