Pronoy Chopra's Blog

Rants and code

Transcripts

So, it turns out, applying to universities abroad isn’t that easy. The worse part is they are arrogant enough to not inform you, that your documents are incomplete. I had to call the universities to check if everything was alright and they replied in the negative. I panicked and called all my relatives who knew about sending documents to the US.

The transcripts that need to be sent to the US should be sealed and sent directly by your previous university. I contacted my counsellor at Jamboree and she said it was obvious. Apparently it isn’t obvious. On that note, if you’re thinking of trying for the US and are thinking of seeking help for the same then please keep the next few lines in mind:

Jamboree is a unit of incredibly incompetent individuals who are not only unable to bring about a credible result but are also very inept at training the students for GRE or TOEFL. I took my exam after having prepared with them and scored a dismal 1190. I retook the test on my own and got a 314 without anyone’s help. As far as admissions are concerned Jamboree is just one of those faces in a dingy street that promise results without actually ever delivering them. They are callous and misinformed.

That being said, lets move on. The universities require sealed transcripts which in my case had to be retrieved by visiting my undergrad university in person and obtaining them. Oh god, I hate that place. But I got through. Then I got my individual mark sheets attested by a notary. That cost me a lot. I mean every document costs about 150 INR to be validated and I had 20 copies to be validated. After having validated them, I sent them flying to the respective destinations via FedEX.

What a pain it has been.

My Experience With CentOS 5.8 and Setting Up Flask

I have worked with Debian, Ubuntu Server, ArchLinux and now CentOS and what a kick in the nuts it has been. CentOS 5.8 ships with Python 2.4 and it is an absolute pain to setup. But finally it’s done.

So I began with installing Python2.7.3 first.

install Python2.7
1
2
3
4
5
6
$ wget http://www.python.org/ftp/python/2.7/Python-2.7.tgz
$ tar -xvf Python-2.7.tgz
$ cd Python-2.7
$ su
root$ ./configure --prefix=/usr/local
root$ make && make altinstall

Now we have Python2.7 binary in /usr/local/bin and we can go about installing Setuptools

install Setuptools
1
2
3
4
5
6
7
$ wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e
$ tar -xvf setuptools-0.6c11.tar.gz
$ cd setuptools-0.6c11
$ su
root$ python2.7 setup.py install
root$ easy_install-2.7 install pip
root$ pip-2.7 install virtualenv

Now, after having done all of this, I needed to install mod_wsgi

mod_wsgi
1
$ yum install mod_wsgi

And that’s where I asked people at #pocoo to shoot me in the face. It turns out you need mod_wsgi compiled with Python2.7 to use it with Python2.7

So, let’s uninstall mod_wsgi and then build it from source

compile mod_wsgi
1
2
3
4
5
$ wget http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-3.4.tar.gz
$ tar -xvf mod_wsgi-3.4.tar.gz
$ cd mod_wsgi-3.4
$ ./configure --using-python=/usr/local/bin/python2.7
$ make

I got this error http://code.google.com/p/modwsgi/wiki/InstallationIssues#Mixing_32_Bit_And_64_Bit_Packages Which means it needs Python2.7 built with x86_64 not the 32 bit.

So, now, reinstall Python2.7

install Python2.7
1
2
3
4
$ cd Python-2.7
$ su
root$ ./configure --prefix=/usr/local --enable-shared
root$ make && make altinstall

And now reinstall mod_wsgi. Wow, this has been so difficult.

Anyway the problem doesn’t end here. Now we have to configure httpd.conf

httpd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
WSGISocketPrefix /var/run/wsgi
WSGIPythonHome /var/www/virtual
#WSGIPythonPath /var/www/test/virtual
<VirtualHost 122.99.126.71:80>
ServerName rhknhost
WSGIDaemonProcess herokufinal user=pronoy group=pronoy threads=5
WSGIScriptAlias / "/var/www/herokufinal/herokufinal.wsgi"
DocumentRoot /var/www/herokufinal
ErrorLog /var/www/herokufinal/logs/error.log

        <Directory /var/www/herokufinal>
                WSGIProcessGroup herokufinal
                WSGIApplicationGroup %{GLOBAL}
                WSGIScriptReloading On
                Options Indexes FollowSymlinks Multiviews
                Order deny,allow
                Allow from all
        </Directory>

</VirtualHost>

And then create the .wsgi file for running the application

myapplication.wsgi
1
2
3
4
5
activate_this  = '/var/www/virtual/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys
sys.path.insert(0, '/var/www/herokufinal')
from profilebuilder import app as application

Jesus. The time it took to figure this out. Oh God, I could’ve built a fucking house by then. 12 continuous hours. Never again CentOS. Never again.

Finally Got Allegro 5 Working on Mac OS X

I’ve ranted about this before I was unable to get Allegro working on Mac OS X. So today, for no reason I tried it again. Followed the Wiki to the letter and yet, it wouldn’t work. It was unable to find the frameworks. Specifically Allegro-5.0Framework. I did EVERYTHING and couldn’t figure it out. Until while searching for Header Search Paths in Build Settings caught my eye. There was a Framework Search Path too. And I provided it with the path /Library/Framework.

It worked and I need to kill someone now. Seriously, fuck you Xcode, fuck you.

Arduino IR Code: Updated

Here’s my updated Arduino code that I wrote to go with the protoshield by 9circuits and the relay shield connected to the protoshield.

ArduinoIR.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
int RECV_PIN = 11;
int relay2 = 7;
int relay1 = 6;
long vol_down = 948321226;
long vol_up = 948321218;

boolean relay1_FLAG = false;
boolean relay2_FLAG = false;

#include <IRremote.h>

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
  pinMode(relay1,OUTPUT);
  pinMode(relay2,OUTPUT);

}

