Sunday, February 17, 2013

Enable NTFS write support on Mac OS X

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

That is really annoying, isin't it? I mean, you plug-in your Disk into your mac, and all you know is you cannot write anything on it. Anyways, I have found an utility to enable mac to write on your NTFS Harddisk. its called ntfs-3g. Here are the steps to install it:


  • brew info fuse4x-kext
  • sudo /bin/cp -rfX /usr/local/Cellar/fuse4x-kext/0.9.2/Library/Extensions/fuse4x.kext /Library/Extensions
  • sudo chmod +s /Library/Extensions/fuse4x.kext/Support/load_fuse4x
  • mount -t fuse4x
  • sudo mv /sbin/mount_ntfs /sbin/mount_ntfs.orig
  • sudo rm /sbin/mount_ntfs
  • brew install fuse4x sshfs
  • sudo kextunload /System/Library/Extensions/fuse4x.kext/
  • sudo kextload /System/Library/Extensions/fuse4x.kext/
  • brew install ntfs-3g
  • sudo ln -s /usr/local/Cellar/ntfs-3g/2012.1.15/sbin/mount_ntfs /sbin/mount_ntfs
Yes, I know I did not give much of explanation here. Thats because I doubt if this is going to useful for some one. If you are reading this and need some explanation, let me know. I ll update this post as needed. But for now. This is for my future reference.

Saturday, February 9, 2013

Install PostgreSQL on OS X using Homebrew

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

Strong advice: DO NOT use any "installers" for you development purpose. And by installers, I mean GUI based wizards / drag and drop ones. always rely on command-line. If you are not using Homebrew yet, Start using it immediately. For those who have never used it, is it like an "apt-get" for mac. Technically speaking, it is a package-manager. There is an other alternative to Homebrew called MacPorts. But I have never user MacPorts. I am happy with Homebrew. So I dont know much about MacPorts.  

So before installing through Homebrew make sure that you uninstalled the old version completely and restarted (Just to make sure there are no startup items related to postgres) your mac. Open "Activity Monitor" and ensure there are no "postgres" processes. And follow commands. If required run command "brew doctor" just to make sure that everything is OK with Homebrew.

  1. brew update
  2. brew install postgresql
  3. initdb /usr/local/var/postgres
  4. cp /usr/local/Cellar/postgresql/(your-pg-version)/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
  5. launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  6. pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Note: When you use Homebrew to install Postgresql, It does not create a "postgres" user for you. If you really need it, you can create one yourself. But normally the user that you are currently logged in as will  have super-user privileges. It comes in handy during development.


Sunday, February 3, 2013

iTerm2 / Bash Line Wrap Bug

UPDATE: Apologies. Looks like this is not a bug. It is an expected behavior. And I failed to read through the documentation properly. Thanks to Jorge for pointing this out. Here is what he replied as you can see in one of the comments below:


    I filed a bug to the iTerm people, and they quickly replied. It turns out is not a bug, just a bash idiosyncrasy. The iTerm2 developers pointed me to this link, where it is clear that the solution is to modify PS1, and surround the non-printing chars between '\[' and '\]', to tell the shell "everything between these escaped square brackets, including the brackets themselves, is a non-printing character.

    I have been using iTerm2 for about some 8 months now. It is the tool that I use for most of my day's work. I kind of dislike IDEs and GUIs. Honestly, I feel that they are sluggish. I love to work on terminal with Vim / Emacs. All these days, I have been ignoring a bug. A bug that is caused by the line that is longer than the width of terminal. And this bug is caused only when you customize the color of your command prompt (PS1). You can have a look at my .bash_profile file. in the first line, I have customized my PS1 as follows:

    `export PS1="\e[1;36m\W\e[m \e[1;35m>\e[m "`

    Lately, I had to break up long lines using `\`. But I sooner found that this was messing up the history too. When you scroll through the history, you can see some weird stuffs happening. Got me really annoyed. Having been annoyed enough, I decided to fix this. I went to iTerm2's GitHub repo. I checked the issue list, there was no issue like that. So I forked the repo and tried running through the source code myself and fix this bug. I went through the code, and there was nothing that I could really find to fix this. Then I had to rely on my old friends Google and StackOverflow. After some lame results, I landed on a SO page where this bug was explained. Looks like it was not an issue with iTerm, but with bash itself. You see, the bash counts the prompt symbols to determine the total line length and breaks the line according to width of terminal and line width. When you set a color \e[1;36m\e[m \e[1;35m[m which is equivalent to blue and pink, bash tends to treat them printable characters and cont it along with the command prompt. While the truth is it does not add length to command prompt, it just adds up color which is not countable. This messes up the buffer and causes the line wrap bug. So I have temporarily changed my prompt to just

    `export PS1=" \W > "`

without any color. I ll wait for some time. If no one else fixes this, I ll have to do it myself. I really need the prompt color. Because, for me, it is a visual distinction between the consecutive commands. I will post my update if I ever fix it. So for now, if you experience this bug, just delete all the colors. And send me a mail, I ll reply you If I happen to fix this.

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

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.