Tuesday, July 15, 2008

HashMap loop in java

This is how you loop through the Key Value pairs in a Hashmap

Iterator iter = values.keySet().iterator();

while (iter.hasNext()) {
String key = iter.next();
String value = values.get(key);
System.out.println("Key ="+key+"\n Value"+value)

Here, I have implicitly assumed that values is a HashMap but as you know it can be of any Object that you like. I just used it for string and felt it might be a good example if someone is looking for it

Friday, July 04, 2008

Viewing firefox status bar in full screen

Using firefox in full screen is rather cool but I was missing the status bar which gives a lot of information about the link whenever I hover or whatever is being done by the browser. After digging up a few places, I came to this link in mozilla's site
about editing configuration files and in particular
Used to change the appearance of the browser.
Used to change the appearance of web pages.
Can be used to change various preferences .
They are in the profiles folder of your user account. Go to your current firefox profile folder, and into the chrome folder. You should see two files. userChrome-example.css and userContent-example.css, remove the example and add this:

/* Make status bars visible */
visibility: visible;

restart firefox. And voila, you have your status bar in full screen.

My Links

I just added a links section there on the sidebar so that you can see what I'm bookmarking lately. Most of them might end up being incorporated on the front page. If they are any bit useful to you, tell me. I might not have read them(or sometimes might want to read them again, so that might be useful to go over.)

If you are a fellow programming, hacking enthusiast, I'll be glad to share some links in del.icio.us.

Thursday, July 03, 2008

A simple mjpeg streamer for python

I've been working with networking stuffs lately, like XML, parsing and lately streaming. Originally, I wanted to do this for my Android project which is still slightly veiled in secrecy. It will be open sourced completely though, when it matures. So, I wrote this application in an effort to understand the networking behind it and get it to work on Android. Frankly, I am not so good with Java and working with networking stuffs with objects. Everyday I appreciate more of that power though and it's fun to learn new things. I tend to practice with python first and after the proof of concept works there, I do it in Java. It's slightly roundabout way of doing things but it works for me.
What this application does is that it takes snapshots of the jpeg files from the server fast enough for making it seem like it's video.. Well, that's what it is anyways. Let's just say I haven't understood streaming and multi part files properly enough to implement. So, basically, it just sends a GET to the server and pulls the file one by one in a loop. It's really that simple.
The tricky part was to get it to display properly. Tkinter took care of that with Python Image Library. It would be easier if the files aren't jpeg though. That might be for future implementations but for now it's fine for what I'm doing with my Android project.
Anyways, I decided to open source it entirely at


That might be useful to someone, if nothing but just to learn a new thing or two about python. It' s fairly unpolished even as a basic tool but I hope to improve it to some degree to learn about multimedia streaming and threading concepts in python.

If the application was any bit useful, do drop a comment.

Here are the sources, if you wanted to view them right away



Here's my picture after I finally got video in Android.. hehe. That program did serve a purpose. Phew!


Out with Ads, In with analytics

Finally, I got rid of the annoying ads and included Google Analytics instead. I hope it helps me track users better (HEHE, evil laugh). Nah, I just want to see my traffic from a fairly trusted source. Since I've started updating the blog again, I want to see how many people are coming.

And yeah, the ads won't EVER come back on this site. PROMISE!!!

I wonder if that news belonged to twitter than over here. I've become a bit more conscious about twittering after I saw this.

Hah, I wonder what would take to make me a twitter shitter! (An iPhone perhaps?.... the Dark side is strong there I can feel it).

Thank You Firefox.

Yep, it's official. And I've grabbed my copy of the thank you letter that Mozilla is giving away.
I actually like the way this has been handled by Mozilla with all the hype about Firefox 3 that was circulating. Albeit, I felt it was a bit cheesy to go around downloading, or asking someone else to download for a while but it was fun. I had the download link on my desktop for every one to see.

So, here's my copy of mozilla certificate.

So you better get one from here
Hurry up, they might be in Limited supply. Hehee

Wednesday, July 02, 2008

positServer online

"Release early, release often"

These were the words that sparked the open source revolution.

I'm finally trying to follow this by releasing my positServer application under GPLv3 on googlecode. It's rather half baked right now and I intend to use it mostly for backup purposes. Hehe, it's hard to screw up when your backup server is the mighty Google Inc.


If you do checkout, do send me a comment. I'll start posting some screenshots and details about what I've been upto soon.

Monday, June 30, 2008

Sending Binary files over xml rpc

I'm posting this because I finally figured how to send files(pictures in particular) over xmlrpc. It took me a while to figure it out since I was mostly concerned with saving the files into database but here it is.

#!/usr/bin/env python

from twisted.web import xmlrpc, server
import os

class PositRPC(xmlrpc.XMLRPC):
        def xmlrpc_savefile(self, file):
                datum = file.data
                thefile = open('/tmp/gnu.jpg', "wb")
                #filebuffer = file
                #os.spawnl(os.P_NOWAIT, '/usr/bin/display', '/tmp/gnu.jpg')  
                print datum
                return 1

if __name__ == '__main__':
    from twisted.internet import reactor
    r = PositRPC()
    reactor.listenTCP(7080, server.Site(r))

Then I opened trusty IDLE
>>> import xmlrpclib
>>> s = xmlrpclib.Server('')
>>> d = xmlrpclib.Binary(open('/home/pras/PicasaDocuments/gnu.jpg', 'rb'))
>>> s.savefile(d)

The idea here is that although the file is sent as a Binary, we need to convert it to string(bytes) to save it. Since we have opened the file with 'rb' option in IDLE and with 'wb' option in our server (respectively for read binary and write binary), we get binary file at the server end.

Sunday, June 29, 2008

Locking screen from command line

I use gnome and so far I've been happy with my Ctrl+Alt+L shortcut in gnome. It used to lock up the screen when I was away from the desktop. However, recently, I've started to use XFCE and sometimes ratpoison, which didn't have this shortcut.
Anyways, the simpler way to lock your screen is from command line and it seems to work everywhere I've tried so far.

$xscreensaver-command -lock
I just kept in here so that I don't forget. Maybe this little tip would be useful for some.

I just found an alternate method that can work too.
$gnome-screensaver-command -l

Friday, June 27, 2008

Code Highlighting in Blogger

Don't you just love syntax highlighting that we've become so used to these days? Be it the venerable emacs editor or the new and upcoming Notepad++es, we love our syntax highlighting editors. But the codes on our sites still do suffer this problem of being black and white. I solved this problem for our college's hfoss wiki by installing the GeSHi CodeTag Extension for mediawiki but while looking at my own posts in here, it seems the idea needs to be extended to blogger. It really looks too ugly to my used-to-pretty-IDE eyes.
In my quest to look for a solution, I hit this blog http://codeshepherd.blogspot.com/2007/09/syntax-highlighting-for-code-embedded.html
Which had two ideas. First one, to use vim's TOhtml. But being lazy to modify all my files over and over again, I decided to forego it. I copied the prettfy.js and prettify.css files to my ubuntu.org.np server and followed the instructions at http://google-code-prettify.googlecode.com/svn/trunk/README.html
The effects were, well, wierd. Apart from rather slow loading times that javascript induces, my code looked horrible with
s after every line. Totally horrible and waste of space. I looked at the code and zeroed in on line 834 where I found this regular expression:

833 var htmlChunk = PR_textToHtml(
834 tabExpander(sourceText.substring(outputIdx, sourceIdx)))
835 .replace(/(\r\n?|\n| ) /g, '$1 ')
836 .replace(/\r\n|\n/g, '

After playing around with this, breaking it and everything, I realized I'm not really helping anyone here. Apart from the fact that not everyone uses javascript by default, including me (thanks to noScript) and even I use some unconventional browsers from time to time just for kicks like w3m, elinks, lynx (Ahh, those good old days, when they were my only browsers). So, I went for the vim solution.

Now, the next frontier: Posting to blogger automagically from vim/emacs whichever is easier to automate from. (Yeah I know there's something for emacs to do this) but with this functionality right there for recognizing the code and htmlifying it.

I think I've had too much coffee tonight. I just realized, "Why am I posting this at 2AM when I have some nice programming to do?" Anyways, back to my programming. Hope this post helps someone. Or, if you know some tool for doing these things automatically, tell me so that I can save some time (or even some google time if that's what you wanted to say :).