Secret SQL Weapon: Indexed (or Materialized) Views

October 27, 2019

A few months backs I implemented logic which needs to lookup entries in a big existing table, but the lookup wasn’t easy indexable. Here’s a guide on one approach you can take. I’m using SQL Server for this example. Let’s assume we have a table with guests, something like this

CREATE TABLE Guests (
   Id BIGINT NOT NULL IDENTITY(1,1) PRIMARY KEY,
   Created datetime NOT NULL DEFAULT getutcdate(),
   Email VARCHAR(256) NOT NULL,
   Name VARCHAR(256) NOT NULL
   -- More fields
);

-- Example data
SELECT TOP (3) * FROM Guests
-- Result:
Id Created    Email  Name
1  2019-10-26 12:58:10.867    corrinne1981@rocketmail.com    Corrinne Bordons
2  2019-10-26 12:58:10.877    admin@schriever.us         Cythia Schriever
3  2019-10-26 12:58:11.177    darcie@tutanota.com            Darcie Potencio
Continue reading →

Clojure defonce: Keep Your Apps State

October 25, 2019

One of the great strengths of Clojure is interactive development. Usually, you run a REPL and an editor that interacts with that REPL. You try out small things in the REPL, send pieces of code from the editor to the REPL, reload modified files, etc. You rarely restart the app, but keep going editing code. I’m missing that in other programming environments.

It works for Clojure due to many factors. The Lispy-ness with a distinct REPL at your disposal and tools taking advantage of it. Then the Clojure pushes you toward functional programming with immutable data structures, which then leads to a culture where the app state is usually held in very few places and the app mostly consists of functions operating on it. So when code is swapped the immutable state can be kept and be used with the new code.

Continue reading →

Compiling Java Classes with Clojure Deps

October 24, 2019

In the past, I used Leinigen for Clojure projects. It downloads dependencies, compiles, handles the classpath, runs tests etc. Clojure 1.9 introduced the clj command line and the deps tooling. You can specify a deps.edn file and declare the dependencies in there. Deps not a build tool by design. it only downloads dependencies from Maven- and git repositories and builds the Java classpath. It doesn’t have other build features. However, for smaller Clojure projects that is enough and you can go without an extra build tool.

So, I started to use Deps as the starting point and it serves me well so far. Recently I wanted to add a Java class to my project. I do that when using Clojure-Java interop gets complex and it is just easier to have a few helper Java classes. However, how do I compile these classes? Leiningen has the lein javac command, but Deps doesn’t do builds.

Continue reading →

Java, Let me use the damn FileDescriptor!

October 15, 2019

Last Update 2024-01-30, see below

Recently I hacked on some utility in Java which should be able to bind low ports like 80 or 443 on demand without running as root. When I needed to bind these port I wanted to execute an external process as root which opens the ports for the main process and then sends the ports via Unix domain socket.

Continue reading →

Intro to MVStore, an embedded key value store

September 25, 2019

MVStore is the backend storage for the popular embedded H2 relational database. If you don’t need a relational database, but a lower level storage MVStore is maybe an option. The MVStore has a good nice range of features. The documentation isn’t as detailed, but the intro documentation gives a decent overview. Anyway, this post is another small intro.

H2 vs MVStore
Figure 1. H2’s companion, the MVStore
Continue reading →