Friday, October 11, 2019

Determine OS version from Command line in MacOS

Sometimes we would like to know about the installed MacOS from Terminal. Or say we are writing scripts to extract the OS related information like it's version and release name etc.

For Mac we have couple of options

System Profiler

Execute the following command from Terminal


As you can see from the screenshot system_profiler will print a lot of information about the Software and Hardware of the Mac.

This is it.....


Execute the following command from Terminal


As you can see from the screenshot sw_vers will print information about the current installed OS Name and Version.

How to change computer name and user name in terminal command prompt in MacOS

Sometimes we want to hide the system name or username that is displayed on the Terminal.

May be to take some screenshot and then paste it in the blog and we want to hide the System name/user Name etc.

For Bash based terminals it can be done by setting PS1 variable.

Example on the terminal

$ export PS1="> "

$ PS1="Mac:~sidd:"

$ export PS1="This is Demo Terminal: $ "
This is Demo Terminal: $

Change your prompt in your  profile file to make it permanent across all Terminals and new sessions.

Thursday, October 10, 2019

How to Install Apache 2 on Ubuntu Linux

Following are the steps to install Apache 2 on Ubuntu Linux and then start it.

Update the System Repository

sudo apt update

Install Apache2 Software with apt command

sudo apt install apache2

Thursday, September 5, 2019

How to convert HttpResponse to String in Java

Following code snippet explains how to convert HttpResponse object to String in Java


  1. Call httpclient.execute()
  2. Get the InputStream from the response
  3. Convert the InputStream to ByteArrayOutputStream
  4. Convert the ByteArrayOutputStream to String
  5. Close the request and InputStream

private String executeAndGetResponse(HttpRequestBase request)
      throws IOException, ClientProtocolException, Exception, UnsupportedEncodingException {
    HttpResponse response = httpClient.execute(request);
    InputStream inputStream = response.getEntity().getContent();
    ByteArrayOutputStream result = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int length;
    while ((length = != -1) {
      result.write(buffer, 0, length);
    String strRes = result.toString(;
    return strRes;

Tuesday, September 3, 2019

Jackson Object Mapper to conver String to JsonNode

Following are some of the code snippet for Jackson Object Mapper
Convert String to JsonNode Object
String data;
JsonNode jsonNode = getObjectMapper().readTree(data);
Convert an Object to JSON String
String jsonString = getObjectMapper().writeValueAsString(object);
Convert InputStream to JsonNode Object
InputStream inputStream;
JsonNode jsonNode = getObjectMapper().readTree(inputStream);

Thursday, August 22, 2019

How to check what version of JQuery is loaded in browser

Sometimes we might want to know what version of jQuery a particular site is using. It is not always possible to know the version of jQuery we are using through the jQuery File name or reading the content of the files, specially when the jQuery is minimized.

Following snippet can tell us the version of jQuery loaded by a site.

if (typeof jQuery != 'undefined') {  
    // jQuery is loaded => print the version

Simply go to the console of the browser, once the webpage is loaded, and then type. the above command on the console. It should display the version as an Alert.

Tuesday, August 20, 2019

How to generate sitemap for Blogs hosted on Blogger

Blogger comes with some goodies, like the atom feed URL, which can be used to generate sitemap for bloggers.
  1. Sign in to Google Search Console.
  2. Select the Blog from the left hand side.
  3. Click on Sitemaps link.
  4. At the top of the page with title "Add a new sitemap"
  5. Add the below code in the text field.
Google Search Console

Example :
Press “Submit Sitemap” button.