Dec 31, 2014

How to use request.PUT or request.DELETE in Django

Those of you who use Django might know that using request.PUT or request.DELETE on Django doesn't work. This is because Django doesn't construct dictionaries for such "verbs", and you need to work with request.raw_post_data or request.body and parse it to get your data (Go ahead, give it a try, while I have a cookie!)

If you are creating a simple REST API, you are not going to have a good time unless you are working with a framework.

Wouldn't it be nice if you could use request.PUT just like the dicts request.POST and request.GET After finally searching online, I have stumbled upon a way to do just that.

You can find the code on BitBucket.

    if request.method == "PUT":
        if hasattr(request, '_post'):
            del request._post
            del request._files
            request.method = "POST"
            request.method = "PUT"
        except AttributeError:
            request.META['REQUEST_METHOD'] = 'POST'
            request.META['REQUEST_METHOD'] = 'PUT'
        request.PUT = request.POST

What you do here is simply change the request method back to POST, reload the variables and rename the request method and request.POST dictionary. A nice hack to get your job done.

Liked this post? Have any suggestions? Just let me know. Feel free to comment below!

Dec 11, 2014

Zico, the ISL and ATK

Zico might have been a great footballer, but the White Pele is perhaps one of the best players not to have won a World Cup ever. Maybe that's why he considers qualifying to the semi finals of the ISL as one of the greatest moments of his career. It's commendable how he has engineered the uphill task after a poor start by FC Goa to the tournament.

The moment I entered the Salt Lake Stadium, I knew the crowd wasn't going to let Zico go away with a victory, a result that would eliminate the home team Atletico de Kolkata out of the tournament. As the starting XI was being announced, the stadium cheered every name. The presence of 36 year old marquee signing Luis Garcia on the bench, raised doubts on his fitness, but Kolkata seemed to go with whatever they had.

Dec 10, 2014

And I'm back!

It's been a long time. A very long time indeed...

It's been so long that the once familiar Blogger interface seems alien to me. Due to my sabbatical, I must admit that I had thoughts of leaving this blog altogether and moving on to a new one, but recent events have convinced me otherwise.

Random people have asked me why I have stopped blogging. I had no idea so many people read this blog - and that they would miss my posts. But the one thing that wanted me to start writing again on this blog was during a job interview.

I had cleared the first level of interviews in a company, and the moment I walked into the room, one of the interviewers asked me - "How is your blog?" (The fact that I have neglected this blog in recent times might have contributed to me not making it to the said company.)

Apart from my readers reaching out to me in real life, I am going to start writing again because I am fresh out of the placement season at IIT Roorkee - a place where students are only as good as the packages they bag. I have a lot of things in mind - about the placement process, the selection procedure and a lot of other things - and I am going to share them on this blog soon (albeit in a safe way- to make sure I don't get in trouble with certain people).

To the readers, I would like to sincerely apologize because I have been away for a long time due to my own selfish reasons (the freelancing pays well, you know!) But watch this space, I am going to share my experience soon.

Liked this post? Have any suggestions? Just let me know. Feel free to comment below!

May 3, 2014

Swelling in your Galaxy S4's battery- here's how to get it replaced in India

Although the S5 is out, Samsung is probably still working hard to get the S4 issues fixed. After a rather late upgrade to Android Kit Kat, you must wonder how important this ex-flagship device is for Samsung. I usually write on cribbing issues, but here's one about a good thing- how I got my Galaxy S4 battery replaced in India.

The battery swelling issue has been well known in case of the S4 and Samsung has acknowledged this issue. In fact, it has been giving free replacements in some parts of Europe. Why not India then? Perhaps, the customers are spoilt kids who couldn't care less for a few thousand bucks?

Apr 1, 2014

Create your own basic lightbox with CSS and jQuery

If you Google "lightbox", you would be greeted by hundreds of plugins, each with its own speciality. Quite often, these plugins are very heavy and contain a lot of functionality that you would probably not require. In most cases, your requirements are very basic and you wonder if it's practical to use a heavy plugin to get the job done. In this tutorial, we will talk about creating your own basic lightbox plugin. Why carry the whole Swiss knife when you just need a pair of scissors?
The lightbox that we are about to create is inspired by the look of the lightbox in this tutorial by Script Tutorials. However, we will discuss it in such a way that enables you to re-use the code in further projects.

Mar 1, 2014

And they lived happily ever after... Really?

“And they lived happily ever after...”- takes me straight back to my childhood. Mamma by the side of your bed telling you how, against all odds, the princess was rescued; the good ol’ days. There was nothing to worry about, because deep down, I knew that everything would turn out to be all right! However, as the years passed by, I realized that the world was cruel- the thought of a happy “ending” is just a fluke. In fact, there’s no ending, and “ever after” is just a cliche used in fictional works!

Jan 31, 2014

10 Common Mistakes by WordPress Beginners

To err is human and to forgive divine.’ Committing mistakes is not a crime, however, not learning from your mistakes definitely is. If you are new to the world of WordPress, it might be intriguing for you to set everything up and your primary focus would be to get things running. In that process, there are quite a few things that you might ignore which would come back to haunt you in the long run. Here is a list of such common mistakes that beginners commit, which you must avoid at all costs.

Jan 18, 2014

The Dream

Five minutes left for the final whistle. Trailing by a goal in the Champions League Final in Munich, Torres is brought on for Kalou. The commentator promptly reminds us for the 645th time that for all the minutes Drogba and Torres have played together in the pitch for Chelsea, neither of them have scored. Torres manages to win a corner though, Mata approaches the corner flag to take it. As the ball curls in, Drogba gets free from his marker and heads the ball. Neuer gets to the ball, but it still goes in...

... and then the goddamn alarm goes off!