My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com









Tuesday, November 19, 2019

How to install Redis and run its instance


First, step first. You can simply install it using homebrew
$ brew install redis

After installation you can check that it creates a configutration file at:
/usr/local/etc/redis.conf

Then, you can verify the install as follows:
$ brew info redis

You can start an instance i.e Start Redis server using the configuration file.
$ redis-server /usr/local/etc/redis.conf

By default, it Runs in standalone mode on Port: 6379


Test if Redis server is running.
$ redis-cli ping
It will replu=y you pong!

To Uninstall Redis and its files.
$ brew uninstall redis


What more do you want. So cheers.
:)

How to install Homebrew (brew command) on Mac, linux

To Install Homebrew, you need to make use of ruby that is already installed. This is a simple command then.

On your terminal use following:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Paste that in a macOS Terminal prompt.

The script explains what it will do and then pauses before it does it. Read about other installation options. Install Homebrew on Linux and Windows Subsystem for Linux.

Voila!! That's it.


After this you can tyest which version is installed. Eg:
$ brew --version
Homebrew 2.1.16
Homebrew/homebrew-core (git revision 6176; last commit 2019-11-18)




Thursday, November 14, 2019

How to show full working directory in mac terminal on every command


Problem description:
You can obviously use a pwd command to see the present working directory. For eg:

prompt$ pwd
/Users/mfaiz/myDir

But sometimes you want to show the full directory path every time. Its a common ask for eg:
/Users/mfaiz/myDir$ pwd


Or, better still you want the directory path to be displayed on top before each command. All such issues can be handled using your bash profile file:


vi ~/.bash_profile


Solution: 
You can add this line -
export PS1='\u@\H:\w$'

or, if you like having a space between the $ and the command, then - 
export PS1='\u@\H:\w$ '



Shown following are two more complex examples that include coloring as well:




Command used to achieve this is:

export PS1="\n$C_LIGHTGREEN\u$C_DARKGRAY@$C_BLUE\h $C_DARKGRAY: $C_LIGHTYELLOW\w\n$C_DARKGRAY\$$C_DEFAULT "




Monday, July 29, 2019

Parsing Json in Java using JsonParser

You can use one of the many available Json Parser for the purpose. I have personally used following in simple applications. You can refer this tutorial:

 
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;



 
You might need to install dependencies first:

In case you are on maven, use following to set a proper environment for the compiler, in order to recognize the JSON's classes. If you want to built your project via Maven, you should add the following dependency to your pom.xml:
1
2
3
4
5
<dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>1.1</version>
</dependency>
Otherwise, you have to add the newest version of json-simple-1.1.1.jar in your CLASSPATH.

First you need to Declare an instance of the JSONParser:
 JSONParser parse = new JSONParser(); 

Then, Convert the string objects into JSON objects:
 JSONObject jobject = (JSONObject)parse.parse(inline); 
If you view the JSON structure, it will be something like this:
{
   "results" : [
      {
   "place_id" : "aa1123",
         "types" : [ "locality", "book" ]
      } ]
}

Then you can convert the JSON object into JSONArray 
JSONArray jsonarray = (JSONArray) jobj.get(“results”); 

Now you can use as per your need, for eg.
get the elements within the results array. Here is how you do it:
//Get data for Results array
for(int i=0;i<jsonarray.size();i++)
{
//Store the JSON objects in an array
//Get the index of the JSON object and print the values as per the index
JSONObject jsonobj_1 = (JSONObject)jsonarray.get(i);
System.out.println(“Elements under results array”);
}

Wednesday, July 24, 2019

Remote debugging using IntelliJ IDE

Here you'll see how to create and manage a configuration to remotely debug your launched Alfresco project that's waiting for a connection. This assumes you have an IntelliJ IDEA IDE up and running, and have already imported the same project you are going to debug.

For more details on how import an Alfresco project into your IntelliJ IDEA IDE, see Setting up your development environment using Intellij IDEA

Open the IntelliJ IDEA IDE and click on Run Configurations (top right).


Click on the green plus (top left) and select Remote to add a new configuration for a remote app.
Enter a name for your configuration, for example, "My-remote-debug"

Apply some settings eg. Change the port number eg. to 8000.
Check that your settings match the screenshot.
Click OK.



Now when you debug, You will be taken back to the project source code.
To start debugging Click on the bug (debug) icon and select the new configuration My-remote-debug to run it.


The project starts running and generating all the log messages of a regular launch in the terminal window. Open your browser and type http://localhost:8080/hello

Voila!! IntelliJ IDEA will intercept the execution at the breakpoint: