Releasing knd: the backend Kinect interface

knd startup

Hi, it’s been a while. So I actually uploaded this next component from Nitrogen Logic, knd, quite a while ago (October 2018). But things got busy and I never wrote the blog post. So now that we’re all on quarantine lockdowns and have extra time, here’s a very late announcement that knd is now open source!

knd provides the core Kinect backend interface for all Nitrogen Logic controllers. It’s a background daemon written in C with a text interface over TCP. knd provides image, position, and zone data to the rest of the Nitrogen Logic system, and performs the heavy lifting of all 3D distance and location calculations.

A few highlights:

  • Optimized approximated integer math functions using reciprocal multiplication to get 30fps on SheevaPlugs, which lack floating point hardware.
  • Human- and machine-friendly TCP text-based command line interface.
  • Cross-compilation support through CMake.
  • Automatic stack trace printout of all threads when there is an error (not always easy in C, but made possible by nlutils and glibc).

Open sourcing nlutils: Nitrogen Logic's C utility library

libnlutils on GitHub

If you’ve read my previous post, you know that I’m opening up some of the source code from my old startup, Nitrogen Logic. Here’s the first major piece of the Nitrogen Logic source code to go open source. It’s a core utility library used by all of Nitrogen Logic’s C projects, called nlutils.

Because of C’s very limited standard library compared to more modern and full-featured languages, it’s incredibly common for developers to write their own core data structures and helper functions that they use over and over. These include better string manipulation functions, linked lists, associative arrays, etc. – things that we take for granted in languages like Ruby.

nlutils is the set of such tools for Nitrogen Logic’s C projects. Where possible the code adheres to C99 and POSIX.1-2008. The header files are thoroughly documented, so browse around the include/ directory to see what nlutils provides. After meticulously reviewing the code and tests, I’ve pushed it to GitHub under the GNU AGPLv3 license for all to enjoy.

Nitrogen Logic is going open source!

Nitrogen Logic

It’s been quite some time since my last post. I’ve been meaning to write more about my old startup, Nitrogen Logic, but as they say life gets busy. But now seems like a good time to start opening up more of the source code that powered Nitrogen Logic. It’ll be slow going, but the first big C release, nlutils, is already on GitHub.

Since Nitrogen Logic was always a one-person show, there’s nobody but me stopping me from releasing, but also nobody pushing me onward. I figured I should finally take advantage of the rare opportunity to add 5+ years of my career to my public portfolio and to the shared knowledge of our industry.

Any time you open source old code there’s a lot of work involved. In Nitrogen Logic’s case there are several major components to open up, each with its own unique needs, and built on a plethora of different technologies:

cliserver_rust: Learning Rust by reimplementing cliserver with Tokio

Tasks to port cliserver

Lately I’ve been reading about the Rust programming language, just for fun. One of the ways I (and others) enjoy learning a new language or framework is porting an old project into the new language, while trying to take advantage of the language’s features.

So to learn Rust, I’ll be reimplementing my old cliserver example for libevent using Rust’s Tokio crate. At the risk of public embarrassment, I will be tracking my progress using GitHub issues.

Ruby Gems for home automation: nlhue and xap_ruby

Nitrogen Logic code on GitHub

The web interfaces for the Nitrogen Logic depth and automation controllers are written in Ruby. To talk to the Philips Hue lighting system and some other DIY home automation systems, I created two Ruby libraries, nlhue and xap_ruby. I recently converted these libraries to Ruby Gems available from

Both of them depend on EventMachine for fast network event handling, but that also makes them a bit difficult to use. They were developed in a bit of a hurry, follow C rather than Ruby indentation, lack automated tests, and don’t represent the best code quality. Nevertheless they have been battle tested in real products working well for real people, and they may yet be useful.

Continue reading for more information about these gems.

MSSQL MERGE/UPSERT with Ruby and the Sequel gem

My last post contained some code snippets useful for working with an Oracle database from Ruby. I’ve also had to interface with Microsoft’s SQL Server database (to add data to a data warehouse) using Ruby and Sequel. Here’s a snippet for using the MERGE statement with the Sequel gem, useful unless/until Sequel gets official MERGE support. This snippet only supports basic UPSERT functionality, where data is updated when the key is matched, inserted when not matched. It does support multi-column keys for matching.

The code builds the SQL dynamically since it has to insert a different number of parameters based on how many columns are being updated or used as keys.

Make sure you read the code comments from the snippet. Also make sure you’ve read up on how the Sequel gem qualifies schema, table, and column names using double- and triple-underscore.

You’ll need the following gems:

Interfacing Legacy Oracle PL/SQL and Modern Ruby Code

Ruby and PL/SQL GitHub Gist

My last couple of blog posts have been about the backend and middleware work I did at my previous employer. I wrote about two Ruby gems, ClassyHash and HashFormer, that help with data validation and transformation in backend APIs and in middleware. Today we’ll look briefly at some code snippets to help Ruby developers interface with older systems that were written in Oracle PL/SQL, possibly using Oracle applications like EBS (E-Business Suite).

To help launch my previous employer’s updated site, I kind of dove head-first into the deep end of PL/SQL, teaching myself the PL/SQL language, refactoring thousands of lines of legacy code that was not designed with maintenance in mind, and learning chunks of Oracle EBS (both the arcane UI and the even more arcane internal PL/SQL interfaces) over a period of several months. Let my pain be your gain. Continue reading for essential gems, some tips and tricks, and a wrapper script to make the sqlplus command-line interface a little nicer for Ruby developers.

Hashformer: Transform data in Ruby

Hashformer on GitHub

Let me tell you about Hashformer, another open source Ruby Gem I wrote for my previous employer. Like ClassyHash, Hashformer was written as part of the “middleware” interface between a Solidus ecommerce site and an Oracle E-business Suite backend. Hashformer defines a Ruby DSL for basic data transformations, like renaming keys, merging values, etc.

Hashformer is a bit more niche than ClassyHash — most projects probably wouldn’t have a use for it, but when you need it, you need it. It’s similar in spirit to that old four-letter word, XSLT, but simpler and Ruby-centric. Read on for an example.

Data validation in Ruby with ClassyHash

In this post I will briefly demonstrate the ClassyHash gem, which is a fast data validation gem written in pure Ruby. I recently released version 0.2.0 of ClassyHash, with some cool PRs integrated and quite a few new features. Here’s a quick example:

schema = {
  query:'repo', 'user'), # Match either 'repo' or 'user'
  values: [[String]], # Match an array of zero or more Strings
data = {
  query: 'repo',
  values: ['classy_hash', 'hashformer'],
CH.validate(data, schema) # Returns true if the data is valid, raises an error if not

Continue reading to learn about ClassyHash’s history and see a basic ClassyHash validation tutorial.

Resurrecting a dinosaur: the iBIZ KeySync keyboard for Pocket PC

Several years ago I came across a number of obsolete Pocket PC handhelds and accessories at a surplus sale. While the PocketPCs themselves weren’t worth keeping due to the dead batteries and slow processors, I held onto a compact portable keyboard with a 9-pin serial connector made by a company called iBIZ. I’m finally getting around to hooking the keyboard up and seeing if I can get it to work. In this post I’ll document the process of connecting to the iBIZ KeySync keyboard and decoding its protocol.