Pythonic HTTPS access

NOTE: Twitter Has Disabled Basic Auth as of August 31 2010 so this example will not work

I could have also named this post “Python HTTP POST with Basic Authentication?” But i wanted to keep it simple , and really this post is just meant for documentation purposes.

import urllib
import httplib2
import sys

if len(sys.argv) != 2:
    print "Please enter message"
    raise SystemExit

msg = sys.argv[1]

username = "user"
password = "pass"

http = httplib2.Http()
http.add_credentials(username, password)
response = http.request(
"https://twitter.com/statuses/update.xml",
"POST",
urllib.urlencode({"status": msg})
)

if response:
    print "Update OK!"
else:
    print "Error updating..."
Advertisements

The “bleeding edge” dilemma

The urge to run the latest trunk of KDE is too great ! but the fact that the trunk is not the most stable keeps a lot of us away from it. Our Friends over at project neon have done a great job trying to address the same issue.
But the problem is slightly bigger than this, imagine a scenario where you are working on two projects and for one piece of code to run you need to uninstall a few installed packages this breaks another piece of software that you need for another project.

Or another scenario would be , you are about to install an experimental piece of software. Do you leave your system in an inconsistent state if that experimental software doesn’t work ? Do you take a back-up ? or do you try to pull off a complex trick of lots of Alternate environments ?

The most embarrassing situation is when you go to your local Free Software User’s Group / LUG to give a talk about how great your OS and its applications are , and just when you are about to speak the app you were showcasing crashes , Damn !
How do you ensure that your apps don’t crash while giving the demo and also maintain your latest unstable hack to your favorite software without both getting into each others way ?

What is the solution to all of the above problems ?
I propose using Boot environments, on Open Indiana a.k.a Oi (Solaris) ( I have started to love this Distro , but my first love is always belenix.org 🙂 )
Now supposing you have a clean install of you create a snapshot

$zfs create snapshot mydistro@firstInstall 

and now make this snapshot bootable

$beadm create -e mydistro@firstinstall FirstInstall 

Now go ahead and bork up your system 🙂
You may want to come back to the borked system again later, so you create a new snapshot and make it bootable.

$zfs create snapshot mydistro@borked
$beadm create -e mydistro@borked Borked 

now you want to boot into the borked Boot Environment next time.

$beadm activate Borked 

reboot, and in the OI grub you will find FirstInstall and Borked entries, select the one you want and continue working. FirstInstall lands you up
in the system before you borked it up. Enjoy hacking 🙂

more info about boot environments and beadm
That’s all for now! Give OI a try , you may switch over 😉
Until next time !
Kunal

First step to getting KDE on OpenIndiana : Boot OpenIndiana ;)

OpenIndiana is a project created from the ashes of OpenSolaris. When oracle decided to close the development of OpenSolaris, some brave folks forked the kernel and put together a user-space to form OpenIndiana (OI), Its a great distro ! Above all its got software innovations (ZFS , dtrace, crossbow etc) which the linux userland can just dream of 🙂 (Though systemTap , btrfs are quite commendable as well.)

OK , so i have this great new distro and i love KDE so i want to see if my favorite softwares (Kate , amarok, digikam) work on OI or not. And sure they do ! (/me feels good here :)) the KDE – Solaris team has already created a repo with the latest KDE 4.6 packages. So , now i am convinced that i must start using OI. So i dump the dd image onto a USB stick and connect it to my laptop (a Dell Studio 1450). Now the fun stuff starts 🙂 OI doesn’t boot !!!!

