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 RubyGems.org.

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:

1
2
3
4
5
6
7
8
9
schema = {
  query: Set.new('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.

New Blog Theme

If you’ve come to my blog before, you may have noticed there’s now a new site design. While Octopress is still awesome, my previous Octopress-based blog theme wasn’t a good match for the new design of my main site. This updated design, using Bootstrap with some customizations, pays homage to the original Octopress layout, but provides a more modern look and feel.

I’m a desktop first kind of guy, and even I love the new theme on my mobile devices. I think you will too. Continue reading to see a side-by-side comparison of the old and new styles, and to see some of the other new tricks of the upgraded theme.