void check_val_execute(long a) {
  if (a == vol_down) {

    if (relay1_FLAG) {
      light1_on();
      relay1_FLAG = !(relay1_FLAG);

    }
    else {
      light1_off();
      relay1_FLAG = !(relay1_FLAG);
    }
  }

  else if (a == vol_up){

    if (relay2_FLAG) {
      light2_on();
      relay2_FLAG = !(relay2_FLAG);
    }

    else {
      light2_off();
      relay2_FLAG = !(relay2_FLAG);
    }
  }
}

void light1_on() {
  digitalWrite(relay1,HIGH);
}

void light2_on() {
  digitalWrite(relay2,HIGH);
}


void light1_off() {
  digitalWrite(relay1,LOW);
}

void light2_off() {
  digitalWrite(relay2,LOW);
}

void loop()
{
  if (irrecv.decode(&results)) {

    //Serial.println(results.value, DEC);
    delay(300);
    irrecv.resume();
    long x = results.value;
    check_val_execute(x);
  }
}

No comments yet, I’ll do that later.r

NASAs ISS Live Stream

This is just a link to the stream that I need to find again and again whenever I want to tune into the NASA’s ISS Live Stream.

1
mms://a1709.l1856953708.c18569.g.lm.akamaistream.net/D/1709/18569/v0001/reflector:53708

Open using VLC.

Configured Linksys WRT120N: Bye Bye Old Wifi

So I finally decided to close my native router (Teracom’s) Wifi and get a proper lossless Wifi running at home. I have had the urge to use this router for a long time now. It was gifted to me by my cousin but I never got around to understanding how to deploy it. Except today. I closed the Teracom Wifi and extended an ethernet cable to the Linksys router.

Now earlier I wasn’t able to deploy it because I didn’t realize it ran on an extended bridged network. I thought it ran PPPoE. I mean it does run PPPoE but only via a service provider’s ethernet network. Considering over here in India we don’t have that we use a bridged network. Okay so that being said and done, I tried to plug an ethernet cable running from the Teracom (henceforth called T) to the Cisco.

It didn’t obviously work the first time (No surprised there). But strangely it was communicating with the network but not relaying packets here. Then I remembered our old exercises back from college. It was obvious, there was subnet conflict. The second router would have two networks. One terminating at it and the other originating from it.

So, if the first subnet was as 192.168.1.foo the other would obviously have to be different. So, the other became 192.160.1.foo and voila it worked like a charm. The problem with T’s network was that it was dropping packets a lot. I don’t know why that started happening suddenly but hey, use Cisco be safe.

Heroku Is Full of Surprises

So we finally deployed on Heroku for a quick run and what do we find? The dynos idle if not used for an hour. So your app will sleep if you don’t send it a request for an hour. I was scared for a second when I realized my app had been killed because probably it refused to sleep.

But hey what’s this, there’s another app that sends request to wake idling apps so that the dynos won’t sleep. Enter Wekkars. I mean there isn’t a puzzle created by human beings that another human being can’t solve. Well I read that in an Edgar Allan Poe book so nevermind the cheesy lines.

On the other hand, the good thing about Heroku is it’s ease of deployment. I mean what do you need to do really:

  1. Create your app
  2. Create a Procfile that will start your app
  3. Commit code to heroku master (using git)
  4. Profit

there’s an additional 3.5 that involves adding a helper add on but that is trivial. So Heroku is pretty good, we’ll continue testing.

AVR Assembly Revisted

Assembly for AVR is really interesting. Back in college I wrote a number of programs and I’ve been going over them again. This is some of the code.

I have 8 LEDs connected from D0 to D7 on PORTC and they are in the source configuration. 0xFF makes them light up and 0x00 shuts them down. So this is the blinky for you.

Now the DELAY function can only be called if the STACKPOINTER is set. The first few lines after .ORG do just that. Now I’ll be working on timer and interrupts but first I’ll put in some more code for simple things like adding 16 bit numbers etc.

My Experience With Pymongo Till Now

In one word, it’s been pretty awesome. PyMongo, the Non relational database is pretty good. Here’s some code.

PyMongo insertion
1
2
3
4
5
6
7
from pymongo import Connection as c

c = c('localhost', 45000)
db = c['test_db']
users = db.test_db['userlist']
user = {'username':'pronoy', 'password':'foobar'}
users.insert(user)

Now to retrieve the info it’s even simpler.

Retrieving data
1
2
3
4
5
6
from pymongo import Connection as c

c = c('localhost', 45000)
db = c['test_db']
users = db.test_db['userlist']
users.find({'username':'pronoy'})

The interesting this is, if the collection isn’t available it’ll create it and if the database doesn’t exist, it’ll create that too. I tried using mongodb deployed on our lab machine and the python application running on my machine. Worked like a charm.

Now we can also search according to the _id key generated by the BSON.

1
2
3
4
5
6
7
8
9
10
11
12
13
from pymongo import Connection as c
from bson.objectid import ObjectId, InvalidId

c = c('localhost', 45000)
db = c['test_db']
users = db.test_db['userlist']
try:
  users.find(ObjectId('728als450000000'))
except InvalidId:
  print "No such ID exists"
else:
  for i in users.find(ObjectId('728als450000000')):
      print i

Took me quite a while to figure out that ObjectId and InvalidId belong to BSON and not pymongo. Either way work is good and next post I’ll share my experience with Flask-Sijax. It’s a really cool way of implementing jQuery Ajax calls.

Replaced Spotlight With QuickSilver

So after I decided not to use mds I removed spotlight’s icon as well. Now I am using QuickSilver for the whole thing. It’s way faster.

Here’s a screenshot.

Yep, seems legit.