Welcome to Knowledge Basement

Linux, Java, Open Source related how-to articles

Connect to Elasticsearch with Java and RestHighLevelClient

Connecting to Elasticsearch and executing queries is generally considered easy. In fact, in many cases a simple curl query like this one is all you need: Though, if you want something more than just finding all documents that contain mySearch (as per the example above), you may get lost in the abundance of options and… read more »

Build A Java Project With Maven

Using Maven to maintain and build your Java projects has a lot of advantages including automatically resolving dependencies, running tests and packaging. In this article you will learn about a complete development cycle using Maven from creating the project to building it. Installing Maven You can install Maven on most Linux distributions using the default… read more »

Getting Started with Chef and Chef-solo

Chef (the systems integration framework) provides a standalone tool called chef-solo. With chef-solo you can run locally chef recipes without the need for a centralised server (Chef master). This is great for getting started with chef, testing recipes or when you just don’t want a centralised Chef master. In this article we’ll go through a… read more »

AppArmor Php-Fpm Configuration with ChangeHat

AppArmor is the default Mandatory Access Control module on Ubuntu, SuSE and other Linux distributions. Thanks to it, you can limit the filesystem access of a process. There are already some good howtos for getting a basic setup of Apparmor for Php-fpm. Though, in cases such as that of running multiple sites securely with Php-fpm, you… read more »

How to Run Sites Securely with Apache and Php-fpm on Ubuntu 16.04 LTS

A great security feature of Php FastCGI Process Manager (Php-fpm) is its ability to run Php scripts with different users. This in addition to its other merits such as performance and many fine grained options for tuning makes it the best choice for running Php sites. Before anything else, I must admit that Nginx with… read more »

Terminate Java Thread

The best way to terminate a Java thread is with a switch such as a boolean property, .e.g abort. As soon as a condition is met, usually a timeout, you can change the value of abort to true and thus exit thread. Example: import java.util.concurrent.*; public class CheckResults { private static int counter = 0;… read more »

Referencing a Child Object to a Variable of Type Parent in Java

Referencing a child object to a variable of type parent in Java can be real confusing. Here is an example of two classes Person and Student and an overriden method whatAmI: class Person { String it = “It is a Person.”; public void whatAmI(Object x) { System.out.print(“Person’s object… ” + it); } } class Student… read more »

Working with Time and Date in Java

Working with time and date in Java is essential to any project. There are three important classes you can use: java.time.LocalTime – working only with time. java.time.LocalDate – working only with date. java.time.LocalDateTime – working with time and date both. All three classes provide two essential methods: of(arguments) – accepting arguments for the time/date/datetime values…. read more »

How to Parse Time in Java

To parse time in Java, the most trouble-free and programatic way is using the parse method of the LocalTime class like this: import java.time.LocalTime; import java.time.format.DateTimeFormatter; public class TimeParse { public static void main(String[] args) { String inputStr = “Time is 11 minutes past 11PM.”; String pattern = “‘Time is ‘m’ minutes past ‘ha.”; DateTimeFormatter… read more »

How to Install and Configure SuPHP

Notice: This article was written when  SuPHP was the most popular choice for running multiple PHP sites on the same Apache server. Now, php-fpm with different users is a better choice. But still, if you need this article, here it is… In short, SuPHP runs the PHP web scripts as a  predefined system user, respecting… read more »