Category Archives: Linux OS

Developer productivity tools for iPad

I have tried doing development on my iPad and I found some tools which I liked:
Python – Pythonista
Java – Jedona

I was able to write some interesting programs while on the go on both my iPhone and especially on iPad. However I have realised that for better productivity it is better to use remote desktop solution to login into my Windows and a VNC solution to login into my MacBook.

Windows Mobile App (Previously called RD Client)
RealVNC Client

I have a static IP available for my home network however one can easily use solution like noip.com to get static domain name to work using the DDNS client built in your home router. I usually configure a port forward on my router to RDP into my windows or VNC into my MacBook if the router does not support VPN server. For better security I have setup a VPN server on my router and I do a VPN connection into my home network effectively eliminating the need of opening ports / do port forwarding.

Using the above approaches I no longer have to carry my laptops around and I use my iPad to do some work directly on iPad or via remote connection to my computers back home.

To manage my personal Linux servers on cloud I use Blink. Combined with Mosh I have found Blink to be a solid solution to SSH into my Linux boxes and do my work.

Blink

This type of setup has greatly reduced the amount of hardware I need to carry around. With one iPad and an iPhone I can work on most of my hobby projects and also do some of my office work.

Viewing files in hex mode

Sometimes I need to look at files in their actual hexadecimal format. I use the combination of vi and hexdump to fulfill this requirement.

To simply view a file’s content in hex format I use this command on my mac.

hexdump -C <file_name>

This typically is enough for the job at hand. However there is also another trick of using hexdump by leveraging vi command. I follow the following steps:

  • Start vi by typing “vi <file_name>” on the command line.
  • Type “:%!hexdump -C”
  • This will replace the contents of the vi screen with the hex view of the current file.
  • Save the file for future use.

Block a shell script till a server boots up

This small script blocks a shell script / docker compose command script till a dependent server boots up.

#!/usr/bin/env bash

while :
do
  response=$(curl --write-out %{http_code} --silent --output /dev/null -X GET "$1")
  if [[ "$response" -ne 200 ]] ; then
    echo "Server is not yet up >> $1 >> $response"
    sleep 1
  else
    echo "Server is up >> $1 >> $response"
    exit 1
  fi
done

Prettify JSON on Terminal

I love using curl command on my Mac terminal to debug my REST endpoints. However the REST call JSON output used to come in a blob of text which required further formatting in an Editor like Visual Studio Code. To allay this problem I ended up installing “jsonpp” using homebrew.

brew install jsonpp

So now I just pipe the output of my curl command to the jsonpp program and I get a fully formatted JSON.

$ curl http://localhost:8080/test | jsonpp
{
"year": 2018,
"month": 2,
"worked": 18,
"leaves": 2
}

 

 

Curl Command New Line Post Output

I like to use curl instead of UI tools like Postman for debugging my RESTful web services traffic whenever possible. I however didn’t like my output being messed up by the bash prompt being suffixed to the output. Something like the following:

$ curl -H "$auth_token" http://localhost:8080/xyz/abc-efg
["-","A","B","C","D","E"]$

So basically what I needed was to have a new line forced after the curl output. A quick search on internet yielded this article. So I executed the following command on my terminal.

$ echo '-w "\n"' >> ~/.curlrc

After doing this when I execute the same curl command I get the following output.

$ curl -H "$auth_token" http://localhost:8080/xyz/abc-efg
["-","A","B","C","D","E"]
$

So now the bash prompt is actually coming on a new line by default!

List of good Curl commands

I use CURL for debugging my REST endpoints every now and then if I don’t want to use Postman or DHC clients. I usually like to copy paste results / statistics from command line into emails to my colleagues. This gives them a plain jane command which they can use to test themselves as well as compare their results with mine. The following article has some good pointers on how to use CURL and some very practical examples have been provided.

15 Practical Linux cURL Command Examples (cURL Download Examples)

Displaying memory statistics along with hostname and war files

I recently got into a situation where I had to debug around 10 servers all of which were suffering from memory issues. My java applications were slowing down after a day or so. Although its is difficult to diagnose this kind of issues which span across multiple VMs (welcome to Micro Services!) but with some little bit of scripting it is possible to see in real time the actual numbers if you manage to use tmux to multiplex multiple shell sessions stacked together. I hacked up the following command to display hostname, running war files as well as the memory statistics refreshed every 1 second on screen.

watch -d -n 1 "hostname | tr '\r\n' ' ' && printf \" \" && jps -l | grep .war | tr '\r\n' ' ' && echo "" && free -h"

Linux Disk Usage

I found a good link which lists good usages of the Linux command “du”.

This command allows me to see the usage in a ascending sort which is really helpful.

Tested on Linux.
du -h / | sort -h

Tested on Mac OS.
du -hs * | gsort -h

In case you don’t have gsort install coreutils.
brew install coreutils

This variation allows me to see any line which has the text “G” in it which basically allows me to see folders using space in GBs. Agreed it might give some folder names as well with “G” in it but I can bear with it.

Tested on Linux.
du -h /the/path | sort -h | grep "G"

Tested on Mac OS.
du -h /the/path | gsort -h | grep "G"