Mac OS: netstat and pid

I am a Linux user by large. Lately I migrated to Mac as it worked better for me. (...and they look beautiful!) Although, I found from @hyfather that there is significant difference between Mac based utilities vs Linux-based. This difference exists as Linux has GNU coreutils and Mac has BSD based.

VS

Many switches are different, output is different and it is very frustrating to experienced users.

I ran into netstat command recently. I needed to find out pid of memcached server on my mac. Spend few mins but no luck. Mac based netstat command won't understand -p switch. Aaargh! I had to use lsof to get my job done.

Here is how I did it -

sudo lsof -i -P|grep memcache

Worked great!

Posted in Tips | Tagged , , , | 1 Comment

How to display local time to users in browser?

In 7 years web programming career, I never met this problem before. In a recent project we needed to show browsers local time on the page. Few folks have solutions to do this server side but none of them work reliably. Why?

  • Browsers don't send any timezone information
  • You can send offset in headers / parameters but its only reliable for dynamic requests

After trying a failing multiple times, I resorted to a browser-based JavaScript solution. This works great!

  1. Convert all the server side timestamps to UTC. This makes server side code life way easier!
  2. Send the dates to browser in iso8601 format which JavaScript can parse easily.
  3. I used very good jQuery library (Localtime)  to convert iso8601 formatted dates to format required by application.

You can also tag your date spans with a special class. This way you can convert all timestamps to different formats unobtrusively. Very simple and elegant solution.

Posted in Developer, Programming | Tagged | Leave a comment

Ruby: Insecure World Writable Directory

I keep getting following warning lately on my mac.

ruby warning: Insecure world writable dir /usr/local/bin, mode 040777

Little research and I found, Ruby warns you about any world writeable directory in your PATH. Not only writeable directories but parents as well.

Fix is super quick.

chmod o-w /usr/local/bin

You can replace /usr/local/bin with any directory which ruby complains about. This fixes the issue.

Posted in Developer, Tips | Tagged | 2 Comments

Save a read-only file in VIM using sudo

Have you opened a read-only file and modified it but couldn't save? Not anymore, I found a quick tip which allows VIM users to save the file as 'sudo' even if you didn't use 'sudo' at the time of opening.
Create a shorthand mapping in VIM as follows:

cmap w!! %!sudo tee > /dev/null %

You can save this to your ~/.vimrc file to persist it.

Now every time you want to override the read-only status and save changes as sudo, just hit 'w!!' and you'll be good.

Love the power of VIM!

Posted in Tips | Tagged , | 1 Comment

Getting Things Done

It is not easy! I have struggled with achieving higher productivity while working on my personal projects or working from home. I kept asking why? Obvious answers were -

  • Lots of distractions - @home usually my PS3 is in my sight, there is no pair to pull me back from reading a relatively long blog post (and then catching up on xkcd).
  • Plenty of things to do - I have plenty of things to do in my new house. So my home tasks list is never-ending. That somehow gets higher priority than my personal project or gets mixed up!

Initially, my reaction to all these things was simple. I need to do better time management! Easy!

Attempt 1 - ToDo lists and Time Tracking

I decided to get a time tracking tool and then plan 10 hours for a weekend strictly for personal work. Seemed very simple and achievable.

I used following set of tools for this -

  • RescueTime - To track and improve my time spent on computer
  • Toggl - Timer for tracking time spent on work
  • Pen and Paper - To make list of tasks and track them.

How did that go?

Well, not great. I was having very high hopes from this simple system. Then I analyzed where did I go wrong?

  • I made a good list of things to do. This was just a list! I will explain why this is an issue.
  • RescueTime allowed me to understand how I spent time on computer, and nothing beyond. It improved my productivity by recovering some lost time but not much.
  • Toggl was a complete failure for this purpose. Often I just forgot to start/stop timers!

Attempt 2 - GTD

This time I decided to go better prepared and  with better tools. Yes, I know what you're thinking! You are thinking, that tools can't improve productivity loss and self-control is more important than anything else. I agree, and will add that better tools will help you to get better results. If your will power is strong and you're very disciplined, with better tools you might be able to use your time even more optimally.

This time I decided to go with -

  • Things - This is a very powerful task management application. It is very simple to use and good at managing your tasks properly. I got inspiration from Akshay Dhavle to use this tool. Expensive but great tool!
  • Pomodoro - This is a free tool for mac. For folks who want to know more about pomodoro, head over here.

How did it go?

Well I have tried this for past 3 weeks and great so far! I will keep updating about this in coming days. I achieved most of the things I planned without serious lag and I am getting better at it.

So what improved this time?

As I mentioned earlier that pen and paper to-do list was great to begin with, but it was just a list! That was the only issue with it. It told me that I have these 100 things in my pipeline and I need to do them. Well yes, but how? How should I pick a certain thing in my list and not other. Depends on how you make your list and I am sure you have a better way to manage your tasks using pen and paper. I wasn't!

Time tracking is not very useful! I tracked time and realized that I wasted time! I knew that already! It didn't push me in the right direction to do more out of my time. Pomodoro is nothing but time tracking, you might say. I felt that it was more powerful technique than just tracking time. You should carry out one task in a pomodoro sprint. So when you're starting a pomodoro sprint, you're committing yourself to finish that task in 25 minutes or less. That is a huge difference in just tracking; I spent 40 minutes on something vs I want to get this done in next 25 minutes!

First I imported (typed) all my tasks on paper into 'Things' application. Added few more tasks which were not listed on paper as well. Later, I organized my tasks in various projects and responsibilities. This built nice context around my tasks. I spent about 10 minutes for around 100 tasks to think about and put dates on them. Many tasks were immediate once. I knew it is impossible to do them. I rearranged my tasks and priorities. No false promises to self!

"Things" really helped me in getting tasks in perspective. Pomodoro really helped me in getting those tasks beyond finish line.

It helped.

Posted in Articles, Personal | 8 Comments