Skip to main content

Posts

Showing posts from August, 2009

Fixing a mistake after commiting in Git

So, I ran into an interesting issue while coding today. I made a lot of changes and committed code to my Git repository. Just after committing, I realized that I still had to make some changes to a file and those changes should also have gone in with the previous commit. Fixing a commit mistake can be done in two ways. Revert the commit, make the changes and then recommit them. This is the preferred way if we have already made the changes public (and thus someone may already have pulled them). However, in my case I am the only one working on this project right now and I had not pushed the changes to GitHub, so I could try the other method. So here's what I did. I made changes to the file, added it to the index, and committed it thus: $git commit --amend Committing code with the --amend switch will cause the index to be committed as part of the previous commit. Git also brings up the editor window, in case we want to change the commit message. This method can also be used to change ...

Lack of design patterns in Python

While searching for PyCon videos, I came across Joe Gregorio's very good video on (lack of) design patterns in Python. I have also added the video timeline along with some notes I made for myself and my takeaway. Enjoy the video. Timeline: [00:00] - Start [00:15] - People pick tools based on a mythology and not necessarily facts [02:35] - Python isn't just Java without the compiler [03:34] - Design patterns are also a sign of weakness in a language [04:06] - Lack of design patterns in Python (proof of lack) [06:10] - Patterns are built into Python [07:00] - Strategy pattern in Python the wrong and right way [07:36] - The strategy pattern is invisible in languages with first-class functions [08:07] - Some other language features in Python (first class functions, metaprogramming, iterators, closures) [09:17] - The iterator pattern (iterators) is also built into Python [09:36] - The observer pattern is also built into Python [10:17] - Factory method pattern in Python ( [10:34] ...

iAccelerator

iAccelerator I took a sabbatical from my consulting work this summer to participate in the iAccelerator program. This is a program for early stage software startups, similar to YCombinator , but the first of it's kind (I believe) in India. I enjoy teaching programming, I have taught programming classes at a college , done corporate workshops, and more recently have been working on a website for participatory learning . This time I was looking for a different kind of mentoring experience, something which would be free form and fun. After a discussion with Freeman , I decided to go spend the summer at iAccelerator. In the first few days of the program we had introductions by all the teams where they spoke about their product and vision. This was followed by a session on team building and thinking out of the box, a few legal sessions, sessions on accounting and company law, and several other mentoring sessions. All this is very useful for early stage software stratups, especially whe...

Custom JSON Encoder in Django

I have been messing around with how to display date formats (in questions and answers) for my web based learning site from the past couple days. After trying various things, I settled for what seems to be a web 2.0 standard for displaying dates - displaying dates as '2 days 4 hours ago' instead of the actual date and time '4th August, 2009 5:50 PM' . I like this because I do not have to deal with any browser localization issues. Everything is a delta between the UTC time a question was asked and the current UTC time (btw if you are working with datetime in Python, do read this blog post ). In my Django based application, I use JQuery to get questions and answers for forums on every topic page. The application sends back JSON to the Javascript functions which display the questions and answers from the JSON objects. The DjangoJSONEncoder (scroll to the end of this module) provided by Django serializes dates in a specific format. I wanted to change this so that a d...