Sunday, December 30, 2012

My 2012 python meme #2012pythonmeme

I have been writing production application in python for the past one year.

1. What's the coolest Python application, framework, or library you have discovered in 2012?
    MRJob - A python package that helps you write and run Hadoop Streaming jobs.

2. What new programming technique did you learn in 2012?
    I have learnt how to write highly modular and reliable code. How to do automated deployments. And how to auto-scale.

3. Which open source project did you contribute to the most in 2012? What did you do?
    Well most of my contributions were to non-python projects. But I did a very tiny contribution to cyclone.

4. Which Python blog or website did you read the most in 2012?
    Planet Python and couple of other blogs.


5. What are the top things you want to learn in 2013?
    Natural Language processing, Machine learning, Big Data in python.


6. What is the top software, application, or library you wish someone would write in 2013?
    A full stack framework that supports Hadoop and related technologies.

Want to do your own list?
here's how:copy-paste the questions and answser them in your blog.
tweet it with #2012pythonmeme hashtag

Monday, October 22, 2012

Friday, October 19, 2012

Xcode: warning: no rule to process file '$(PROJECT_DIR)/path/to/file' of type for architecture

I came across this warning.
warning: no rule to process file '$(PROJECT_DIR)/path/to/file' of type for architecture 
Silly me! I did something stupid. Looks like I have put a .h file in the list of compiled sources. The list should only have .m files. I dont know if we can put a .c file in it, but there should not be any other filetype. I fond that some developers even dragged Javascript files into the compiled sources. If you are facing the same problem, you should probably remove any non-.m files from list of compiled sources. Here is how you do it, considering you are running on Xcode4 or above.


  • Open up your project target's "Build Phases" tab. (Click on the project, then the target's name, and then on the "Build Phases" tab).
  • In the the compiled sources section, make sure that you dont have any files other than .m files.


Happy Hacking.

Tuesday, September 4, 2012

My first pull request

“A journey of a thousand miles begins with a single step.”

That single step for me, in my carrier, is learning python. A fun loving, magnificent beauty. For me, programming is like raising a baby. Initially, the baby girl doesn’t know anything. As a dad, its my responsibility to teach her what to expect, how to react & what to respond. For me, it is more than art. Its parenting. I take care of her so that, she never crashes. To ensure that she  can be fixed when someone breaks her, I should write great test cases. She is just a kid right? She is not mature enough to take care of her all by herself. So I have to make sure that she is always happy by employing some care taker who always look after her changes. Buildbot is her caretaker. When some one breaks her, buildbot will notify me where I can fix her right away.

So I was trying to get buildbot up and running. For some unknown reasons, it did not start. It just crashed. When I looked at the logs, it said that “twisted.web.errors.NoResource” was missing. Well that was weird. So I decided to go through the source-code of twisted. And “No Resource” was no where to be found. I got confused. Only then I found out that Twisted was updated to 12.2 just a few minutes ago.

There was a breaking change in it. “NoResource” has been removed. It was not there. The only thing that appeared to be similar to it was “Errors” So quickly without thinking anything else, I patched it and send a pull request.

I was happy, because it was my first contribution for a big project. Then next day when I checked my mail, I was sad. Looked like “NoResource” has been moved to “Twisted.web.Resource” package. I was dumb enough that I failed to see it. My pull request has not been accepted. It was fixed by some one else. Then I remembered something.

”I haven’t failed. I’ve just found 10,000 ways that won’t work.”

Yes, I just found one way in which I cannot submit a pull request.

“If You’ve Never Failed – You Haven’t Tried Hard Enough to Succeed”
“Success does not consist in never making blunders, but in never making the same one a second time.”

I am happy that my pull request got rejected. If a person always agrees to what you say, then you sort of never learn anything. It is only while someone disagrees you, you learn something new.

Wednesday, July 25, 2012

iOS 6 UI Interface Orientation - shouldAutorotateToInterfaceOrientation: Not Working


This post will soon be moved to here
This blog has moved to http://dhilipsiva.com/blog/
This post is outdated.

The method shouldAutorotateToInterfaceOrientation: is NOT supported in iOS 6. Its deprecated. Just in case if you are a newbie, who just stared working in cocoa, and wondering why is your view controller messed up in iOS 6 and perfect in iOS 5, just know that shouldAutorotateToInterfaceOrientation: is not supported anymore. Even though it may work well with Xcode 4 to 4.3 it will NOT work on Xcode 4.5. 