After reading countless blogposts and consulting people on IRC (DrLou on #openindiana apparently had the same problem as me , and we sat together for 3 days (with breaks ofcourse 🙂 trying out everything that we could find) . In the mean time i had posted my problem to the OI discuss mailing list as well. Finally after a 2 day wait , i got replies from the OI gurus on the discuss mailing list. The message from Garrett D’Amore was particularly useful , he suggested me to add the -k option to the kernel line in grub and boot , this would fire up the In-Kernel Debugger the KMDB when i pressed “F1-A” during the boot process. But alas ! this didn’t work either 😦 Now i was desperately in need of some new ideas. Garrett’s post hinted me to check out more OI kernel flags. As it turned out, in an obscure wiki entry in BigAdmin (the solaris admin wiki) there was a mention of the flag “-B acpi-user-options=2” i appended the kernel line with this option and presto ! OI booted !. Now this was after 3 days of “beating around the bush” debugging and it felt great 🙂 . So, i headed over to #openindiana and told DrLou about my findings , and after a few tries even his laptop booted !! Yay ! (Supposedly this acpi bug comes to haunt users of solaris , from time to time :))

Now all that i had to do is to create a new beadm ( look up the solaris man pages , you will be amazed !) and add the bionicmutton repo to OI and that’s it, i have KDE 4.6 on OpenIndiana. OI Looks and Feels much better now 😉

This blog post is to document two things:
1. ” -B acpi-user-options=2″ might get OI to boot on your machine.
2. Never give up any problem , if you are facing it , you can be pretty sure someone else is facing it too ! stick to the problem and solve it.
(And after you solve it , in the Spirit of Good Will , share it with others by documenting it in your blog/wiki)

KDE solaris needs a lot of polish and could do with some more contributors. So if you have some spare time , drop by at #kde-solaris , #openindiana , #illumos on freenode.

That’s all for now ,
Until next time 😉
Kunal

I am going to conf.kde.in . You Should Too !

I am going to KDE india Konference ;)

KDE india Community is Organizing its first conference at Bangalore and I am thrilled to be a part of the organizing committee. I am going to the Konf ( As i would like to call it, lovingly 🙂 ) that’s no news, i love KDE ! but this blog post is for the vast majority of my friends who have no idea what KDE is , and what it means to be a part of.

Read On , to  know more about what to expect at the Konf , and why you just have to be there !

1. Artists :

KDE is a *HUGE* project and we have brilliant artists in our KDE art team. Seen our shiny new poster or the stunning artwork on the website ?  Those are Courtesy Eugene Trounev, be there to talk to him personally ! He is also giving a talk about “Graphics & Open Source: Survival guide” . You don’t have to be a software guru to attend this talk, just bring the artist in you 😉

2. Photographer :

As a photographer you try to capture all the moments you cherish ! You almost definitely use a photo-management application like Adobe Lightroom or the likes. But my fellow developer Aditya Bhatt will introduce you to “digiKam: Professional Photo Management” a *Free* photo management app that you just have to know about ! If you are excited about “automatic lens correction”, “Online sharing Integration” in lightroom, digikam had it for a very looooong time ! Be there to know more about it !

3. Person Managing a large diverse workforce (a.k.a Manager):

Before i start off on this point , let me put you in perspective. KDE is a project which has, as far as i know, thousands of active contributors, so it is very very big ! Now, I introduce our community ninja (a.k.a community manager, formally) Lydia Pintscher. She directly interacts with all of the thousands of the contributors , when required , and is very good at managing people. So , i am sure you can definitely learn a thing or two from her ! Plus have a lot of fun at the conference !

4. Gamer

You are an avid gamer , right ! Ever wondered what goes underneath your shiny new game that makes it tick ? Be there to attend the talk “Glue games with Gluon” Shantanu . I am sure , your time will be very well invested ! not spent 😉

5. Programmer / Technology Enthusiast :

You my friend are in for a treat ! Frankly this blog post will be an injustice to all the amazing tech talks lined up. Just head over to http://kde.in/conf/talks/ to treat yourself !

6. User :

You guys are very important part of the community ! we the KDE community are always open to new ideas and criticism / suggestions.  Please do drop by and bring in your friends too ! Your visit would definitely be fruitful . We also have loads of Hands-on Sessions , please bring in your laptops if possible 🙂

7. School Kids / College Students :

Guys and Gals , you just have to be there ! Heard of Google Summer of Code ? Google Code-In ? We have a LOT of ex-GSoC ers attending the Konf , come and meet them personally ! Also get to know about the project that interests you ( a must for GSoC & GCI ) and there is no better way than to get introduced by the people who actually develop for the project !

If you have queries about the event , post a meesage to conf@kde.in or Just register ! at  http://kde.in/conf/register/

NOTE : Use the below discount codes, don’t forget to bring your college IDs  🙂

  • Student discount: KDEIN_DIS_STU
  • Teacher discount: KDEIN_DIS_TCR

That’s all for now ! and See you at the Conf.

–cheers

Kunal Ghosh

Searching , Google Vs Facebook

