March 19, 2009

On git, gitosis, and python issues on Windows Vista

Some browsing, debugging, and IRC chats later, I have managed to set up a git repository on Windows Vista using cygwin, with a few unexpected hiccups. I will try to repeat the process on a virgin setup to come up with a more authoritative flowchart of how to go about things. For now, I'll just list down the issues I faced.

I used gitosis to host git repositories over ssh. It's pretty elegant, really. Administering gitosis is limited to managing a configuration file and user keys, which itself themselves are in a gitosis hosted git repository. Neat.

These two articles

cover everything you need to do to host git repos. The first link should be straightforward. However, since the second link is for linux users, there are a few deviations for windows. Try to follow the link, if you face difficulties, refer to the tips below.

Installing gitosis

Log in to an administrator account. Do a

cd ~/src
git clone git://eagain.net/gitosis.git
cd gitosis
python setup.py install
If the last command fails thusly
Traceback (most recent call last):
File "setup.py", line 2, in ?
from setuptools import setup, find_packages
ImportError: No module named setuptools
you may need setuptools from here. Scroll to the bottom, download an egg, and do
sh setuptools-0.6c9-py2.5.egg
Repeat the last step. After you have installed gitosis successfully, run the following command
chmod +r /usr/lib/python2.5/ -R
This was the first wtf. The downloaded egg we just installed gets installed with administrator ACLs, the above command ensures that everyone has access to the downloaded eggs.

Setting up gitosis

You need to add the git repository user `git' the windows way (the adduser command in the second link will not work). Once you've done that, make sure you've run the following commands

# in the new 'git' user's account
ssh-user-config

# from the admin account
# (domain users need to add '-d domain_name' to the mk* commands)
mkpasswd.exe -l > /etc/passwd
mkgroup.exe -l > /etc/group
Also, the command
sudo -H -u git gitosis-init < /tmp/id_rsa.pub
will need to be run as
# git user's account
gitosis-init < /tmp/id_rsa.pub
Of course, this assumes that you've copied your key to the /tmp folder.

The rest of the write-up should be fine, except for one thing. When you try to `git commit' you repo configuration, you may see an error like :
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 307 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To git@localhost:gitosis-admin.git
989f371..0616ebb master -> master
: invalid optione: line 2: set: -
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
Second wtf. Damn those pesky windows newlines. Do a
# `git' user's account
dos2unix ~/repositories/gitosis-admin.git/hooks/post-update
and you should be good to go.

This should do it. If you still run into problems, let me know. If you find solutions to them, post them up so that I may link to you. And when you do have a git repository up, give me the url to fork from :)

Edit: fixed grammar

March 11, 2009

Use Gmail to tell the world about yourself

Here's a trick that you might find handy.

Using a combination of gmail address aliases and canned responses, you can use gmail to automatically send directed, and relevant responses on your behalf.

You have to enable canned responses ...
... add a canned response while composing ...

and set up an appropriate filter.

As you can see in the pictures above, I have set up gmail to respond to any mails to sandesh247+ci@gmail.com with my contact information. I could have a public web page that does the same thing, yes, but in this way I reveal information only to those who explicitly ask for it, plus I have an account of all the requests.

You have to be careful though, this does set your account up for spamming. An automated reply immediately validates an email id, make sure you do this only with email addresses you want to make public.

March 04, 2009

Make your editor help you


While the above is funny, using a good editor, and using it effectively, usually prevents such situations. A good auto-completing editor isn't necessarily to help one type faster - it is most helpful for the context sensitive documentation that it provides. It brings documentation closer to the act of writing code, and saves the context switch introduced due to Alt+Tab, F1 or any other documentation invoking key-binding.

Like so -
If you haven't found out how to make your editor do this, you probably should.

February 25, 2009

Tauba Tauba

`Emosanal Atyachar' has to be the most brilliant song in a while. While initially it sounded almost repulsive, it now makes me laugh every time I listen to it. The devil is, as they say, in the details.
Bol bol why did you ditch me,
zindagi bhi lele yaar kill me,
bol bol why did you ditch me whore...
Ha ha ... modern devdas, indeed.

IMDB, and official links.

February 23, 2009

`calculable' textboxes using jquery

Here's some code to make your textboxes calculable. Demonstration here.

(function($) {
            $.fn.calculable = function() {
                return this.each(function() {
                    $(this).focus(function(e) {
                        var expr = $(this).attr('calcExpr');
                        if (expr) {
                            $(this).val(expr);
                        }
                    }); // end focus
                    
                    $(this).blur(function(e) {
                        try {
                            var expr = $(this).val();
                            var calculated = eval('with(Math){'+expr+'}');

                            $(this).attr('calcExpr', expr);
                            $(this).val(calculated);
                        }
                        catch (e) {
                            $(this).attr('calcExpr', '');
                        }
                    }); // end blur
                }); // end each
            };
        })(jQuery);

Yes, it uses eval. Doesn't evaluate on initial load. Provides no way to post the expression to the backend.

Expect improvements, and submit patches, once this goes into source control.

edit: Now available in a github repository.

April 04, 2007

Back to gym

I have started training in the gym again. Who wouldn't, after seeing what it can do for you? Though I doubt that a 45 minute workout, 4 days a week, is going to get me anywhere close to that.

March 23, 2007

Yet another puzzle


We pick two numbers a and b, so that a>=b and both numbers are within
the range [2,99]. We give Mr.P the product a*b and give Mr.S the sum
a+b.

The following dialog takes place:

Mr.P: I don't know the numbers
Mr.S: I knew you didn't know. I don't know either.
Mr.P: Now I know the numbers
Mr.S: Now I know them too

Can we find the numbers a and b?


I must admit ... my feeble mind couldn't comprehend that this puzzle even had solution when I first saw it. However, now I know that it does, and am still trying to work it out. If you are a bit impatient - Google around, you'll find the answer.

December 19, 2006

Identify yourself, civilian

This is the message you get at forum.nokia.com upon entering the username/password -

"The credentials you provided cannot be determined to be authentic."

Nice.

December 14, 2006

Equilateral triangle from an A4 sheet (solution)

If you don't know what the problem was, go here.

So, here's the solution. All we needed to do was find the point on the dashed line (left fig.) which would give us our equilateral triangle. Which can be done by folding the paper as shown in the figure in the right. Simple, eh?

Click here to see the figure.

I'll post pictures of the origami too, soon :)

Update:
Someone asked for a clarification, so here it is (image).

Once you get the point, fold along that point and one of the bottom corners. Tear. Repeat with the other corner. Done.

December 07, 2006

A4 for origami?

The day before yesterday, I sat down to make an origami at my office desk. Now, Origami can be a bit daunting, so I had chosen a simple one to begin with. However, the first step itself proved to be a hurdle.



Hmm. Now the only paper easily accessible in our office is A4 size (yes, I used discarded sheets of paper). Which brings me to my question - how do you get an equilateral triangle from an A4 sheet? Using the minimum number of folds too, or else the paper will be too crumpled for use.

If you have a solution, you may post it as a comment :)