Blog

$ less blog.txt
This page is still kind of buggy with the pagination and format. If you prefer, see an archive of all of my blog posts.

Debugging Address already in use errors

2019-07-31

All too frequent an occurrence in the development lifecycle is doing some work, closing up your laptop/suspending the machine, and coming back to your work hours or days later.

As you try to start up the local webserver or API server, you get cryptic error messages like the following:

  • Address already in use
  • Another process is already listening on port
  • Port xyzw is currently used by another application
  • OSError: [Errno 98] Address already in use
  • self.socket.bind(self.server_address) blah blah blah blah

And after checking all of your open terminal windows, that you have not in fact any running or killable-processes…

At this point, the n00b naive way to fix this problem is to simply restart your entire machine. To be fair, this technique works almost all of the time, but kills productivity, and forces you to save work-in-progress that’s not at a good stopping point, or worse, accidentally restart without saving your progress.

But, there is a better way.

Let me introduce you to a command:

netstat -tulpn

This command will print out the bound network ports on your machine, and which processes and process ids are running them. To free up the port to be used by your development server once again, simply kill PID, where PID is the process ID.

Now, how to remember this command? I haven’t figured that out yet, nor have I thought of an alias I want to save it to, that is just as memorable. The arguments almost spell out “tulip”–like the flower, except missing the i, and you just add an n to it. Maybe a mnemonic like, “If you fix your network address port in use issue, you will smell the essence of n tulips”?

Whatever you do, netstat -tulpn is now a friend and welcome companion in my software toolbox.

Debugging like a Boss with Slack

2019-07-11

Edit: This article also got published on the GoodAudience Blog.

I’ve been using println debugging since forever. It’s the best! It’s minimal, is the least surprising form of debugging, and allows you to set-it-and-forget it. I’ve also used interactive debuggers before, but when println debugging techniques are used effectively, I’d argue that step-through interactive debuggers are not necessary at all, and actually slow you down.

For years now, I’ve been using an evolved form of println debugging, which I affectionately call “Slack debugging,” and I’ve written various manifestations of utility/helper functions called slack_debug over the years.

This has been a close-kept secret for myself and select other teammates and colleagues who were curious to know what exact wizardry I was doing.

And now, for the first time, I’ve decided to clean up the solution, open-source it, and share it with the world.

Behold, the Power of “Slack Debugging”

In [1]: from htk import slack_debug

In [2]: from htk import slack_debug_json

In [3]: slack_debug('This is seriously awesome!')
Out[3]: <Response [200]>

In [4]: slack_debug('Yeah, no kidding.')
Out[4]: <Response [200]>

In [5]: slack_debug_json({'A':1,'B':2,'C':3,'X':['foo','bar','baz'],'Z':{'nested_key':'nested_val
   ...: ue'}}),
Out[5]: (None,)

Debugging like a Boss with Slack

And without further ado, Slack debugging is available here: https://github.com/hacktoolkit/python-htk and https://github.com/hacktoolkit/pyhtk-lite. (And for Ruby: https://github.com/hacktoolkit/htk-rb).

Love it? Hate it? Please share your thoughts and comments, or even better yet, submit pull requests to make it better!

Kill Netskope Client on Mac

2018-10-23

Netskope is a corporate security tool installed on corporate-owned devices that will introduce and override the default SSL certificate authorities by injecting its own local server.

For developers, this often poses an inconvenience especially if they need to develop applications that make API calls and HTTP requests to other web services, if the developers are hitting a web service that has not previously been white-listed by the IT department. The IT department may not be in close communication with the engineering teams, and require additional information from the developers in order to configure a new whitelist rule, impacting the ability of engineers to meet deadlines.

tl;dr; How to kill temporarily disable Netskope

sudo launchctl unload /Library/LaunchDaemons/com.netskope.stagentsvc.plist

TIL: pbcopy

2018-10-03

TIL: Discovered a super game changing technique. From command line, you can copy contents of any file to Mac OS clipboard by running this command:

  1. cat yourfilename.txt | pbcopy
  2. Open your other application, press Command+V to paste as normal
  3. Profit. Immensely.

When Slack links don't work, Restart Google Chrome

2018-03-01

Periodically, web hyperlinks in Slack would stop working.

The fix is surprisingly quite simple: Restart Google Chrome.

The best way to restart Google Chrome safely and preserve your current open tabs is to type into the address bar:

chrome://restart


Make a Donation