Pownce gone, use kwippy

In a blatant act of self promotion, now that pownce is finished, I can confidently write that we are the only other django based micro-blogging network with some traction. I do admit the user interface needs a bit of work, but if you interact with our community, you will realize that they are a set of amazing people.

So keeping in mind that you want to move on from pownce, try something new … or just try kwippy.

http://www.kwippy.com/signup/09b890abe5

Language of politics

After the tragic terrorist attacks in Mumbai, we see all the political parties starting their games. Lets have a closer look at what they said and where they went wrong.

Manmohan Singh - A speech which lacked character, though it did not lack the objectivity. In a time of crisis when this was televised what we needed was a stong speech, not this verbal powerpoint. If i had to rate this, it would get a 5 out of 10.(should be fired)

RR Patil - Well he will always be known for calling this a minor event. Was he even thinking when he said this, to rate this is difficult … he gets a -5 out of 10.(got fired)

http://ibnlive.in.com/news/maharashtra-deputy-cm-rr-patil-resigns/79454-3.html

Shivraj Patil - I was watching his press statement 2 on 26th night, and in all honestly where are the real leaders. It was a weak and non-assuring response on his end. He gets a 2 out of 10.(got fired)

V S Achuthanandan - dogs and politicians, they are some how related. Why would you state “If it had not been (Major) Sandeep’s house, not even a dog would have glanced that way.” on national media even after understanding the pain Major Sandeep’s father is in, Insensitive and must be voted out pretty soon. For this he pretty much beats the Thackeray family (needs to be fired asap)

http://www.zeenews.com/nation/2008-12-02/487658news.html

Thackeray family - Where are you guys ? Are they among the casulties ? They have dissapeared and I do wish they are gone forever. The quality of their politics borders the unethical and its good that they actually know how to keep quiet. Due to lack of any articles i cannot rate them at all, if i could i would give them -infinity out of 10. (should be fired from active politics)

Rest of the lot - They bordered from average to inadequate, I really wished that the young guns of Indian politics would show some balls. But then wishes are for people, implementation are for people with power :). Notable missing would be Rahul Gandhi, Omar Abdullah, Sachin Pilot, ….

What these guys need is to introduce more educated people in the mix and create some real value as parties. We need better press conferences (yes, critical) and good orators as leaders. I think the mic and z-class security has allowed the politicians to stay away from the masses for too long, time they talked to us man 2 man.

Mumbai, terror and NSG

Its been a really long 24 hours, I have been following it all on TV or the internet (twitter to be specific). In this process I have see yet another intelligence lapse where probably 200+ people will lose their life on the final count and this will create a dent in our national image. England conveniently goes back home after not even coming close to winning their matches in cricket, a whole host of articles being published about how India will lose its “terror free” south Asia image, and finally how it affects the Delhi elections coming up.

I was watching this show where a famous personality was talking about creating a SAS like force to defend ourselves against terrorists, though he made some valid point about crisis handling we should be clear that our SAS is the NSG. They are the true super commando force chosen out of the best young men in our army, they are provided with the best equipment (Isreali tavors n stuff) in addition to tactial training. This force was created in the aftermath of Operation bluestar, 1984 and has served in a lot of secret missions in addition to the known ones (Akshardham temple 2002). So please guys, be careful when we comment about our army and commandos, they are among the best (American army come and train in Mizoram,India for urban/forest warfare).

Mumbai has taken it and over time will probably absorb the losses like we have been doing after every crisis. But this should tell us that it is time to take control of who rules and how they rules us. Our politicians have been letting us down too often, and do not seem to have the willingness to change our corrupt/opaque system. Lets vote and also get other people to make a choice which does not compromise our national security and pride.

government aka sarkar

