Posts
Setting Up Postfix Email Server
Most monitoring tools can send email notifications, so a local email server is quite helpful for testing. In this post, I used Red Hat Enterprise Linux 8.0 hosted on an Amazon EC2 instance.
First, I installed the postfix package:
dnf install -y postfix Then, I edit the /etc/postfix/main.cf configuration file:
sudo sed -i "s/#myhostname = host.domain.tld/myhostname = $(hostname -f)/" /etc/postfix/main.cf sudo sed -i "s/#mydomain = domain.tld/mydomain = ap-south-1.compute.internal/" /etc/postfix/main.cf sudo sed -i "s/#myorigin = \$myhostname/myorigin = \$myhostname/" /etc/postfix/main.
Posts
Java Trust Store
In this post, we install an Nginx server, enable HTTPS and make an HTTP request from Java with the Nginx server’s HTTPS certificate imported into a trust store. This post uses RedHat Enterprise Linux 8.
First, creating the certificates…
mkdir certs; cd certs openssl genrsa -out locally.key1 openssl pkcs8 -topk8 -in locally.key1 -out locally.key -nocrypt openssl req -new -key locally.key -out locally.csr -subj "/C=AE/ST=Dubai/O=KNR/OU=IT/CN=localhost.localdomain" openssl x509 -in locally.csr -out locally.crt -req -signkey locally.
Posts
Java Simple Webserver
Java 18 and higher include a simple web server that can be invoked from the command-line, as follows:
jwebserver -b 0.0.0.0 -p 8080 The simple HTTP server can also be started from the API:
import com.sun.net.httpserver.*; var server = SimpleFileServer.createFileServer( new InetSocketAddress(8080), Path.of("/tmp/files"), OutputLevel.VERBOSE ); server.start(); The simple web server can be extended with filters and handlers. Handlers are used to provide different branches of handling for different types of requests.
Posts
Working With Elastic Search
Elastic Search, created by Shay Banon in 2014, is a Java-based search engine based on Apache Lucene. It uses an HTTP and JSON based protcol. This post assumes that you have installed Elastic Search. If you have not, please follow the steps in my blog post on Elastic Search installation.
In this post, our interaction with Elastic Search will be with the curl utility. Curl (short for Client URL, previously called httpget and urlget) is a tool developed by Daniel Stenberg, and it is available on most mainstream Linux distributions.
Posts
Java Parallel Sort
Java 8 introduced .parallelSort() to the Array class. It uses multiple threads to perform the sort operation and is therefore quicker. Here’s some code to benchmark .parallelSort() against the regular .sort():
var numbers = new Random().ints(90000000, 1, 999999999); int[] arrNumbers = numbers.toArray(); //List<Integer> lstNumbers = numbers.boxed().collect(Collectors.toList()); Date dtStart, dtEnd; long diffInMillis = -1; dtStart = new Date(); //Comment out the one to execute //Arrays.sort(arrNumbers); //Takes ~6 seconds //Arrays.parallelSort(arrNumbers); //Takes ~1 second dtEnd = new Date(); diffInMillis = dtEnd.
Posts
Trying Java Streams
Streams in Java enables us to filter, sort, map, count and loop over elements in collections.
For this example, we use a Record type, a Java 14 feature to represent a static website generator.
record StaticWebsiteGenerator( String name, String language, String license, int stars ) {} We then create instances for each type of static website generator and store them within a list:
StaticWebsiteGenerator swgNextJs = new StaticWebsiteGenerator("Next.js", "JavaScript", "MIT", 84087); StaticWebsiteGenerator swgHugo = new StaticWebsiteGenerator("Hugo", "Go", "Apache 2.
Posts
Setting Up PyKMIP Server
This setup is with a Ubuntu 20.04 VM.
As a first step, create the needed directories and change the ownership to the user that PyKMIP will run as:
sudo mkdir /usr/local/PyKMIP /etc/pykmip /var/log/pykmip sudo chown ubuntu /usr/local/PyKMIP sudo chown ubuntu /etc/pykmip sudo chown ubuntu /var/log/pykmip Next, install the required packages and create a self-signed certificate:
sudo apt-get install -y python3-dev libffi-dev libssl-dev libsqlite3-dev sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/ssl/private/selfsigned.
Posts
Getting Started With Openldap
This LDAP setup uses Ubuntu 20.04 Linux.
To install the needed packages, do the following:
sudo apt -y update sudo apt install -y slapd ldap-utils #Requires human intervention to enter the OpenLDAP admin password sudo apt install -y net-tools #For netstat #sudo apt-get install -y ca-certificates #This was already installed Next, we generate a self-signed certificate:
openssl genrsa -out ldap_server.key1 openssl pkcs8 -topk8 -in ldap_server.key1 -out ldap_server.key -nocrypt openssl req -new -key ldap_server.
Posts
Python Custom Key Sorter
Just as Java has the comparator and the comparable interface, Python allow the use of the built-in sort capability against complex input that needs a mapping function to determine the key against which a list of values has to be sorted.
Let’s take an example a list of bookings for a bus. On the first row, we have four seats number A1, B1, C1, and D1. The second row has the seats A2, B2, C2, and D2.
Posts
Getting Started With Elasticsearch
A visitor to an eCommerce website would look up a product by searching for it in an input text box with the search term, such as “cookie cutter”. A good eCommerce website then uses a search engine to find all variations of the search terms, ranks the results, and displays the results ordered by relevance to the user. ElasticSearch is one such search engine that is commonly used as a document-oriented database for the text-search use case.