June 2016

Ubuntu – reload iptables rules during boot

Steps to load iptable rules automatically on Ubuntu Linux using package iptables-persistent. Install iptables-persistent $ sudo apt-get install iptables-persistent When asked during installation should it read more

Java – Arrays.sort custom Comparator example

Java – create inline Comparator example

Java – print exception as string examples

Print exception stack trace Print exception short description

Java – string to int example

Java – string prefix match using startsWith

Java String startsWith(String prefix) example: To specify offset use startsWith(String prefix, int toffset)

Java – two dimensional array example

Java – two dimentional array example

Java – fill an array using java.util.Arrays

Fill all values in an array Fill range in an array

Mac – print java home on command line

To print Java (JVM) home path on command line the following command (jave_home) can be used as shown below: $ /usr/libexec/java_home /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home To display all read more

Remove passphrase from ssh private key

To remove passphrase from an existing key, we can use ssh-keygen with -p option. Here is an example which changes passphrase of private rsa key read more

How to check if an ssh key has passphrase

To check if an ssh key has passphrase, one can look for the presence of ENCRYPTED string in the private key. Here is an example read more

Use netcat (nc) to check if a remote port is reachable

Netcat (nc) can be use to check if a remote port is reachable and client can connect to it. The following commands were tried on read more

Java System.out.format examples

System.out.format method format multiple arguments based on format string. Basic example print integer 8 characters in width print float with 2 digits after decimal point

Java System.out.print and println

System.out.println example println will append a new line after the string. System.out.print example print will not append a new line after the string.

Java – equals vs ==

String method equals check if both references points objects with same values stored in them. Operator == check if both references points to same object.

Java – array basics

Initialize arrat and print length Access element at specific index Access non existing index This will throw Index Out Of Bounds Exception

Linux – ssh agent forwarding when using bastion host

When using a bastion host (or Jumpbox) to connection to production server using ssh private keys, ssh agent forward can be used. The main advantage read more

Java – array for-each loop

Java – compare strings

Case sensitive comparison Compare strings using firstString.compareTo(secondString). Positive outcome means firstString > secondString and so on. Case insensitive comparison – compareToIgnoreCase

Java – initialize string array

Initialize string array using curly braces {}

Linux – find listening ports

Sometimes it is useful to find what ports a machine is listening to. Here are some use cases: Display listening ports $ netstat -l Display read more

Enable query log without restarting mysql on Linux

Steps to enable mysql query log on mysql server without restarting mysql process on Ubuntu and other Linux flavours. Set general_log_file on SQL prompt: SET read more

Chrome – copy any request as cURL including headers

Chrome developer tools has a pretty handy feature to copy any GET/POST request in network tab to cURL. This also copies all headers involved in read more

Mac – how to change desktop icons size

Mac desktop icons size can be increased or decreased using Desktop view options. There are steps: Click anywhere on blank Desktop area. Click on View read more