OO Python

Most people I have spoken to about python, do not believe in the object oriented capabilities of python. Python does not require you to always create a class like Java or C# but it is a language that is inherently object oriented. Like we say that “In Linux everything is a file”, in python, everything is an object. Even functions are objects and can be passed around. Python decorators pass around functions but that will be an article for some other time (and maybe a long one as well).

Python follows the Verb method of programming. The two ways of programming  (Verb based and Noun based) are explained beautifully here. But let me brief it for you. Suppose the task is to take out the garbage, in the verb world you would do something like this Continue Reading →

06. September 2013 by Narayana Ravikumar
Categories: Programming, python | Tags: , , , | Leave a comment

Some Little known things in Python

This article came after a long hiatus from the previous one and I would like to apologize for that. I came across many neat things in python recently and am somewhat finding it overwhelming to master them all. Every time I learn something, there is something else that completely baffles me or at least intrigues me to solve problems differently. Hopefully writing this article would be comforting of some sort. In this article I am going to document some little capabilities available to python users to help them in their day to day adventures.

Lambda Function

Python gives a powerful utility to create anonymous functions to users. These functions are not bound to any name (i.e they are anonymous, as already stated, by me :-P ). Lambda functions are apparently well built into the core of python structure and support all possible optimizations and provide good performance. Let me just start off with a example so that my rants make sense.

>>g = lambda x: x**2
>>print g(8)
64
>>print g(5)
25

Continue Reading →

10. August 2013 by Narayana Ravikumar
Categories: Programming, python | Tags: , , , | Leave a comment

Python Yield and Generators

I come across a lot gems in python. Some are easy to understand, some require more time. The best way to understand them is by working with them and using them in programs. To make the understanding stronger you can write about them. I wanted to understand the yield command better so here it is.

To understand ‘yield’ you first have to understand generators, iterables and their difference.

Iterables

Iterables are a pretty well-known concept. They are anything that you can iterate on. Remember in basic C you first had to find the length and then run a ‘for’ loop to find all the elements. Iterables you can directly iterate and access all the elements. Continue Reading →

17. July 2013 by Narayana Ravikumar
Categories: Programming, python | Tags: , , , , | Leave a comment

Fun Python Packages

These definitely have to be checked out.

Mechanize

ge. It basically gives you a programmable browser. It takes care of https, cookies and all the forms. It gives you immense power to Mechanize is an awesome packado a lot of things.

Imagine you have a browser that fills all the forms for you, submits them and process the response. Imagine doing it 1000 times or hey, a million times only limited by the processing power you have. Imagine spamming comments using this, I am not saying that you should, I am only saying you can. But most comments have captcha and limit on comment flooding anyway.

But this package can helps you do some managing if desired. It helps you access resources required, have custom filtering, provide custom services etc. Things you can probably do is make a separate archive of your emails, email contacts,  alerts based on constraints etc. The most freakingly awesome thing you can do is write your own web crawler. Crawl through the web, index info, handle loops and maybe finally start your own search engine that kicks Google’s ass. Continue Reading →

12. July 2013 by Narayana Ravikumar
Categories: Programming, python, Uncategorized | Tags: , , | Leave a comment

Anime, waste of time?

I have watched a lot of anime from my childhood and continue to watch them even now. I read a lot of manga as well. If you don’t know what a manga is, this can help you. I clearly remember dragon ballz being my first anime immediately followed by naruto and a bunch of others. Now, I have watched so many, I have lost count.

 But every time I started watching an anime my parents would start to whine

  1. They are such a waste of time.
  2. Are you still a kid to watch cartoons?
  3. If you stop watching them you might do better at exams.
  4. If you watch anymore the world will stop spinning.
  5. MY feet hurt because YOU are watching anime etc.

Every time they said that, I would always feel guilty and wonder, am I really wasting my time? Will I screw up my exams? What is the mystical connection between earth’s core and watching anime? As stated by me here, I always want to learn and keep learning from everything I do. So there was one important question I asked myself, what am I learning from anime? Here are some important ones.

1. One Piece – You have to rely on your ‘nakama’ (teammate), you can’t do everything alone

One-Piece-New-World

Continue Reading →

08. July 2013 by Narayana Ravikumar
Categories: Diary, Perception | Tags: , , , , | Leave a comment

The Operating System Saga

