OSGI Web Sockets

20 January 2019 Author: Erik Lievaart In this article I will demonstrate the simplest and fastest way to create a web socket under OSGI. I will use apache felix with jetty without any external dependencies. View Full Article

Automatically importing preferences and projects into Eclipse workspaces

18 July 2018 Author: Erik Lievaart In this article I will describe how one can setup an Eclipse workspace without manual steps.

Eclipse does not have global configuration. It never has, and it seems like it never will. It is probably the number one reason why people switch to IntelliJ, but this does not seem to impress the developers of Eclipse. Eclipse does have various export functions, but the programmer is expected to manually click through menus to import the configuration. Eclipse does not have an automatic mechanism for importing projects into a workspace, well it sort of does, we'll get there. But lets go over the alternatives for importing preferences first, you may like them better than my solution. View Full Article


HTML Websockets

19 July 2017 Author: Erik Lievaart In this article I present a simple websocket testing page. Next I will explain the javascript involved. View Full Article

Apache cgi handlers

15 June 2017 Author: Erik Lievaart In this article, I will be examining apache handlers and guide you through setting them up for cgi. Cgi scripts can be used to generate or modify responses to requests on the Apache webserver. Handlers can use these scripts to manipulate every request passing a certain rule. This is a flexible mechanism that turns a static webserver into a full blown application server. This guide aims to make setting up a cgi handler as simple and as painless as possible. View Full Article

Apache cgi scripts on Linux Mint 18.1

07 June 2017 Author: Erik Lievaart Cgi scripts can be used to generate or modify a response to requests on the Apache webserver. Roughly any shell or programming language can be used. Cgi offers hassle free means for generating dynamic output. Creating them is by no means a complicated task, but I found that many of the help pages skip some of the steps required to get up and running. Having struggled through this today, I am in the perfect position to create a complete step by step guide to get there. This guide is purely focused at getting your cgi scripts running and will ignore topics such as security and performance. I will show you how to execute a cgi script for a specific url, In my next article I will show you how to run scripts for a range of urls.

Lets get started: View Full Article


Introducing the Cheat Sheet

05 March 2017 Author: Erik Lievaart I have added a new feature to this website. From now on it will be possible to view my personal cheat sheet on http://eriklievaart.com/cheat

Any time I try out a new programming language or framework, I tend to save useful snippets. I used to save these on my google drive, but I decided it was time for a better solution. By storing it on my public website I no longer need to log in to view the snippets. Also, other people may find some tips & tricks here. Feel free to look around and I hope you find something useful.


Java8 Lambda's

07 March 2016 Author: Erik Lievaart Currently without an assignment, I decided to spend some time studying Java8's lambda syntax. I never really had the opportunity to apply them in my work projects, since most servers run on an older java version. In this article I will demonstrating using the Java8 lambda syntax and stream API.

So what is a lambda? The term Lambda comes from the Lambda Calculus and refers to anonymous functions in programming. Anonymous functions allow very expressive code, making applications easier to write and maintain. The concept is by no means new, but it is new to Java. View Full Article


Introducing doclauncher

05 March 2016 Author: Erik Lievaart In this article I will quickly introduce a simple tool I built and use to access javadoc quickly.

Programmers all have their quirks. We tend to be quirky people :)
One of my quirks is that I like to work offline. Network connections fail more often than we'd like. Even when we have internet, the site we are trying to reach may be unavailable. Both at home and at work I have been in numerous situations where there was no internet connection available. I always want to have an offline version of javadoc, reference documentation and jar files available. Files stored locally are opened faster and always available.

I have written a simple command line tool for openening javadoc. If I need to open the javadoc of for example java.util.HashMap al I have to do is open a command line and type:

doc java8 HashMap
I find that this works a lot faster than opening a browser and googling it. It also reduces the load of context switching and ensures you always have the right version of the library. View Full Article

Running a linux mail server (Ubuntu)

02 March 2016 Author: Erik Lievaart While looking for assignments I came to the realisation that I don't have an email address that is representational. In the past I have opened dedicated email address for such new tasks, but then you end up with yet another email address. Wouldn't it be nice if we could open an email adress that is linked to our domain name and forwards to an existing email address?

Since my domain name is tied to a linux droplet hosted on digital ocean, running a mail server on the droplet is a logical choice. Installing and configuring server applications can be time consuming, and I was worried this would be a large chunk of work. But actually, the mail server was configured and up and running in a flash. I was pleasantly surprised by the software. In this article I will examine the steps that were necessary to get the mail server up and running. View Full Article


