Posts

PostgreSQL: setup User and Role in Linux (Mint)

After installing PostgreSQL, type the following command: $ psql -U postgres postgres is the default super user. We login as Postgresql database system by using this super user.  Display existing user's roles: postgres-# \du+  Create ps_admin role: postgres=# CREATE ROLE ps_admin WITH LOGIN CREATEDB PASSWORD 'admin'; The ps_admin can login with password 'admin' and can create new database. Note: Here, password is simply 'admin'. In the real life the password should be complex combination of words, symbols and numbers. Display list of roles: postgres=# \du+ You will see something like below: Role Name: ps_admin List of roles Attributes: Create DB Create Database: $createdb testdb -p 5432 -h localhost -U ps_admin; The createdb is command line command. The database name testdb will be created under ps_admin user. It should be run in the console. -p = port (default port is 5432) -h = hostname (default hostname is loclhost) -U = username (ps_admin) It will be prom...

How to Convert OutputStream to InputStream

Sometime we need to convert Output Stream to Input Stream. We can perform the conversion multiple ways.  The following two approaches are most popular: 1. ByteArrayOutputStream to ByteArrayInputStream 2. PipedOutputStream to PipedInputStream Complete example code is available in the [ Github ]. Approach 1: ByteArrayOutputStream/ByteArrayInputStream The ByteArrayOutputStream/ByteArrayInputStream is the easiest way to convert OutputStream to InputStream. Code snippet: TextWriter textWriterBins = new TextWriter(); ByteArrayOutputStream bouts = new ByteArrayOutputStream(); textWriterBins.write(bouts); ByteArrayInputStream bins = new ByteArrayInputStream(bouts.toByteArray()); TextReader textReader = new TextReader(bins); textReader.print(); Here, TextWriter is a class which writes some text in the OutputStream and TextReader is a class which reads data from InputStream and print on the console. In the above code snippet, the TextWriter.write method writes the da...

WildFly 19 and Log4J2

In this post, I would like to share my story about external configuration file of Log4J2. I developed a Java web application in WildFly 19 application server. It was my pet project. I followed few strict rules about 3rd party libraries. For example, I did not use log4j2-web library/jar file. It was the challenge because in some workplace you cannot have luxury to get all bells and whistle. You have to accept the situation. Therefore, I took this challenge to use external configuration file of Log4J2 in the web application without depending on log4j2-web jar file. My development environment's logging configuration is not same as production environment. In this case, I do not want to swap between development configuration and production configuration file during deployment.    The above situation can be mitigate by two ways: Use external logging configuration file. User application server specific logging system. For exampke, ...

How to merge multiple pdf files

Today, I merged my brother's coverletter and resume into one single pdf file. How did I merge two pdfs? Hmmm.... Did I buy Adobe Acrobat professional.........Oh no!!!!. I am Linux user. I can do magic. Sorry Windows users..... I am using Linux mint. I have pdftk tool. Type the following command in the terminal to install pdftk: $ sudo apt-get install pdftk Firstly, I renamed my brother's coverletter from "lastname-firstname-coverletter.pdf" to "lastname-firstname-1.pdf" and resume from "lastname-firstname-resume.pdf" to "lastname-firstname-2.pdf" Finally, I ran the following command in the terminal pdftk lastname-firstname-*.pdf cat output lastname-firstname-coverletter_resume.pdf

YAML tutorial links

This is a quick YAML tutorial: https://learnxinyminutes.com/docs/yaml/

MongoDB sharding the simple way

Here, I will discuss how to create mongo shard in the single machine (locally) for dev environment. My OS is Linux Mint and MongoDB version is 4+. Install MongoDB: I downloaded mongodb tar files and extracted it to the /opt/mongo/. Create database directory: $mkdir -p /opt/mongo_db/shard_db I like /opt directory very much, if you do not like create your database directory in /opt, please create it in your desire location. I dislike pointless argument. To create shard you must have a plan to organize your shard clusters. In this example, I will create 3 shard each shard will have 2 replicate sets and 1 config server with 2 replicate sets and 1 mongos to connect shard cluster via config server 1) Shard servers/clusters   1.1) Create sdb directory inside the shard_db/ directory:          $mkdir sdb     1.2) Inside sdb/ directory we are going to create 6 directories as I mentioned earlier that I am going to create 3 shard with 2 re...

How to copy directory structure without copying contents of the directory

Few days ago, I have to download Spring Framework latest stable jars. There is no single zip file which contains all the jars of Spring Framework. So, I have to create the directory for specific jar and download it.  I had older version of Spring Framework directory which contains folder for specific jar file. I do not want copy the content inside the directory just directory structure. Therefore, I issued the following command. find . -type d >dirs.txt xargs mkdir -p