Vacation Of Code

Vacation Of Code

This all started when pingou gave me the opportunity to write a utility which helps to user to edit comment on pagure.Now for those who don’t know what pagure is , so pagure is open source equivalent of Github, to be precise :

Pagure is a light-weight git-centered forge based on pygit2. Currently, Pagure offers a web-interface for git repositories, a ticket system and possibilities to create new projects, fork existing ones and create/merge pull-requests across or within projects.

So the utility that was allotted to me was an edit button that privilege the owner of the comment to modify the comment on the pull request. That sounds really simple but writing the whole code and modifying others code are two different things.

I finally started exploring Flask and its feature so Flask is framework  that helps you write servers , Server as the name suggest is use to serve request.I had a brief idea about the type of request but never got the chance to explore it.

There are many types of request that help the client and server to talk to each other  famous ones are POST and GET.

The GET method

The GET method is the method used by the browser to ask the server to send back a given resource: “Hey server, I want to get this resource.” In this case, the browser sends an empty body. Because the body is empty, if a form is sent using this method, the data sent to the server is appended to the URL.

The POST method

The POST method is a little different. It’s the method the browser sends the server to ask for a response that takes into account the data provided in the body of the HTTP request: “Hey server, take a look at this data and send me back an appropriate result.” If a form is sent using this method, the data is appended to the body of the HTTP request.

Source: MDN

So in first attempt I wrote a shabby code and somehow make it work , but as I told it was really shabby so pingou and subho told me to use hidden form technique which is used to trigger certain functions without actually making the user know what is going on . It is more of a hack to get things done your way.The problem I faced was delete comment and edit comment use the same form to send request so both have the same end point hence inside the function that deletes comment I devised a way to distinguish how to differentiate when to edit comment and when to delete it.

The algorithm was simple get comment id , get new comment , replace the old comment by new one and make entry in the database.The code snippet that really helped me to understand things to a new depth was:

Example

Consider the following form:

<form action="http://foo.com" method="get">
  <input name="say" value="Hi">
  <input name="to" value="Mom">
  <button>Send my greetings</button>
</form>
With the GET method, the HTTP request looks like this:
GET /?say=Hi&to=Mom
HTTP/1.1 Host: foo.com
Example

Consider this form (the same one as above):

<form action="http://foo.com" method="post">
  <input name="say" value="Hi">
  <input name="to" value="Mom">
  <button>Send my greetings</button>
</form>

When sent using the POST method, the HTTP request looks like this:

POST / HTTP/1.1
Host: foo.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 13

say=Hi&to=Mom
 My Pull request is still under consideration so you can actually check what I did in pagure. Do let me know what you think about it.
Advertisements

PYCON INDIA 2015

PYCON INDIA 2015

Before anything I want to thank Viggy for introducing me to Pycon , it’s been amazing experience attending it. Now Pycon.

Day 0

21951676651_9155d05fdd

This year Pycon India tried to conduct DevSprint and it was amazing. I got SymPy to work with and I really enjoyed although i wasn’t able to close and issue for them but I learnt a lot. Met these amazing talented lot of SymPy contributors blessed coders for sure. This day I also saw faces behind those “Alphanumeric Nicks” on IRC. Meeting THE RED HAT guy Kushal was an awestruck experience. I met different people form different regions.I was hanging around with the volunteers and the candidate became a volunteer to one of the biggest volunteer driven event. At the end we went for DGPLUG dinner and our virtual group actually came face to face with each other.

DAY 1

Since I was volunteering so all of us were given different responsibilities. That days keynote was given by Dr. Ajith Kumar and it was flawlessly beautiful , he conveys different thought with small anecdotes , some of them were Powerless Pointless Presentation, “inertia” of our education system and an indirect hint on MS products. After that I attended many talks and also volunteered for the event I actually came know about different libraries. The day was high on learning and meeting new people. The day ended with Vijay sir taking us out for volunteer’s treat which was an awesome gesture from Pycon India team. Ohh I forgot to mention I gave a lightning talk on Summer Training done by DGPLUG that was hell of an experience and being a part of the ‘EPIC’ staircase meet of DGPLUG was just an icing on the cake. I met Shakthi Sir , I have been reading his blogs and his books meeting him in life was a real pleasure.

DAY 2

This day was last day for Pycon and I cannot believe that it’s going to end, it’s  the same feeling which you get when you go back to school form a long vacation. Bidding farewell to new friends was really tough, I really wanted those people to be here always for the first time my ‘geeky’ jokes were appreciated and I had like minded people with me.And reflecting my mood was Bangalore’s rain, it poured heavily that day.I left the conference hall with a heavy heart but with a hope to meet those people again.