After having watched Mark Zuckerberg’s two part interview on youtube, i was wondering what would, searching the same thing ( “seagate Goflex” ) on both the platforms (facebook and Google) would result in.

Side by side, the search term on google , facebook , bing (apparently facebook has some tie-up with M$)

OK , some of my observations ( please do share your observations too ! ) :

1. Google is good with Factual data.

2. Facebook has an added advantage with it knowing what my friends , other facebook users’ and i like . And how many of the users’ like / dislike / have commented on the topic i am searching. For the factual data , its using Bing (M$ ‘s search engine).

3. Bing is a reasonable search engine, i have nothing to say about it .

THE MOST IMPORTANT OBSERVATION :

4. Though Facebook uses Bing for its search, the Bing results Facebook displays on its search page are significantly different. I think Facebook does its own filtering on top of Bing results , to filter out results like following :

  • FreeAgent® GoFlex™

    Complete all three stages and stand to win the FreeAgent® GoFlex™ Family and Full HD 42 inch LCD TV. Contest closes 28 June 2010. Play now! FreeAgent® GoFlex™. Meet the world …

    seagategoflex.com · Cached page
  • seagate goflex : seagate goflex – Cheap, Discount and FREE Super …

    seagate goflex – Cheap, Discount and FREE Super Saver Shipping

    seagategoflex.blogspot.com · Cached page

The first of the above results from Bing, is quite relevant to my search string (“seagate Goflex”) its the official site of the product. Here both Facebook and Google missed it.

My motivation for the blog post is that , many search providers are coming in the market, each with their own way of looking at the problem of search. All are trying to do their best. But none of them IMHO are actually showing me what “I WANT TO SEE”.

They (search engines) should understand what i am searching for (in this case a product) and give me most relevant information first ( in this case, the price in and around where i live , the technical specs etc , they should ask some more questions to refine their search results ) .

Both google and facebook have the means (personal data) to understand about me and should strive to give personalized search results. With an option of “Factual Search” which is also very important. Facebook’s positive point is that, it gives me very few searches with some degree of personalization (what my friends think about it) . When i search for a text , i am not going to look through millions of pages that google shows me but only a few say about 10 to 20 most “relevant” results.

Both Google and Facebook should learn from each other. And M$ should focus on the one thing it has managed to do fairly good , make an operating system 😉 (Humor intended). It would be fun to see what future of search has in store for us !

Until next time !

LIVE LONG & PROSPER.

Kunal Ghosh

Urinal protocol vulnerability

When a guy goes into the bathroom, which urinal does he pick?  Most guys are familiar with the International Choice of Urinal Protocol.  It’s discussed at length elsewhere, but the basic premise is that the first guy picks an end urinal, and every subsequent guy chooses the urinal which puts him furthest from anyone else peeing.  At least one buffer urinal is required between any two guys or Awkwardness ensues.

Let’s take a look at the efficiency of this protocol at slotting everyone into acceptable urinals.  For some numbers of urinals, this protocol leads to efficient placement.  If there are five urinals, they fill up like this:

The first two guys take the end and the third guy takes the middle one.  At this point, the urinals are jammed — no further guys can pee without Awkwardness.  But it’s pretty efficient; over 50% of the urinals are used.

On the other hand, if there are seven urinals, they don’t fill up so efficiently:

There should be room for four guys to pee without Awkwardness, but because the third guy followed the protocol and chose the middle urinal, there are no options left for the fourth guy (he presumably pees in a stall or the sink).

For eight urinals, the protocol works better:

So a row of eight urinals has a better packing efficiency than a row of seven, and a row of five is better than either.

This leads us to a question: what is the general formula for the number of guys who will fill in N urinals if they all come in one at a time and follow the urinal protocol? One could write a simple recursive program to solve it, placing one guy at a time, but there’s also a closed-form expression.  If f(n) is the number of guys who can use n urinals, f(n) for n>2 is given by:

The protocol is vulnerable to producing inefficient results for some urinal counts.  Some numbers of urinals encourage efficient packing, and others encourage sparse packing.  If you graph the packing efficiency (f(n)/n), you get this:

This means that some large numbers of urinals will pack efficiently (50%) and some inefficiently (33%).  The ‘best’ number of urinals, corresponding to the peaks of the graph, are of the form:

The worst, on the other hand, are given by:

