On Django

A week or two ago I started learning Django, and wrote my first app, a simple contacts book thingy. Right from the get go, I was amazed by how everything felt so natural in Django, at least to me. The MTV pattern seemed really intuitive and I had …

A week or two ago I started learning Django, and wrote my first app, a simple contacts book thingy. Right from the get go, I was amazed by how everything felt so natural in Django, at least to me. The MTV pattern seemed really intuitive and I had no problem diving right in and creating an app. The Django documentation is extremely well written and answered all the questions I had while coding. Even though I was creating my first Django app, I had no problems in incorporating generic views, model forms, pagination etc. In order to have database migration support (yes, I kept changing the schema even for a simple app :p) I installed South and everything was smooth sailing from there. The last thing I want to add to the app is search capabilities, and for this I’ve decided to use the Haystack application. I’m pretty sure this is overkill for such a simple app, but I wanted to try out this application and hence decided to throw it in.

After working with Django, I’ve decided to go back and give Rails another go. I’ve almost completely forgotten all the concepts from Rails, and I would love to refresh my memory. 

Mozilla World Series of Hack

Sam and I took part in Mozilla’s World Series of Hack held on 7/22/11 7.30pm to 7/23/11 7.30am. The rules of this contest were slightly different from previous hackathons I’ve attended: contestants were allowed to start work on their projects as e…

Sam and I took part in Mozilla’s World Series of Hack held on 7/22/11 7.30pm to 7/23/11 7.30am. The rules of this contest were slightly different from previous hackathons I’ve attended: contestants were allowed to start work on their projects as early as 7/15. They would then have 12 hours to work on it during the event and then they must demo at 8.00am. 

Sam and I had an idea that we started working on sometime around 7/19, but on the day of the competition we decided to completely change our idea and build something in the 12 hour period.

We wanted to implement a turntable.fm clone in 12 hours. Our concept revolved around a social music experience, where peers (users) connected to hubs (channels) and within a hub they could play music that would be heard by all peers connected to that hub. Each hub would have a ‘now-playing’ queue and songs added by peers would get added to this queue. Everyone present in the hub could also chat with other users present in the hub.

We implemented our idea using node.js, making heavy use of the awesome NowJS library for communication between the server and the clients. All audio playback was handled using html5.

NowJS is a wonderful library, and it was no suprise that a LOT of teams at the event took full advantage of it’s capabilities. The guys from NowJS were also at the event and were super helpful. 

Overall, the event was a great experience, and I learnt a lot in 12 hours. Kudos to Mozilla and the engineers from all the other companies who helped make WSOH kickass.

 

Tweet streamer using Node.js

A day or two ago I decided to learn Node.js and was looking for tutorials and articles on the internet for the same. In my quest for knowledge I came across this tutorial that talks about building a real-time tweet streamer using Node. Unfortunate…

A day or two ago I decided to learn Node.js and was looking for tutorials and articles on the internet for the same. In my quest for knowledge I came across this tutorial that talks about building a real-time tweet streamer using Node. Unfortunately, the code as presented on the website doesn’t work, I guess due to changes in the Node API since the tutorial. After a bit of researching and digging around in the Node API docs, I managed to produce a version that works.

Be warned though, this application makes a LOT of requests to the Twitter API resulting in your application being banned for an hour from using the Twitter API. Also, this is the first node application that I have written, so I might be making a lot of beginner mistakes. Please forgive me for this. The goal of writing this application was to have a working version of what was presented to us in the tutorial.

The version of node I am using(based on the output of 'node -v') is 'v0.5.0-pre'.

Here is my code.

All your __import__ are belong to us

Everyone knows and loves Python’s import function. This function is used to import external modules into the current module/script we are writing. Here are a few simple examples illustrating how the function can be used: Internally, a call to the …

Everyone knows and loves Python’s import function. This function is used to import external modules into the current module/script we are writing. Here are a few simple examples illustrating how the function can be used:


# import a specific module
from vehicle.four_wheels import car
my_car = car.Car(transmission="automatic")
# import a specific class within a module
from vehicle.four_wheels.car import Car
my_car = Car(transmission="automatic")
# import everything from a module into the current namespace
from vehicle.four_wheels import *
my_car = Car(transmission="automatic")
my_bus = Bus(color="Yellow")

view raw

gistfile1.py

hosted with ❤ by GitHub

Internally, a call to the import function makes a call to the built-in __import__ function. However, there are 2 cases where using import would not work and the only way out is to call __import__ ourselves.

The most common case where we would have to call __import__ directly would be when we want to import specific modules at run-time based on user input. Here is how we might do that:


# global scope these variables so that
# we can use them throughout our code
Car = None
Bus = None
#
# exciting stuff happening here
#
# now, based on the variable vehicle
# we want to import a specific module
if vehicle == "car":
# equivalent to: from vehicle.four_wheels.car import Car
_Car = __import__("vehicle.four_wheels.car", globals(), locals(), ["Car"])
Car = _Car.Car
if vehicle == "bus":
# equivalent to: from vehicle.four_wheels.bus import Bus
_Bus = __import__("vehicle.four_wheels.bus", globals(), locals(), ["Bus"])
Bus = _Bus.Bus

view raw

gistfile1.py

hosted with ❤ by GitHub

Yes, I know that we didn’t really have to import at run-time in the previous example. It was just meant to be a simple example πŸ™‚