Well, my name is Dipankar Sarkar. And Sarkar is hindi for goverment … so one my friends (specifically Varun Gulshan) would keep calling me that which to be honest is a fantastic nickname ;). Jokes apart, I guess i am a bit frustrated with how things work around me. As an individual who says “chop, chop” as he is in a perennial hurry, it kills me to see how things work. Lets analyze this scenario properly, so India as a nation is used to the so called “Hindu growth rate” (3-4% of GDP) for a very long time. The problem with such growth is that it goes no where neither can you be called a problem or something great, as of today we have started growing post-liberalization (7-8%). But the problem of *slow growth* withing our working populace still persists.

We can take the latest Singur example as one case where its clear that we have not made the jump from socialist to capitalist even if our intentions as a nation is very clear (Capitalist that is). To be firmly capitalist would require a complete revision of how we Indians view our *ego*, as it is never personal when it comes to business (well there are exceptions as usual). What we require more than the 10% growth is that we need a revision or social change which makes us capable of understanding our position in the global village. Are we inferior ? i doubt that. Do we lack resources ? i doubt that too. We should start utilizing the power we have worked so hard to gain, if we do not hold our heads high then all of this growth is not worth it.

This fundamental change has to come from the goverment and the way we do our foreign policy, we need to be stronger only then can we Indians hold our position in the Global village. Being a super power or for that matter any power requires a lot of diplomacy and good foreign policy, hope we make it to the next league. On that note … more ranting later :).

The darwin awards - A Chronicle of Enterprising Demises

The darwin awards - A Chronicle of Enterprising Demises

Came across this due to my good friend Mr. Samir … well it turns out that there is an award for people who do wierd stuff and end up seriously injured or dead. I salute the guy who is running this … who says there is no humor in death :).

Honoring those who improve the species…by
accidentally removing themselves from it!

Now that is a killer sales line and i am sold here …. now i am off to checking out who won this year’s awards. do join me there too ;) ….

Excerpt from one such recipients story.
(February 1998) Matthew and his friends were sliding down a Mammoth Mountain ski run on a foam pad at 3am, when he crashed into a lift tower and died. His makeshift sledge of yellow foam had been stolen from the legs of a lift tower on Stump Alley. The cushion is meant to protect skiers who hit the tower, and the tower Matthew ran into was the one from which he had created his sledge. There’s a moral in there somewhere.

Rumors and more ….

To be honest, I am a very conspiracy theory kind of a guy. Always believe things after i can validate certain things personally, that invariably leads to me getting too involved (call it the observer effect). But then again there are certain things that are much bigger than me which i believe are absolute frauds, i will state some of the most obvious ones.

  • Humans landing on the moon (yeah right, NASA is struggling now … wonder why they need to design what already works)
  • NGOs are for the greater good (from what i hear they are only for their own good, time we stopped using the tax payers money for them)
  • Net neutrality (impossible, DNS servers still in the USA … the point is lost on me as to how is it fair, internet as we know is still very much controlled by americans)
  • United Nations / World Bank are global organizations (now that is just BS, if we see the UN with its veto powers …. its useless. World bank apparently is another story all together)

Those were some of the more objective visible things what i feel are *not working* or working for the benefit if very few. To fix all this will require a lot of work from all quarters of the Earth (especially the super rich developed nations who just messed up their gambling business … read investment banks). Anyways more capitalistic world views on the other side.

CodeIgniter + nginx : Facebook application

This is a basic tutorial on how to get CodeIgniter facebook application on nginx (with the gotchas). The nginx configuration would be like the following

1
2
3
4
5
6
7
8
9
10
11
12
13
server {
        listen 80;
        server_name blah.com;
        location ~ /index.php/ {
                root           /home/production/blah;
                index  index.html index.htm index.php;
                include        conf/fcgi.conf;
                fastcgi_param  SCRIPT_FILENAME /home/production/fb_apps/quickdate/index.php;
                fastcgi_pass   127.0.0.1:9000;
        }
        access_log      /usr/local/nginx/logs/blah.access_log;
        error_log       /usr/local/nginx/logs/blah.error_log;
    }

The critical line is the fastcgi_params parameter, that changes the whole game. In the code Igniter application you need to add the following file in [app]/system/application/libraries/FB_controller.php

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
<?php
 
