Python, E51 and Sid
I installed python almost immediately after I picked my phone, about six months back. But I forgot all about it! Yesterday, I decided to fix it up for good and start getting my phone do some of my work?
As a first step, I’ve had tremendous success getting python over a bluetooth serial console to work. Of course, sincere thanks to google and other hackers who have tried and tested this method before me. First thing I ever did is to repeat what I did to get my older 6111 to talk to sarge. It is available here. That worked like a piece of cake. I installed a newer python and the python shell using this method.
I tried connecting to python over bluetooth serial console. But I don’t think I ever got it right. So google and I got these links.
http://ramblingfoo.blogspot.com/2007/05/bluetooth-fun-with-my-nokia-6600.html
https://bugs.launchpad.net/ubuntu/+source/bluez-utils/+bug/227429
Both had the most vital information to get started. Here is what I did.
$ sdptool add --channel=4 SP
$ rfcomm listen 1 4
I used 1 because I tried setting my debian to use 0 at startup. Another “fail” attempt that one.
In another terminal,
$ screen /dev/rfcomm1
It had some wierd characters to start, just press enter and a new interactive python prompt appears. I checked to ensure that it is the one on the phone and not on my machine!
Now to try something useful
…
An Idea?
I hate to think I have good ideas, but this one might be worth exploring. Yesterday was a major network outage in our lab. There was some upgrade going on in the computing facilities so the networks kinda went for a toss. This is not a big issue in research facilities because at very few instances can such outages lead to larger problems. Almost nothing ever happens in a day or two. Ok, the MTechs/BTechs are different, but they have classes. So no network is not something that’d affect them.
I forgot that I was idle because of no network and went to the library to renew my long due books. Like a fool, I was carrying five books only to find out that the network at the library ain’t working and they cannot transact. Yeah, perils of a networked infra-structure. But there is a second point to this. Could the library have continued without stopping work? If not fresh issues, could they have at least handled renewals and returns, new memberships et al?
At first thought, no. But with a slight improvement in infrastructure: yes. All the machines are latest with very good hard drive capacities. If the library software was capable of caching certain details and work offline, library is independent of the network. And library was not alone.
You get the idea? I knew of a team that was interested in these lines. But they split. Ok, I come from there too. But the goal there was slightly different from this. Of course, this is not for a toss. I still need to verify with them that they are over with this. Again, I have done no research whatsoever to see what products already exist in this space.
RC Files?
A friend of mine asked me “What is RC in RC Files?”. What is it anyway? I did some googling and some tcl wiki pointed me to this link. So RC actually seems to stand for run commands. I’ve been using them for about 4 years now but never once wondered why they are called so! Interesting learning for the day.
Writing my own algorithm
I always considered myself a not-so-bad programmer, but I never have written my own algorithm for anything. Not to mean that I always lifted my code from somewhere, but almost always I would have coded some known algorithm to do the same work. You have pseudo codes in most algorithm text books.
Today, perhaps second or third time, I wrote my own algorithm to do a simple job: bit reverse an integer. It is a common thing in FFT implementations. In most cases, the bit reversal in FFT will use the block nature of FFT also. But my requirement is not in FFT. I looked around a bit and got quite a couple of links with working code. I ain’t linking them here.
Here is the snippet of code I wrote for this. I am not claiming anything by writing this code. Just that I spent a couple of minutes arriving at it. Its totally intuitive and “naive”, if you want to call it that.
int bitreverse(int val, int len) {
int i;
int br = 0;
for(i=0;i<len;i++) {
br += ((val&1) * ((int)exp2f((float)(len-i-1))));
val >>=1;
}
return br;
}
From python to C(pp)
Image via Wikipedia
Yesterday was big disappointment. My python code was taking just too long to process a graph of about 30000 nodes and 80000 edges. Actually, it was taking more than an hour to just construct it. After that I have a bunch of algorithms to run on it. And this graph is generated from a sample graph of about 1024 nodes and edges. But in reality I need to run the whole thing against an initial graph of 20000 nodes. The whole thing just doesn’t sound to work. There are two possibilities: First is my code could be dirty; Or python does not do my kind of work very well. I can’t say anything about python until I have cleared my code to be the best. But I don’t have the time to invest here, since all this is just paths to my actual work, and my work is elsewhere!
So, the other choice is to code the whole thing in C/C++. Actually it should be C, because I am not a particular fan on C++. But given the time constraints, I just may have to go with C++. The reason is simple. I want something like STL to hasten my job and not worry about performance. I simply don’t see any such library for C. There are some ways to use STL with C, I guess. So, C++ it is. I should probably spend some time and write STL like library for C or at least spend some time to see if somebody is already doing the job. Anybody knows some good library for C, please leave a comment. Yeah, and don’t bother asking why I am not a fan of C++. I wouldn’t bother to reply.
Count occurrences of a word in a file?
Tricky question. My friend came up with a request to count the number of occurrences of a word in a text file, without too much of a script. A single line solution? One that pops at the top of the head is grep -c. But that will fail if the word repeated within the line! With so many text processing commands in linux, I was left wondering what works easiest.
I haven’t used awk/sed/perl in a while. I could write him a python script in just about the typing time. But how should I do it without any of these? With the constraint that the words are separated by spaces, I ended up with this,
$ tr [:blank:] ['\n'] < file.txt | grep -c "pattern"
Seems to work. Not sure if there is an obvious mistake laughing at me. Maybe python can be harmful to your old linux habits!!
How not to write software
No, this is not another preaching or top ten tips or anything. This is about something I loved when I first understood it, felt people didn’t know to use it when I started using it and now feel is a bad design example. There are two facets to it : the windows registry and the nokia pc suite.
I knew about windows registry when I first started learning Visual Basic about 8 years ago. It felt exciting. You could actually register a service and some client could look it up and use much like the today’s hyped WSDL and SOA stuff. I was not a programmer then. Was just another curious kid trying to understand what my machine has installed.
After a while, I came across a whole lot of demo software that you could continue using by changing some entries in this registry. I felt that the programmers of these tools were missing something, or the entire idea of a demo is just a hype. Again it was too early for me to say anything about this. I just did not know enough of the software business then.
About three years back, I picked my first Nokia mobile phone. It came with this software called PC suite. At that time, I was as excited about it as I was about using windows registry. This was a time when I just started using linux. I used to regularly login to windows since I was not entirely comfortable with the toolset in linux and this nokia pc suite did not ship a linux version. It still doesn’t, but that is another issue.
But the pc suite experience left me wondering if it was written by software programmers. I was working in a software outsourcing co at this time and did understand something about software design and principles. But I found pc suite application very stupid. I seemed to eat a lot of my machine’s resources while trying to sync contacts with my phone, or transferring images from the phone. I have many times cursed the app and quit without doing anything.
Last week when I picked E51, the pc suite developers proved their capabilities. Pc suite wouldn’t install because the previous PC suite version was not completely uninstalled. WTH, you wrote both the versions, won’t you know how to upgrade between them? It left me irritated. I even thought I’ll return the phone to nokia and request them to hire some software engineers to do the user installation end of stuff also.
The issue : PC suite makes one million entries in various names across the entire registry making it almost impossible to remove them all. In fact, it must have gotten so out of their hands, that they even had a PC suite clean up application! Can you beat that? Anyways, after a couple of registry edits a lot of curses and about three restarts, the thing finally worked. Now I understand why they don’t ship PC suite for linux. You perhaps can never make it so complicated. Windows registry and Nokia PC suite combo is one perfect example for a “spaghetti pattern”, an anti-pattern that most software guys try to avoid. Do they really?
The reason for irritation has its seeds elsewhere. I have not used windows a lot in the last two years. I have a debian dual boot and am loving it. Installing something in linux can get just as painful, but most of the times, the issue is just unresolved dependancy. Rarely unresolvable. But in windows, they neither tell you what dependancy failed, nor what you can do to resolve them. You need somebody who speaks in “registry” to resolve the issue. Maybe this is because I don’t develop in a windows environment, but the user friendly part is totally lost. Why else is anyone using windows?
Tags: windows, linux, pc_suite, nokia, software, design, rambling
Firefox 3 is impressive
I have this age old machine in my hostel room. It is a 800MHz Celeron with 256M RAM. That is a good combination for CLI guys like me. It runs debian sid. Its primary purpose is documenting work over night, practicing a couple of scripts, occasional programming and movies. I use the gui only when browsing shares over dc, internet and movies. For movies I use no window manager. Default WM shifts between icewm and fluxbox.
I have installed iceweasel and dillo from the repository. Using iceweasel used to kill my machine. I can’t open a second tab and the machine resource monitor graph is mostly clamped to the top 98%. So, you know what time I spend on the internet after I get to my room.
Anyway, last weekend I downloaded firefox 3. Believe it or not, I am able to run firefox 3 along side django test server and emacs without saturating the machine resources. And even otherwise, I am able to have at least 3-4 tabs simultaneously open on my machine. I almost can’t believe this. Now I am really wondering if I ll update my firefox 3. I am just scared it might become memory hungry when they finally release it.
Mind Maps
I am trying to learn and use this technique for problem solving for some time now. I’ve heard quite a few people say that it works great and all that. Maybe it does. I don’t have enough data to substantiate either way. Today I stumbled upon this useful web tool that can create a mind map for you online. They call it bubbl.us. Maybe you’ve heard of it or maybe you are already using this, but this is entirely new to me. I just created my first mind map of things that I need to complete this month. I am not posting it here, because it is as chaotic as my thought process. Good, that gives me confidence that I have mapped my mind (mindlessly).
My First Web Design
After many futile and failed attempts to create a decent looking page, I decided I am not the right guy to do css. So, all my pages are taken from opendesigns.org or oswd.org. They are doing a good job and why kill myself with an unknown devil?
But the small itch to do my own work remained, until yesterday. I was so jobless that I went and created my own template. Extremely simple looking, uses images (:-( ), css. I think it is standards compliant. I haven’t yet checked it. I don’t even know what it looks like on IE. I ll get a uniform look between IE and firefox and then perhaps test for compliance.
You can take a look at the design here. I am not sure if I have seen it earlier. If you know another page that is fairly similar, do let me know. I’d be a good boy and provide a link back!
Blogged with Flock
Tags: web, new_design, css
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=11b6d669-e976-48e9-9728-ec8dac5bdc8d)