This is a story of an individual who took one of the most dreaded course at NCSU in the Spring of 2013. This apparently insane course is called Operating Systems. The highly project oriented course at the end of which you would want to take a world tour to make up for everything you missed during the semester. It all starts in a classroom filled with 120 students, prof and TAs who have this I-know-it-all-you-guys-are-dumb look. The first sentence said by the prof “This is a tough course, hope you will have fun”. I guess her idea of fun was taking student’s minds and boiling them in a frying pan at precisely 320F with a pinch of salt. But oh well, after all the battering and ramming the 80 of us who remained rose from the ashes like a phoenix, chiseled and moulded to face any challenge thrown at us. Although, some of us who lost our minds had to vent out, by hysterically laughing through a weekend.

Spoiler Alert – This course was actually as tough as advertised. (unless you were bloody brilliant to start with)

Boasting Alert – I got an A+ in this course :P

tldr; → skip to the last paragraph.

Continue Reading →

01. July 2013 by Narayana Ravikumar
Categories: Diary, Programming | Tags: , , , , , | 11 comments

Design Thinking

I am writing this article at 1am with droopy eyes and cannot guarantee its quality. But anyway, I came across design thinking in a special topic class I took in Spring 2013 called “Visual Interfaces for Mobile Design”. This was a really different and interesting course. It had zero importance to exams and by-hearting stuff. It was an very open-ended and fun class. It was a class where the amount of things you learnt totally depended on how much you wanted to learn. The prof had a given a bunch of topics we had to do a reading assignment on, and one of them was, as the heading says “Design Thinking”.

For this I had to read a paper (that unfortunately can’t be linked here) and watch this really good TED video. I have not completely understood what design thinking actually means or how to develop it. But I feel it is very important for all us to learn what design thinking is if we want to grow as an effective developer and really enjoy what we do.

design_thinking_1

A image that somewhat explains the life cycle of design thinking.

Continue Reading →

29. June 2013 by Narayana Ravikumar
Categories: Perception | Tags: , , , | Leave a comment

Immutability

Immutability is a very important concept that most of us might not know it explicitly. An immutable object cannot be modified after it has been created. Consider the following simple python code.

var = "hello"
print var
var[1] = "6"
print var

gives an error
TypeError: 'str' object does not support item assignment

That is because ‘String’ is an immutable object it cannot be modified after creation. A compiler/interpreter stores the ‘String’ in an optimized format for easy and efficient use thus rendering them un-modifiable.

Why are immutable objects needed?

  1. A compiler/ interpreter does this to reduce complications and work efficiently.
  2. Immutable objects are inherently thread-safe
  3. Simpler to understand
  4. Offer good security

That is great, but why should I know about immutable objects?

Continue Reading →

29. June 2013 by Narayana Ravikumar
Categories: Programming | Tags: , , , , | Leave a comment

Python FTW

Python has made programming an absolute pleasure for me. I simply love coding in python. The ease of programming and the importance given to programming logic than programming syntax is an absolute delight. I first learnt python from this tutorial. It is a great website to learn python, especially for the beginners. A more advanced one can be found here. Whenever someone asks me, how is it to code in python? I always remember this xkcd comic.

python_ftw_1

According to me (among the programming languages I know), python is the only true “high” level language. I mean, if programming languages took part in “Game of Thrones” python would be on Iron Throne the whole time uncontested. Continue Reading →

28. June 2013 by Narayana Ravikumar
Categories: Programming, python | Tags: , , , | 6 comments

Stack Buffer Overflow

Stack Buffer Overflow is a very neat security vulnerability. I was fortunate enough to learn and work on it during my security course at NC State. It can be defined as an anomaly where a program overwrites the buffer allocated to it and writes into adjacent memory.

How can this be beneficial?

Well, you can potentially overwrite a return address and make it point to some malicious code. When the system returns to that address it executes the malicious code allowing an adversary to take control of your system.

Why would anyone want to do this?

Money, research, fun, your kung fu master ordered, some celestial being commanded, it could be anything.

How do you do it?

Well, to understand how to overflow a buffer you must know how stack works and for that, you must know where the stack is located. This is typical diagram of the system memory layout.

bufferOverflow_1

Continue Reading →

26. June 2013 by Narayana Ravikumar
Categories: security vulnerability | Tags: , , , , | 2 comments