class FB_Controller extends Controller {
 
        // Facebook application key
        var $API_KEY = 'your api key';
 
        var $facebook;
        var $uid;
 
        /*
         * Custom Controller constructor.
         * Adds Facebook support.
         *
         */
        function FB_Controller() {
 
                parent::Controller();
 
                // Authentication key
                $secret = 'your secret key';
 
                // Prevent the 'Undefined index: facebook_config' notice from being thrown.
                $GLOBALS['facebook_config']['debug'] = NULL;
 
                // Create a Facebook client API object.
                $this->facebook = new Facebook($this->API_KEY, $secret);
                $this->uid = $this->facebook->require_login();
        }
}
?>

There are some significant changes in the configuration which is at [app]/system/application/config/config.php

1
2
3
$config['enable_query_strings'] = TRUE;
$config['subclass_prefix'] = 'FB_';
$config['uri_protocol'] = "REQUEST_URI";

Now in the application you should write controllers extending the above defined class , for example I modified the welcome controller.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
 
class Welcome extends FB_Controller {
        function Welcome() {
 
                parent::FB_Controller();
 
                // Check if the application has been added by the user
                try {
                        if (!$this->facebook->api_client->Users_isAppUser()) {
                                $this->facebook->redirect($this->facebook->get_add_url());
                                return;
                        }
                }
                catch (Exception $x) {
                        // Clear cookies for your application and redirect them to a login prompt
                        $this->facebook->expire_session();
                        $facebook->redirect($this->facebook->get_login_url());
                }
        }
        function index() {
        }
}

Fire this up and see it all running smoothly, this is basically compiled from all kinds of forum over the internet. Thought it will be useful for someone. In case of any issues contact me at me@dipankar.name.

IIT versus everyone

“Life’s fair if you don’t compare”

The basis of article is the above quote which has no known author. Yesterday, i was sitting with my friends and i was the only IITian sitting there. When these guys started talking about their university life, well I started to realize that the golden years of fun for them were the toughest years for me and my batch. To start this all out, lets go back to the end of 12th and then college life.

Most of the other university kids start their life in college looking out for opportunities to explore life and have fun, the consequences are very much secondary. But in IIT, to tell you the honest truth there is a lot at stake if you mess it up. Take for example attendance … IITs are very very strict (at least my dept. was) compared to Delhi University or for that matter any other. A lot of people have had a DISCO (disciplinary committee) sitting on them for reasons that could be argued as trivial / juvenile mistakes. Basically, fun is not something for the light hearted in our premier institutes.

Now why am i writing about this :D … the point i want to make is that the 4 years of slogging results in a conception of the world which is extremely utilitarian and to some extent makes you a cynic. Well, we all come out relatively rich in the process, but i do think in an evolving economy like ours making money is not as impossible as it used to be. I am trying here not to be a cynic :P and have fun writing this stuff … IIT has taught me a lot about people , thinking, and life in general, but maybe just maybe i missed out on all the fun my friends were having. As they say time is money, and i guess most IITians have it built in when they go into the battlefield of life.

I had to compare … even if it is an apple / oranges comparison … feel free to flame me :D.

Django : Optimizations within the platform

In my experience with both rails and django, i would have to admit that a lot of things need to be improved at the core of these platforms so that developers can truly deploy a really fast production site. Let talk about what we did at kwippy to make it that much more faster than the default Django setup.

  • Use memcached properly : The trick in getting speed is to cache all logged out pages and heavy caching of the user objects when logged in. For example we recently got our sessions into the memcached cloud to see a good speed jump.
  • Database structuring : Django does a lot of joins and magic in it ORM, and has a built in caching layer. But the problem is that we developers structure our tables to our percieved needs … not necessarily for the way the ORM works. One way is to start writing custom SQL inside your views, another is to understand the ORM better. Your choice :).
  • Database connection pooling : It is pretty shocking to realize that Django does not do connection pooling, I have used DButils connection pooling for our needs. But IMHO it should be a default thing inside the application platform.
  • SMTP is slow : Imagine the user filling up a form which is emailed to you, and your SMTP is down. There is a good chance that you will lose that data and the application will give a 500 :). To alleviate that i have created a command queue where emails are not sent within the application and a daemon is doing all the dirty work. I will put it all out in the market :), so that you guys can make you site that much more faster/robust.
  • Pagination : To be honest, i still do not like django pagination. The problem was that it will getting all the objects and as the database is on a separate machine a lot of data was being transferred over the network. So i created my custom pagination which was faster than ObjectPaginator or Paginator.