Apple provides a new method to get this thing done, in a much cleaner fashion. You use supportedInterfaceOrientations instead. It returns all of the interface orientations that the view controller supports, a mask of interface orientation values.

UIInterfaceOrientationMask Enum:


These constants are mask bits for specifying a view controller’s supported interface orientations.


Example:

Again, if you are newbie searching for an example, let me give you an example. Consider that you have to set your interface orientation to both left and right landscape orientations:

Using shouldAutorotateToInterfaceOrientation: method:



Using supportedInterfaceOrientations method:





UPDATE: This is a reply to an email which I received. Wanted to share this update.

     I am always glad to help anybody, if I have the time for it. Well from iOS 6.0, the system never asks for the supported interface orientations with the view controllers. It only asks the parent. In most of the cases, AppDelegate is always the parent. This is a line of code from the ReWire (http://www.rewireapp.com/) app that I have been working lately. I had a specific requirement. I had to set landscape mode only to VideoMeditationViewController. The rest of the video controllers should only support portrait orientation. So here is a solution:


-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    if([rwNavigationController.topViewController isMemberOfClass:[VideoMeditationViewController class]]){
        return UIInterfaceOrientationMaskLandscape;
    }
    else{
        return UIInterfaceOrientationMaskPortrait;
    }


 Yes, I know this is a hack. And I know this is not an elegant way of doing things. But trust me, this is the easiest.

Tuesday, July 24, 2012

Xcode - Could not launch app - No such file or directory Error.

This post will soon be moved to here
This blog has moved to http://dhilipsiva.com/blog/
This post is outdated.   

It has been 4 months since I have been developing for Apple (iOS). As a user, I am in love with Apple. But as a developer, I feel Apple is a crap. I mean, It treats developers like a piece of crap. I hate tools that apple provide for developers. Often buggy. I loved Microsoft from a developers perspective. Okie, to the subject now. I found this really annoying problem with Xcode and fixed it. When you run a project on Xcode, you sometimes end up with a message like this:

Could not launch app - No such file or directory

Thats really annoying. This error happens in a number of different situations. Sometime restarting the Xcode, fixes the problem. If not, follow these steps:
  1. Disconnect your device. 
  2. Delete the app from your device. 
  3. Quit xcode (Don't just simply close the window, quit it) 
  4. Delete derived data folder (~/Library/Developer/Xcode/DerivedData/-gbrvhlvwmpiobxdujegtghggrffp - or something like that) 
  5. Now start Xcode, connect device and run the project. It should work fine.
There it is.

EDIT: Weird. Even theses steps are not helping me sometimes. I dont know what is causing this problem. When everything else fails, restarting both Mac and iOS device solved the issue in some situation. And what is weirder? Some times the app just runs fine the next day, without me changing anything.  I know I am not practicing an elegant solution, but this is the only working solution I found so far. If you have any Ideas, you can mail me. I ll update this post as necessary. BTW, this is the post with most hits on my blog. 20,000 and counting! :)

Friday, June 8, 2012

What the Love?


Unfulfillable longing, and yet I wait.
Unquenchable thirst, and yet I cry.
Bottomless pit, and yet I fall.
Endless road, and yet I run.
Never-ending ladder, and yet I climb.
Ever-growing agony, and yet I laugh.
Sleepless nights, and yet I dream.
Hopeless days, and yet I love.

- DhilipSiva

Sunday, April 15, 2012

Endurance & Subtle thinking...

Endurance. Endurance. Endurance. I was having a talk with Mahesh and learnt a lot of things that day. Since from then I have been doing a lot of thinking. I have been thinking about this for some 6 or 7 days in a row now. I am constantly improving my thoughts on it. So what were we talking about? Endurance and Subtlety!

Short Version : Endurance and Subtlety are the tools that make a warrior. Without them you are just a common man.

Long Version : Let me tell a few words about "subtle thinking" first. Because in my opinion, a subtle thinking is highly coherent with Endurance. It is critical to understand some of the tiniest details to endure. Let me give you an example if you don't understand my point.

Consider a person "A" who is mentally challenged. He has no idea what he is doing, because his mind is messed-up. His appearance shows that he is not normal. He throws throws stones at everyone on road. "B" is a normal person who happens to be walking down the road.  As expected, "A" throws a stone at "B". Now, the story has two ends. (1) - "B" can UNDERSTAND that "A" is not normal person. Depending on "B"'s Character he can either step aside and go away or talk to his relatives to keep him safe. "B" endures because he understands that "A" is mentally helpless. (2) - "B" is blind enough to ignore the mental condition of "A" and he prepares himself for a fight or argument. This is where "B" is said to lost endurance due to lack of understanding. In this case, I feel pity only for "B" for being mentally helpless than "A".

Understand my point now? But it is just an obvious example! Subtle thinking involves in paying attention to tiniest details of life. It is the awesome ability to understand the most mysterious aspects of anything. If only you could pay attention to details at that level, you can endure. And endurance makes you a warrior.

The reason I am posting this today is fairly trivial. I live my life with some of the people who are unable to understand. Driven by some blind motive which is just pointless. And the motives that they have did not come out of understanding of anything. They are just motives that are embedded by some other ignorant moron. They were asked to believe without reasons. These are people who lack subtle thinking.

There was this one thing that was screwing up my head. The cast problem. It is one of the most misunderstood systems in India. So immature, so blind and so ignorant. It broke me into pieces sometimes, but it is not gonna happen ever again. Maybe I ll be writing about the cast system sometime next week. But now, I understand that these people are raised by telling lies. They believe in those lies so much blindly that they think, they will die without it. And I really really feel pity for those souls. Well the thing that confuses me is, is it appropriate to classify these people as blind or ignorant? blind is OK. But ignorant is much worse. I ll keep thinking on it.

But the point is you gotta endure to realize the truth. And you should have a subtle thinking to endure. "Truth about what?", you ask me. well the truth pretty much about everything. So what is the truth that I realized? Ok, before answering that question let me tell something, "I don't expect you to understand it, unless you have a subtle thinking". To the answer: "The truth is : Nothing is true!". If that makes sense to you, welcome to the clan. If it doesn't, you should wake-up. And it is the waking-up that requires the endurance and subtle thinking.

Tuesday, March 27, 2012

Python Decorator – A Syntactic Sugar

Python Decorator - A Syntactic Sugar

Sweet!!! And that's why python decorators are called as syntactic sugar. So what are decorators in python anyway? If you are newbie, it might confuse a lot at first. The idea is simple. To take a function, and return another function. As the name suggests, it decorates a function. Here I am trying to explain only the basic working of the decorators. I ll post a more detailed post on decorator when I find time. So lets consider a baby program to start with: to print the entered string. I think the following program do not need any explanation.

#First Example
import sys

def originalFunction(stringArg):
    print "The entered String is :"
    print stringArg

def main():
    print "Enter a String :"
    strInput = sys.stdin.readline()
    originalFunction(strInput)

if __name__ == "__main__":
    main()

The function does not do much. It just prints the string you entered in the console. The output looks some what like this:

Enter a String :
dhilipsiva
The entered String is :
dhilipsiva

well, that was not so hard. Having done that, now lets dive into decorator and apply it to the first example. As I already said, a decorator takes a function and return another function. A decorator is denoted by a '@' symbol in its beginning. Using the first example, lets consider we have to use a decorator '@CAPITALIZED' which alters the 'originalFunction' so that it prints the capitalized version of the passed string. It is simply done by adding the '@CAPITALIZED' statement just before the declaration of the 'originalFunction'.

@CAPITALIZED
originalFunction():
    ...
which is equivalent to
originalFunction = CAPITALIZED(originalFunction)

An important thing that few newbies might mistake is that '@CAPITALIZED' is some sort of built-in special keyword or has some special meaning. Either ways it is NOT true. It is just a function name. The function that you are going to define. The decorator function. you can keep it anyway you want just like a normal function. I like to be in that way because, it tells exactly what the decorator does. So, let go-a-head and implement it.

import sys
def CAPITALIZED(origFunc):
    def modifiedFunction(strArg):
        origFunc(strArg.upper())
        print "This line is appended from modifiedFunction"
    return modifiedFunction

@CAPITALIZED
def originalFunction(stringArg):
    print "The entered String is :"
    print stringArg

def main():
    print "Enter a String : "
    strInput = sys.stdin.readline()
    originalFunction(strInput)
    

if __name__ == "__main__":
    main()

in the above example, the 'originalFunction' is passed as argument to the 'origFunc' and 'stringArg' is passed on to the 'strArg' in the 'CAPITALIZED'. The decorator returns the 'modifiedFunction' to the 'originalFunction'. And now the originalFunction is modified to print the uppercase-d letters of entered string. the output goes like this:

Enter a String : 
dhilipsiva
The entered String is :
DHILIPSIVA
This line is appended from modifiedFunction
More detailed explanation on decorator is coming soon. Comments and corrections are welcomed.

Sunday, February 19, 2012

Plugin - Architecture : Programming Using Python [Tutorial]


This post will soon be moved to here
This blog has moved to http://dhilipsiva.com/blog/
This post is outdated.

Python!!! She, is a beauty. I have been in love with her lately. At work, I was asked to write an application that supports a plugin architecture. After 4 days of mind-screwing thinking,  I came up with a model that supports plugin architecture. I honestly don't know if this is the efficient way. But, it works. So here is a tutorial for you. This is just a quick tutorial.

Consider an example : you need to write a program that gets a string input from console and perfoms a case-swap and returns back to you. So let us code three plugins for that. First plugin is to get a value from the console, then to swap case and the last plugin to print the result. Therefore let us divide the components into 5 parts.

  1. A Class File : To hold all the data that are shared by the plugins at run-time
  2. Plugin 1 : To get a string from console 
  3. Plugin 2 : To Swap Cases
  4. Plugin 3 : To print the result 
  5. The Main Program

Implementation:

1. You need a class file to hold all the data that are share by the plugins and the main program. so lets deal with that file first. Lets call this file as AppData.py

class AppDataClass:
 global ipString
 global opString

2. The First Plugin : ReadInput.py
from AppData import AppDataClass
def init():
 AppDataClass.ipString = str(raw_input("EnTeR a StRiNg : "))

3. The next plugin : SwapCase.py
from AppData import AppDataClass
def init():
 AppDataClass.opString = AppDataClass.ipString.swapcase()

4.The Final Plugin : PrintOutput.py
from AppData import AppDataClass
def init():
 print AppDataClass.ipString.swapcase()

5. the main program : PluginExample.py
import imp
from AppData import AppDataClass

def main():

 AppDataClass.ipString = ''
 AppDataClass.opString = ''
 ModuleNameList = ['ReadInput','SwapCase','PrintOutput']
 
 for ModuleName in ModuleNameList:
  mFile, mPath, mDescription = imp.find_module(ModuleName,['PLUGINS/'])
  mObject = imp.load_module(ModuleName, mFile, mPath, mDescription)
  mObject.init()
  
    
if __name__ == '__main__':
 main()

Points to ponder :

I have used init() method as an entry point to all the plugins above. So that when we import modules, we know which is the entrypoint of the plugin.

Sunday, February 12, 2012

Stories that helped me grow


There are only a handful of people, with whom I shared this story before. Now, I wanted to share this with the whole world. This story is about nothing but some personal thoughts, which I would love to share with the world. I just want to share 4 small stories. Nothing more, nothing less!

The first story is about - me as a coward.
I hope you all know ‘Valley of death’, a poem, written by Tennyson. Goes something like, "Forward the Light Brigade, charge for the guns he said" and "How can their glory fade?". my favorite stanza in the poem is "Not tho' the soldiers knew, Someone had blunder'd" – The soldiers knew that they are about to die. But not one soldier asked any questions. They just did it and they just died. Against the fact that they are going to die, they had courage to follow their leader’s order. That’s bravery and that’s an Honor. And this poem is beautifully portrayed in the film, ‘The Blind Side’. I just totally fell in love with that film. This created a strong impression in my mind, during my 8th standard schooling. This created an impression that I was a coward. Because, I never listened to my teachers or elders. But, something extraordinary happened last April. It is only from that time, I gained the courage to listen to my elders.

The second story is about - me as a waste paper.
Nothing about me was normal. I learnt everything in a hard way. I fall hard, crashing into core of earth, but always had gathered enough strength to stand quickly back again. I always made a lot of mistakes. and I was happy about it. Because, to make many mistakes, you must have courage to try new things out. I learned from my mistakes. That gave me experience, a lot of experience. Hacking was my favorite. I used to hack a lot of stuffs. Radios, simple mechanical items, simple electrical items, etc. Due to my trail and error type of learning and I never listened to what others said, It always took a lot of time understand things. But I think I understood it clearly, than everyone else. But that was not the case. "If you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid", Well said by the greatest superhero of all times, Mr. Albert Einstein. And I believed that I was stupid because, I always failed in exams. No one considered me. So really felt like a waste paper who was useless for anything. But, my grandpa is a great man. And my uncle is also a great man. Because these were the people who protected me, and stood by my side up until now. I am very thankful to them. Things changed when I joined High School. Because, my trial & error type learning helped me understand writing program. Writing program was like raising my own child. Teaching it what to do. Teaching it how to behave. Taking care that it would survive the task at hand and successfully completes it. It was phenomenal. It was awesome. I was able to write programs even the ones which my teachers felt as difficult. I was able to write programs at an amazing speed than others. My classmates came rushing to me to ask for doubts. I heard my teachers saying they put extra effort in preparing, as I was sitting in class. Not just computer, I was dominating math class, too. Because it was always me who gave answers. As I entered College, I defied just about everything. I felt powerful. For 3 years, I stopped learning because I was under illusion that I know everything. But it all changed when from last April. From April, I am starting over, again.

The third story is about - me as my roll models.
I was raised under very different situation. I hated TV. But I loved to watch discovery channel, Nat-Geo and very few cartoons. I spent most of my childhood thinking. Thinking why the things are in the way that they are. Questioning myself a lot. Hunting answers. Exploring jungle. Exploring bird nests. Exploring animal behaviors. Hacking something. Mostly alone all the times. I felt awesome being me. Its me and my world. I listen to story that my grandpa tells. My Great Great Grand mother ( i.e., Grandmother’s Grandmother was alive when I was born. She used to tell Ramayana n Mahabharata. I loved 2 persons very much. Hanuman and Karna. They are my roll models. Other than that, General Iero and Lord-voldemort also are also my roll models. I love hanuman because he was an unmatched and unparalleled student of Surya Bahvan (The Sun-God). He learns everything at a blazing fast. Undefeatable. And my personal opinion is that he has an awesome leadership quality. Because, even though he was powerful enough to beat a whole army, single handed, he took Ram as his leader and stood by his side. It is a very wonderful quality . Without hanuman, Ram would have died the very moment when he went to battlefield. In fact, he would not have gone even to the battlefield without hanuman. And need I say about karna ? He is an awesome fellow. I just wrote a blog about him last week. Click Here you wish to read it. So I personally hate Krishna a little. He was responsible for karna’s death. So I hate him a little.

The fourth story is about – magic that happened last April.
It has been a fantastic journey last six months . I have been redefining me. If you had met me before April, you would have kicked me out of office . Now it’s completely new me. What happened 6 moths completely redefined me . April was peek of my atrocities. I felt powerful than ever. That took my ego to skies. But as college got over, I realized what I have become . I lost joy in what I was doing, and I enjoyed only when others spoke highly of me. I hated what I loved, if it didn’t make me feel special. I have become the stupid that I wished I should never become. I had 34 backlogs in total. No one hired me. Everybody rejected me, as soon as they saw my marks. Again, learnt my lesson in a hard way. The heaviness of being powerful is replaced by lightness of being nothing. I started everything over again. I feared a lot. But things are getting straight now.

Saturday, February 4, 2012

Karna was not defeated, but betrayed!

Do you think that Karna died because of the arrow that was launched by Arjuna? What happened to karna was a betrayal. That should not have happened to such a generous, skillful and courageous warrior. Karna was actually betrayed. Not once, not twice, but 4 times. How?, This is how:
  1. In the first place, his mom betrayed him. Kunthi, his mother, was stupid enough to “experiment” a boon that was granted to her. The sun-god magically appears, as kunthi wished, and blesses her with Arjuna (with kavasa & kundala, of course). Kuthi then decides to leave him float along the sacred river Ganga.
  2. This one also goes to Kunthi. She requests karna for 2 boons.
    • Hand over his kavasa & kundala
    • And to use the bramahastira only once. That’s not fair, by any means.
  3. The third was by lord Krishna. The big guy lowers height of the surface of earth by stamping on it, and thereby saving Arjuna who is eventually gonna be a tool to kill karna. Well, that’s not warfare. I mean, shifting the position of the earth is by no means, warfare.
  4. This is again by lord Krishna. Even after shot by arjuna’s arrow, karna does not die. His deeds have been saving him. But lord Krishna disguises as a begger and begs for his karma that was accumulated for his good deeds. And Karna even does that.
  5. In addition to these things, karna also gets lots of curses for his guru, a Brahmin, the boomadevi, and a hadful of few others. So, what I see is not an arrow that killed him. But curses of those people and 4 highly damaging betrayal by both his mom and a god. It took this much of betrayals to bring down a warrior. So do you still think that karna was defeated? Think again…