Another case where we might have to call __import__ is when, for some reason, the parent modules/folders for a module we want to import or a module itself has a name with characters that are not allowed by Python. For example, something like the snippet below would not work:


# this does not work!
from vehicles.four-wheels.car import Car

view raw

gistfile1.py

hosted with ❤ by GitHub

Notice how the hyphen is not allowed in the module name. Here is how we might work around that:


# this works!
_Car = __import__("vehicles.four-wheels-car", globals(), locals(), ["Car"])
Car = _Car.Car

view raw

gistfile1.py

hosted with ❤ by GitHub

California!

I’ve been in California for 3 weeks now and I’ve been having a blast! Work is great and being with friends and family is always a good time. I’ve started work on my secret project, but have been having misgivings about it since yesterday. More spe…

I’ve been in California for 3 weeks now and I’ve been having a blast! Work is great and being with friends and family is always a good time.

I’ve started work on my secret project, but have been having misgivings about it since yesterday. More specifically, I’m concerned about the fact that what I’m building is not how I pictured my idea. I’ve decided to stop development for a few days and think more seriously about the purpose of the application. I think I have a good idea, it’s just that I feel that I’m not executing it correctly. In the meantime, I’ll be working on the other items on my Summer to-do list. Also, I think I’m going to take up running on the days that I don’t bike to work 😐 

My Ubuntu Setup

I’m currently running Ubuntu 10.04, and will update to 11.04 in a week. Since I started using Ubuntu over a year and half ago I’ve found a few apps that I now absolutely cannot live without. Here is my attempt at listing most of them, in no partic…

I’m currently running Ubuntu 10.04, and will update to 11.04 in a week. Since I started using Ubuntu over a year and half ago I’ve found a few apps that I now absolutely cannot live without. Here is my attempt at listing most of them, in no particular order:-

tig: Text based gui for browsing git repos. 

ddd: For when command line gdb is just not enough. Used it extensively during my CS 241 course, especially for the programming assignment in which we had to implement malloc(); pointer arithmetic can get messy quickly πŸ™‚

gvim: I’m a huge (g)vim fan! I adore this colorscheme, and you should also get this for painless folder navigation within (g)vim. 

Dropbox: Ever since my old laptop died on me and I lost all my data, I’ve started to become super cautious with regards to backing data up. That’s where Dropbox comes in and simplifies my life. I’m a huge fan of their service and the way syncing with multiple devices works so seamlessly. 

vlc: for when you need your media fix. 

Ubuntu Tweak: makes customizing your Ubuntu setup a breeze. 

Cheese Webcam Booth: My choice for a webcam software. 

xpad: Allows you to put sticky notes on your desktop, very similar to the notes widget in Windows 7

Faenza icon set: It’s pretty. Oh, so pretty.

htop: It’s like top. But better. 

That’s all I can think of right now. I’m petty sure I’m missing a few so I’ll be editing this post as and when I think of something. 

Finals!

Finals have started here at the U of I, and I just got done with my CS 411 final yesterday. 3 more to go: Math 415 8.00am on 5/9, Phil 102 at 1.30pm on 5/9 and CS 241 at 8.00am on 5/13. I’m heading to California after that to begin my internship w…

Finals have started here at the U of I, and I just got done with my CS 411 final yesterday. 3 more to go: Math 415 8.00am on 5/9, Phil 102 at 1.30pm on 5/9 and CS 241 at 8.00am on 5/13. I’m heading to California after that to begin my internship with Riverbed Technologies, Inc. Yay! I’m going to be working at the Sunnyvale, CA office. I can’t wait for Summer πŸ™‚ 

 

Bacon?

While working on my CS 411 final project, I found myself listening to my “Lamb of God” radio station on Pandora extensively, somehow simple PHP-MySQL tasks and Lamb of God-esque epic metal music go great together. Like bacon, cheese and fries :D.

While working on my CS 411 final project, I found myself listening to my “Lamb of God” radio station on Pandora extensively, somehow simple PHP-MySQL tasks and Lamb of God-esque epic metal music go great together. Like bacon, cheese and fries :D. 

 

 

work Work WORK

“But what about the title of this post?” you ask. I have to finish a group project for Phil 102, a group project for CS 411, a homework and programming assignment for CS 241. And catch up in all my classes. And start prep for finals.

<emotional> I just realized that this semester will be over in just under a month. Soon I will be a Junior. A JUNIOR! I can’t believe how fast time seems to be moving. I’m having an amazing time at UIUC so far: I love my major, I’ve met wonderful people and I’ve learnt a lot about life in general. I can’t believe this will all be over in two years. </emotional>

“But what about the title of this post?” you ask. I have to finish a group project for Phil 102, a group project for CS 411, a homework and programming assignment for CS 241. And catch up in all my classes. And start prep for finals. 

Life etc.

Installed node.js and MongoDB on my computer yesterday. Might play a bit with that over Spring Break. Another goal of mine is to finish my CS 241 programming assignment(implementation of malloc) and catch up in all my classes. And work on the CS 4…

Installed node.js and MongoDB on my computer yesterday. Might play a bit with that over Spring Break. Another goal of mine is to finish my CS 241 programming assignment(implementation of malloc) and catch up in all my classes. And work on the CS 411 project. 

Check out this amazing CSS 3 demo!