Well there are all i could think of right now. Obviously there are some other optimizations that i keep doing …. and will keep writing about. Till the next time, feel free to contact me about these optimizations at me@dipankar.name.

Django : using a seperate memcached cloud for sessions

When you are using a platform like django you realise how slow sessions can get when you are using the database as a backend. The problem of using a memory cache like memcached is the fact that when you restart the server to refresh the cache or remove stale objects, the problem is that you lose your sessions data and a lot of people using your site get logged out. The only solution to this problem is to use 2 memcached instances , one for your regular python objects and another for your sessions objects … this is not a default feature in Django. So here is the solution to this particular problem.

In your project directory create the following files, the first file is basically a copy of a core django file (contrib/sessions/backends/cache.py) and the second is a file where the class gets initialized (its not necessary , but a good example).

/session_backend.py

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
from django.contrib.sessions.backends.base import SessionBase, CreateError
from kwippyproject.session_cache import cache
 
class SessionStore(SessionBase):
    """
    A cache-based session store.
    """
    def __init__(self, session_key=None):
        self._cache = cache
        super(SessionStore, self).__init__(session_key)
 
    def load(self):
        session_data = self._cache.get(self.session_key)
        if session_data is not None:
            return session_data
        self.create()
        return {}
 
    def create(self):
        # Because a cache can fail silently (e.g. memcache), we don't know if
        # we are failing to create a new session because of a key collision or
        # because the cache is missing. So we try for a (large) number of times
        # and then raise an exception. That's the risk you shoulder if using
        # cache backing.
        for i in xrange(10000):
            self.session_key = self._get_new_session_key()
            try:
                self.save(must_create=True)
            except CreateError:
                continue
            self.modified = True
            return
        raise RuntimeError("Unable to create a new session key.")
 
    def save(self, must_create=False):
        if must_create:
            func = self._cache.add
        else:
            func = self._cache.set
        result = func(self.session_key, self._get_session(no_load=must_create),
                self.get_expiry_age())
        if must_create and not result:
            raise CreateError
 
    def exists(self, session_key):
        if self._cache.get(session_key):
            return True
        return False
 
    def delete(self, session_key=None):
        if session_key is None:
            if self._session_key is None:
                return
            session_key = self._session_key
        self._cache.delete(session_key)
/session_cache.py

1
2
3
4
5
6
from django.core.cache.backends.memcached import CacheClass
from django.conf import settings
 
scheme, rest = settings.SESSION_CACHE.split(':', 1)
host = rest[2:-1]
cache = CacheClass(host,{})

In your settings file you need to make the following changes

/settings.py

1
2
SESSION_ENGINE = "kwippyproject.session_backend"
SESSION_CACHE = 'memcached://127.0.0.1:11200/'

Restart, start a memcached server on port 11200 and see your site becoming that much more faster :). Keep coding and in any problems with this approach feel free to mail me on me@dipankar.name.

Subscribe:

Application developer, web analyst and partly, system administra tor who likes working on new technologies and implementation challenges. Particularly interested in startups, open source an d scalable technologies.

Contact me at me@dipankar.name. Subscribe!

Search:

Sponsored links:

RSS Twitter / dipankarsarkar

Tags

I recommend:

  • Recommandation 1
  • Recommandation 2
  • Recommandation 2
  • Recommandation 2

Social networks:

  • Twitter
  • Linkedin
  • Youtube
  • Flickr