So, if you want people to pack efficiently into your urinals, there should be 3, 5, 9, 17, or 33 of them, and if you want to take advantage of the protocol to maximize awkwardness, there should be 4, 7, 13, or 25 of them.

These calculations suggest a few other hacks.  Guys: if you enter a bathroom with an awkward number of vacant urinals in a row, rather than taking one of the end ones, you can take one a third of the way down the line.  This will break the awkward row into two optimal rows, turning a worst-case scenario into a best-case one. On the other hand, say you want to create awkwardness.  If the bathroom has an unawkward number of urinals, you can pick one a third of the way in, transforming an optimal row into two awkward rows.

And, of course, if you want to make things really awkward, I suggest printing out this article and trying to explain it to the guy peeing next to you.

Discussion question: This is obviously a male-specific issue.  Can you think of any female-specific experiences that could benefit from some mathematical analysis, experiences which — being a dude — I might be unfamiliar with?  Alignments of periods with sequences of holidays? The patterns to those playground clapping rhymes? Whatever it is that goes on at slumber parties? Post your suggestions in the comments!

Edit: The protocol may not be international, but I’m calling it that anyway for acronym reasons.

ACK: This was originally published in XKCD http://blag.xkcd.com/2009/09/02/urinal-protocol-vulnerability/

My Own Activity Logger Application.

Having been constantly coxed by my father to log whatever i do , i have been using sticky notes from KDE project forsome time now. But i have a habit of messing around with my installation and managed to screw up my box. And inturn i lost all my logs. 😦 so  i decided  to write a Portable Activity Logging Application. Working through yesterday evening i have come up with this , it comes with the Netbeans Project Folder in case you want to modify it. If you happen to modify it OR have a suggestion , please leave a comment to this post.

The Application JAR file. ( Needs Java Runtime Environment to run).

NTFSFIX a life saving command !

I had a dual boot linux + XP for which i had a huge NTFS partition of about 170GB to store my backup data, ebooks, project details, STAR TREK episodes , songs etc.Then having fixed my 5.1 audio problem ( which was the only reason i still had XP hanging around) in linux, i completely removed the XP partition, just yesterday, i thought of installing windows again because we are learning assembly language at college and our teachers insist we use only MASM ( an archaic microsoft assembler) so i thought of installing WIN2K as that was all i needed, in 2K’s partition menu i created the partition and just as i was going to hit enter, the Dreaded BLUE SCREEN came up and that was the start of all my problems.

Having thought, i had made some mistake i came back to linux to check if my data was ok .But then i realized  that the backup drive wouldnt mount, after having gone through a lot of misery (trying out Chkdsk /f) etc & having to battle the thought of losing my data ,I checked up the NTFSFIX command for the

error “$MFTMirr does not match $MFT” and using the syntax:

$ ntfsfix (path of the partition eg. /dev/sda4)

and wala !! it ( the partition ) started working again !

Hope this short essay of mine helps you.

Also, never loose heart when all odds are against you.

Kunal Ghosh

(kunalghosh)

Please tune in for my next article on Practical Source Code Management

I have currently learnt the use of source code management and am using SVN for my CFF (Code For Freedom) Project which is related to creating a GUI for their Distro Constructor Application to create custom spin offs of openSOLARIS 2008.11 if you are wondering what openSOLARIS is !! head  to www.opensolaris.com for more info.

Its got some pretty cool features too !! I can bet you wouldn’t have seen those features before !

How About a DIY project for that lazy weekend !!

Recently we had our vacations , which was filled with plans to do things that i always wanted to do but didn’t get the time. Among the list of things there was a very interesting DIY (Do It Yourself) project to make a GSM SIM (Subscriber Identity Module) card reader. Its pretty thrilling and quite easy to accomplish also !! I came across this project on Youtube, the last place according to me to find such stuff.

Well this project is from the site http://www.citizenengineer.com/ these guys have done quite a good job and the resources such as the circuit diagram and the necessary software are readily available. And for those of you who hail from Bangalore , the components are easily available from SP Road and should cost around Rs34/- without the SIM-card holder which itself costed me Rs30/- anyways the links are as follows:

1. The Project Home Page

2.The Schematics PNG EagleCAD file and EagleCAD board layout

3.Software Source Windows executable

Finally Some Pics of my SIM READER 🙂

photo-0002

photo-00011