Find what is listening on a given port

To find out what application is listening on a given port on Linux, issue following command,

with Mac OS X, the netstat command behaves differently, and you need to provide the protocol via -p option.

Besides, there is another command you can use, lsof.

where $PORT_LIST is a list of ports in comma-separated format.

For example,

Have fun :)

Check package information installed by Homebrew

After installing a package using Homebrew, you can see the package information right away, it prints out to the stdout, such as: caveats, configuration, dependencies… Somehow, if you forget them, and want to look up the package information, what would you do?

Luckily, Homebrew provides an option to look up the information of installed packages, and just like this,

detail of the package will be shown on terminal screen. I personally don’t remember much of configuration of many packages that I install on my machine, like nginx…and with this command, I can easily find out the nginx config file and start working without the need to remember anything.

Config to launch Sublime Text from command-line on Mac OS X

If you are a developer and use Sublime Text frequently, you might want to add Sublime Text to launch from command-line. It depends on your Sublime Text version (2, or 3) to config the symbol alias,

With Sublime Text 2,

With Sublime Text 3,

Make sure to have /usr/local/bin in the PATH variable, if not, append the following line to the .bashrc, .bash_profile if using Bash, or .zshrc if using ZShell.

Just another very basic tip for command line users :)

Fix Docker push authorization required

When pushing Docker images to the registry, you might fail and see this error

So the question is, how to authenticate into Docker from this command line? and why doesn’t it prompt for authentication?

Well, I don’t know, but I find out that you need to authenticate in different command.

Prompt your password, then you will be able to push images to registry. There is an –email option, but it will soon be deprecated, so don’t mind about that if you see it appearing in any other articles on Internet.

Show color on Rails test reports

By default, the test report of Ruby on Rails looks pretty much boring and it is hard to recognize if any test fails.

Default Ruby on Rails Test Report

Default Ruby on Rails Test Report

To improve the readability on test report, use the minitest-reporter gem

Update the Gemfile, for example,

After that, the report will look a bit nicer,

Improve Test Reporter Readability for Ruby on Rails Test Reporter

Improve Test Reporter Readability for Ruby on Rails Test Reporter

Have fun :)

Remove www prefix from domain name

When you access a domain name, by default, it will redirect to the one with www prefix in domain name. To remove this www prefix, in Apache Server, apply following rewrite condition in .htaccess file or Apache config file,

Not only for your own server, you can apply this on shared hosting services too such as NameCheap, GoDaddy, iPage …

Resolve SSH Too Many Authentication Failures

When trying to connect to servers using SSH, you sometimes see this error message,

The problem is that SSH will automatically lookup for any available public keys on system and try to use them for connection, if none of them is valid, it pops out the error.

So to avoid this situation, simply pass the option to stop using public keys PubkeyAuthentication=no

then it should work!

Add social sharing to Ionic apps

Social sharing is a very popular feature that most of apps implement, and as you develop an Ionic app, you might wonder how to make it. It is quite simple, since Ionic integrates with Cordova to interact with native functionality, we will use one known plugin, cordova-plugin-x-socialsharing.

To use this Cordova plugin, we need to install via following command,

It is ready to work now, by using window.plugins.socialsharing object, for example,

Okay, that is regular Javascript, what if you want to take advantages of AngularJS in Ionic? Then setup to use ngCordova.

Include the ngCordova library right before cordova.js in index.html,

To use it, inject ngCordova to the right module, and use with $cordovaSocialSharing object.

Something like this,

For more information about this plugin, refer to its Github page.

Also, checkout for ngCordova documentation for Social Sharing plugin.

You can try with the demo project, petehouston/demo-ionic-social-sharing.

Alright, have fun!

Add URL Scheme to whitelist in iOS 9

From iOS 9, Apple has changed the canOpenURL method, it will check for URL schemes, which should be added to the whitelist. To do this, simply open the app plist file and add the following key,

just add the scheme of the app you want to open. Without this declaration, error will occur,

For more information about changes in URL scheme, please refer to this detailed article that explains the new canOpenURL behavior.