Parsing in JavaCC

08 September 2014 Author: Erik Lievaart In the previous installment, I explained how to chunk a stream of characters into Tokens in JavaCC. In this article I will discuss validating the stream of Tokens created by the lexer. The parser has a fundamentally different role than the lexer. The lexer attempts to convert a stream of characters into a stream of words (Token Objects). The parser is no longer concerned with syntax, but with structure. The parser verifies that Tokens that are valid in a language, occur in an order that is meaningful.
Also, I want to discuss the relationship the lexer and the parser have. When I started writing code in JavaCC, I wrote multiple conflicting Token definitions. I expected the Token to be selected from the possibilities based on what Token the parser is expecting. This is not how it works. The lexer doesn't select its TOKENS depending on the current parser rule, because it doen't even know the parser exists. In practice the lexer may have a reference to the parser, but theoretically it doesn't. The lexer makes its decisions based on the characters it encounters, nothing else. Understanding that the lexer is a standalone entity might help you avoid some common mistakes.
I will discuss writing code in parser rules, but not generating code as a result of the parsing process. My main focus is on understanding JavaCC. Typically with JavaCC we create an AST. AST's are node structures used to store Tokens. It is a convenient format often used in compiler design. Generating your output format is highly application specific and out of the scope of this article. Examples of output include but are not limited to: assembly, bytecode and other programming languages. I will not discuss JJTree in this article, I plan to write a follow up article for using JJTree. In the rest of this article we will take a look at how we create parsers in JavaCC.

JavaCC Expansion Choices

Let's have a look at how we define parser rules in JavaCC. I wil start with simple parser rules and make them progressively more complex.
The simplest parser rule I can think of verifies the presence of a single Token:
void empty(): {} { <EOF> }
View Full Article

Lexical Analysis in JavaCC

31 August 2014 Author: Erik Lievaart In the previous installment, I showed the basics for getting a JavaCC compiler up and running. In this article, we will take a look at the nitty gritty of lexical analysis in JavaCC. There will be a little bit of overlap with the previous article, but we will go into much greater depth here. Lexical Analysis is the process of breaking a stream of characters into chunks called tokens. Tokens are the smallest unit of information meaningful to the parser.

Defining tokens

Token declarations follow the format:
[KREP] : { <[NAME]: [EXPR]> }
And here is a rudimentary token declaration:
TOKEN : { <PUBLIC: "public"> }
View Full Article

Getting Started with JavaCC

22 August 2014 Author: Erik Lievaart Recently, I wanted to write my own parser for a hobby project. I chose to use JavaCC, because it seems to be one of the more accessible Parser Generators. In my journey I did find, however, that there is a lack of a gentle introduction into JavaCC. The articles I found were very high level and theoretical, or they always solved the same problems (basic arithmetic expressions). I plan on writing a couple of articles that are very hands on, very practical. This first article will be a quick getting started guide aimed to get you up and running quickly. The next paragraph will describe from a theoretical perspective what JavaCC is and why one would want to use a parser generator. In "Creating a workspace" I will show you how to get the hello world project up and running in a minute or so. Then I will discuss the demo project for JavaCC in depth. It is a good starting point for creating a parser.

JavaCC

JavaCC is named the Java Compiler Compiler. It is an open source parser generator. You can use it to create your own custom parser. A parser is a program which uses validates an input file against a grammar. It reads a file in one format and (if valid) converts it to another format, usually executable code. We typically create parsers when we are creating our own programming language. Sometimes we create them for templating languages or for tokenizing raw text. Creating parsers by hand is error prone and parser generators offer a higher level syntax to aid process. For simple text manipulation one would use String manipulation libraries, for moderately complex problems regex is enough. Using JavaCC for such problems is overkill and will cause mor e problems than is solves. When things get complex, however, having a parser generator at your disposal is a life saver. One of the features of JavaCC that I really like, is that the generated parser has no dependency on javacc. In other words, javacc creates pure java source files that can run without any external dependencies. Antlr in comparison requires the antlr jar to be present at run time. My focus here is practical, so this is the only theory on the matter I will be discussing here. I am not going to discuss concepts such as LL(1) grammars or recursive descent parsing. I do recommend acquainting oneself with the theory behind parsing, when working with parser generators.

Creating a workspace

In this section we will create a basic JavaCC project in a few minutes, so you can start learning quickly. View Full Article