Object Namespace Manager on node.js

I’ve been porting the Object Namespace Manager library (formerly ONMjs, now simply onm) from a global namespace implementation to CommonJS and working on a Grunt-based build strategy. Here’s what I need to do:

  • Maintain the onm source code, in CoffeeScript, using a single module format. I’m thinking this will be CommonJS. But, we’ll see.
  • Generate debug and release CommonJS packages for node.js/npm.
  • Generate debug and release packages for the browser using (likely) AMD/RequireJS, and possibly a global namespace option for pure HTML clients that leverage an AppCache manifest for this JavaScript.

onm on node via npm

Going forward, the Object Namespace Manager (onm) will be distributed via the npm package for node.js.

npm install onm

Or, to save onm as a dependency in your package.json:

npm install onm --save

using onm on node

// index.js
var onm = require('onm');
var dataModel = new onm.Model({ jsonTag: "testNamespace" });
var dataStore = new onm.Store(dataModel);
console.log(dataStore.toJSON(undefined, 2));

… will print to the debug console log:

{
  "testNamespace": {}
}

consuming public onm data models via npm

In essence an onm data model declaration defines a data exchange protocol. To make your data exchange protocol public, package your onm data model declaration as a node.js package and publish it via npm.

For example, I’ve published the node package onmd-scdl for a complicated data model called Software Circuit Description Language (SCDL). The details aren’t important. What is cool is how easy it is for you to work with SCDL data now.

Do a little setup:

mkdir test && cd $_
npm install onm
npm install onmd-scdl

Now a little code:

// index.js
var onm = require('onm');
var scdl = require('onmd-scdl');
// Default construct a SCDL object store.
var scdlStore = new onm.Store(new onm.Model(scdl.DataModel));
console.log(scdlStore.toJSON(undefined, 2));

… execute the node program:

node index.js

… prints the following JSON to the console log:

{
  "scdl": {
    "catalogues": {}
  }
}

Generically, that is without regard to the data model, the onm package provides object create, remove, enumerate, traverse, introspect, address, observation, and and serialize services via its API (https://github.com/Encapsule/ONMjs/wiki).

So there’s a lot more that we could have done in the above example.

Here’s a more complicated example that leverages the onm package API to affect data model introspection and initialization of test SCDL data set.

GitHub: https://github.com/ChrisRus/scdl-data-model-demo

onm in the browser

I’m between solutions for the browser as of this writing. The current onm package build (based on Grunt) produces a single-file JavaScript file for use in the browser via grunt-browserify. I have not tested this yet. And, I may never.

I’m looking at uRequire as a possible way to achieve the single source code base, multiple build target scenarios I have in mind of onm package’s Grunt build.

Posted in Compute, Internet, Open Source, Software | Tagged , , , , , , , , , , | Leave a comment

Weird Chome/Chromium Rendering Problems in KDE 4.11.2 under VirtualBox

I recently upgraded to VirtualBox 4.3.4 on a Windows 7 host machine and noticed a bunch of strange rendering problems with Chrome/Chromium in Debian and Kubuntu Linux guest instances running the latest stable KDE 4.11.2.

Symtoms:

  • Whenever Chrome opens a modal dialog box, it is rendered _below_ the active window (i.e. not visible). Because it’s modal, Chome appears to hang.
  • When the modal dialog is displayed, dragging the outer frame of the Chrome window shears: the tab remains in-place during drag and the frame moves. Releasing the drag snaps the client area of the tab back into the correct coordinates making the previously invisible modal dialog visible.
  • This same “shearing” (due to what I believe is a Z-order bug) is manifest in drop-down menus, and also when moving other non-Chrome app windows over the tab client area of a running Chrome instance. The client area of the active tab appears to remain pinned at the top of the Z-order.

I tried re-installing the VirtualBox guest additions, and even switched Linux trying to get out from underneath this problem. Finally, I tracked down some useful information:

The relevant tip is to modify the google-chrome.desktop file to add the –blacklist-accelerated-compositing option to the end of the exec lines (see first link above for details).

This is preferable to completely disabling VirtualBox 3D acceleration. I’ve only seen this problem with Chrome/Chromium (so far).

Posted in Compute, Software | Tagged , , , | 1 Comment

Baseline Web Development Environment on Debian 7.2.0

Installed a fresh copy of Debian 7.2.0 in a VirtualBox VM and am gong through the process of setting up a web development environment on top of this Linux distribution. FWIW, I like KDE and am using it instead of Gnome on Debian.

I’ve already installed Chromium browser. Also, if you’re new to Debian and wondering WTF Firefox, it’s Iceweasle (should be perfectly obvious right?) Google it if you’re curious. I was.

Step 0: Become member of sudo group

As root, adduser username sudo

If su’d, exit, logout/login user to get sudo group priviledge.

Step 1: Node.js

Node.js is too fast moving for Debian package support so you need to do a little work. Helpful stackoverflow thread: http://stackoverflow.com/questions/10478768/installing-node-js-on-debian-6-0

I’m following the instructions here: http://sekati.com/etc/install-nodejs-on-debian-squeeze. Credit: Sekati


sudo apt-get update && apt-get install git-core curl build-essential openssl libssl-dev
git clone https://github.com/joyent/node.git
cd node

# 'git tag' shows all available versions: select the latest stable.
git checkout v0.10.23

# Configure seems not to find libssl by default so we give it an explicit pointer.
# Optionally: you can isolate node by adding --prefix=/opt/node
./configure --openssl-libpath=/usr/lib/ssl
make
make test
sudo make install
node -v # it's alive!

# Lucky us: NPM is packaged with Node.js source so this is now installed too
# curl http://npmjs.org/install.sh | sudo sh
npm -v # it's alive!

… which works like a charm.

Note: I’m seeing a single failure in the make test step currently (64-bit Debian and Ubuntu-based distros). I’m not sure what the impact of this is. Seems like the issue is known: https://github.com/joyent/node/issues/5343

Step 2: CoffeeScript

http://coffeescript.org/

sudo npm install -g coffee-script

Note: You might be setting up a new VM? Better make sure that that your ~/tmp directory ownership is correct; if the first use of ~/tmp is as root then it will be created with root ownership and later when you try to npm install later you’ll get an EACCES error…

Step 3: Emacs

because old habits die hard

sudo apt-get install emacs

Step 4: Yeoman

http://yeoman.io/gettingstarted.html

… and follow the directions remembering to sudo all those npm install -g ‘s!

This will get you Yeoman, Grunt and Bower installed.

Edit: Glad I took the time to write these steps down because when I came back this AM to continue on, I hit a nasty unresolved bug in VirtualBox 4.2.18 r88780 that made the saved VDI boot media inaccessible.  The only way to work-around was to loose the latest VM state and revert per directions posted here: https://www.virtualbox.org/ticket/11750

http://beshoy.girgis.us/2012/11/virtualbox-ubuntu-chrome-rendering-issue/#comment-136
^— possible fix for annoying rendering problems with Chrome/Chromium under KDE executing in latest VirtualBox 4.3.4 (works for me).

Posted in Compute, Internet, Open Source, Software | Tagged , , , , | Leave a comment

So You Want Your JavaScript Library to Run Everywhere?

Guess this is going to be a running-edit post as the more I dig, the more I find… Damn it, this should be easier.

Originally I wrote:

A very helpful post on SitePen.com: Run-Anywhere JavaScript

All I have to say is what a #*&^Q mess… Suppose it’s not too bad once you work through the details and arrive at stable implementation pattern for your library but it’s a serious mess if you just wander in cold off the street and try to understand the various JavaScript module packaging options in use.

One fairly straight-forward example that seems to cover the bases is is available in the node-uuid module (boofa/node-uuid) on GitHub. I’m reading the SitePen.com blog post in one browser instance and looking at the node-uuid source in another to audit my understanding. Helpful.

Edit (and I’ll leave it here and cover what I learn in another post):

node-uuid seems to be leveraging a boilerplate approach. The SitePen.com blog post is several years old and the most recent comment (a year old) on uRequire appears to be the correct vector from my starting point in the zone of ignorance.

This also will drag me through several topics on the list of things I need to know. For example Yeoman (and everything else required to set up an actually defensible/sensible build and test environment for the ONMjs library which today, although it “works” in the browser, and encapsulates a bunch of really useful ideas (says me) is not the holistic little generally useful library I want it to be).

Posted in Open Source, Software | Tagged , , , , , | 3 Comments

MacBook Pro Trackpad Goes Berserk, Fixed By SMC & PRAM Reset

The trackpad sensor on my 2011 MacBook Pro recently went berserk making my laptop virtually unusable. I had read about the device’s sensitivity to moister and was concerned that I had damaged the sensor recently by getting a few rain drops on it.

Problem symptoms: random cursor movement, random clicks, failure to recognize or correctly identify mutli-touch gestures…

First thing I tried was to shut the laptop down, covering the keyboard with a phone book, and letting the unit sit with rice poured over the trackpad for 30-hours in an attempt to dry out any moister that could have worked its way into the trackpad sensor (water droplets can easily get through the seam around the trackpad). But this didn’t work.

I then tracked down directions to reset the unit’s system management controller (SMC) and reflash its internal PRAM. This worked like a charm for me. I’m not exactly sure what went wrong but this latest procedure solved my problem.

Here’s what I did to reset the SMC and PRAM:

Note: These directions are specific to unibody MacBook’s that do not have a removable battery. If you have a different model MacBook, you’ll need to track down the model-specific “secret handshakes” required to affect SMC/PRAM reset. Also, make sure your data and hard work is backed up! I had no problem that does not mean you won’t.

SMC Reset

  1. Plug the unit in and ensure it’s powered OFF
  2. Press and release LEFT-SHIFT + CTRL + LEFT-OPTION + POWER and then release

PRAM Reset

  1. Ensure the unit is powered OFF
  2. Press and hold LEFT-COMMAND + LEFT-OPTION + ‘P’ + ‘R’ + POWER (continue to hold this key combination through the power-up boot cycle)

If you have a similar issue, hopefully the above procedure works for you as well as it did for me.

Proactive Tip

Note that in OSX Mavericks, in System | Accessibility you can select an option that disables the trackpad if an external mouse is connected (e.g. Bluetooth). I’ve selected this option proactively so that if this ever happens again, simply connecting my Bluetooth mouse will disable the trackpad and allow me to use the laptop.

Good Luck!

If this doesn’t help you, your trackpad might actually be fried. Nobody would give me an exact quote but ballpark you’re looking at $150+ repair and a week w/out your MacBook. Or, $50-75 in parts and an afternoon watching YouTube repair videos and tinkering with small screws to affect the fix yourself.

Posted in Compute, Devices | Tagged , , , , , | 4 Comments

TodoMVC, Model-View-Whatever, and MSOFS

One of my local tech meetup acquaintances showed me TodoMVC.com last night while we were discussing my new ONMjs library. The purpose of TodoMVC.com is to help developers compare and choose among the many open source model-view-* pattern frameworks available today as FOS JavaScript libraries.

TodoMVC presents a simple Todo application template, and challenges the MV* framework authors to implement the missing functionality with their library and then add it to the growing list of options. That’s a cool idea and there’s a lot to be learned by going through the examples and backing source code.

The suggestion was that I should take the challenge and write an ONMjs-based Todo app and bring it to the party. But is ONMjs a model-view-controller (MVC), model-view-view-model (MVVM) or model-view-whatever framework? Or, is it something else entirely?

The short answer is OMNjs is neither a MVC nor MVVM framework.  It’s an MSOFS framework. MSOFS?

MSOFS

MSOFS is an acronym that stands for Model-Store-Observe-Feedback-Signal that you have never heard of because I made the moniker up. In spirit MSOFS builds from and derives from the core concepts of MVC but is more granular, and pedantically insists on using the term ‘model‘ in its canonical sense to mean “a schematic description of a system, theory, or phenomenon that accounts for its known or inferred properties and may be used for further study of its characteristics.”

I think in patterns and consider all efforts to codify general truths worthy. But computer scientists need to stop forking the language and work harder, and think more deeply about explaining these truths in terms that don’t force us all to remap the lexicon depending on what we’re reading and who we’re speaking with. Parenthetically there are others who share this pet peeve of mine, but seemingly we’re a small minority.

 Let’s break MSOFS down into its constituent parts and discuss each in relation to patterns and concepts that are likely familiar to everyone who made it through the first paragraph of this post.

Model – a data model, or model for short, describes the structure (as in topology) and properties (as in attributes) of a data structure in sufficient detail such that a generic software algorithm can manufacture an instance of the modelled data structure, traverse its hierarchical structure, and ascertain if an instance of some randomly sourced data structure instance conforms to the constraints embodied by the model.

Models in MSOFS do not encapsulate the details of operating on an instance of a data structure as they do in MVC. MSOFS models do not take commands; they are used for reference when constructing, traversing, and validating data. As well, models are the basis of data introspection and addressing – two extremely powerful allies in the never-ending battle to write less, more generic, easily testable code.

In the ONMjs library implementation of MSOFS, models are simple JavaScript objects that adhere to some simple syntax and structure rules. That’s it. No magic.

Store – a data store, or store for short, stores an instance of a modelled data structure and embodies the generic algorithm mentioned above that leverages the model to automate the construction, initialization, traversal, and validation of the data instance it contains.

You can liken a MSOFS store to a little industrial robot that does what it does according to an external program without any concern or knowledge about what it’s actually doing. A MSOFS store, like a robot, is designed to perform a fixed set of generic (although not necessarily trivial) functions, is specialized to the task at hand by an external program, and is controlled by external operator.

In the ONMjs library implementation of MSOFS, a store is represented by a run-time instance of the generic ONMjs.Store object. ONMjs.Store implements the generic functionality described above, is specialized by a MSOFS model,  and controlled externally by your application via its API.

In slightly more detail, ONMjs.Store exposes a simple API that allows you to add, remove, enumerate, access, and introspect the data contained within the store. Additionally, ONMjs.Store’s API provides a sophisticated implementation of the observer pattern that your application leverages to monitor and react to changes in store’s contained data.

Readers familiar with the concepts of inversion of control (IoC) and dependency injection will recognize a lot of similarity between a MSOFS store and an object assembler.

Observe – a MSOFS observer is an application-specific subroutine that is called by an ONMjs.Store instance to notify the subroutine that its contained data has been modified. At a high-level of abstraction writing observer subroutines is very similar to writing an event handler that responds to the occurrence of some semantically meaningful condition (e.g. the addition or removal of an object from the store, the mutation of a property value…) in some application-specific way.

MSOFS is deliberately vague about the specific role of observer subroutines. Unlike MVC that formally defines the responsibilities of controller and view subsystems, MSOFS is agnostic to this distinction. This is not because MVC’s formal notion of view and controller is flawed but rather because MSOFS deals at a lower level of abstraction. This means that a MSOFS observer subroutine may occupy either, both, or neither of these roles.

I am personally fascinated by recursive design patterns that can be re-applied at various levels of abstraction because they afford such great opportunities to write generic and re-usable code. MVC is recursive pattern but in my experience it’s rather difficult to build and maintain hierarchical MVC’s (e.g. the top-level MVC’s model is itself an MVC and so on…) As well, attempting to document and explain the details of such systems is an onerous task.

MSOFS suggests a more granular, lower-level separation of concerns, roles, and responsibilities  than MVC  that, to my way of thinking, is much simpler to  understand and apply recursively .

Feedback – feedback is the act of mutating the data contained within a MSOFS store. The term was chosen because it is typical in systems that leverage the MSOFS pattern that data mutation is affected by MSOFS observer subroutines responding to a data change event. Insofar as data mutation originated the change event in the first place, an observer who reacts by further mutating the data establishes a feedback loop.

Feedback is not solely limited to observer subroutines however. Routines that handle user input, network request completion etc. that mutate the contents of a store are also considered to be part of the feedback loop.

Signal – MSOFS signals are essentially callbacks to observer routines dispatched by a store in response to a data change event. Data change signals differ from data change events in that a change event actuates, typically, more than one signal.

For example, the addition of a new data object instance to a store is considered a change event that initiates multiple signal callbacks. Specifically, adding a new data object to a store dispatches a series of signal callbacks notifying observers of the addition of the object, its constituent namespaces, and the modification of parent objects and their namespaces.

MSOFS in Action

My new ONMjs library is based on the MSOFS pattern and is now available on GitHub (sources, documentation (in progress), and download links).

Edit: Since I wrote this post I’ve received some great feedback alerting me to all kinds of stupid rookie JavaScript ECMAScript mistakes manifest in the  ONMjs implementation. ONMjs is not production code yet. This post coincides with v0.1.00 alpha release and is intended primarily to foster discussion about  the MSOFS  pattern and the ONMjs API. Performance issues notwithstanding, the API is unlikely to change much if at all based on the feedback I received so far.

Additionally, I’ve posted several simple JSFIDDLE projects that demonstrate these concepts in action.

I’m still on the fence about building an official TodoMVC app (we worked out the basic data model and built a functional todo list (minus routing and persistence) in about 5-minutes last night using ONMjs and I sort of lost interest after that because it’s not really a big enough problem to merit all the abstraction). But I should probably do it as a learning exercise (when I’m done with the library docs…)

MVVM

I mentioned the Model-View-View-Model (MVVM) pattern earlier this article but focused mainly on Model-View-Controller (MVC) in the discussion above because it’s more widely known and more closely related to MSOFS than is MVVM.

As an aside, I’ve spent quite a lot of time this year playing with the fantastic Knockout.js MVVM framework and highly recommend this library for client-side UI work.

The way I’ve been using Knockout.js is rather unique however. Rather than relying on MVVM to manage my data, I leverage MSOFS (via ONMjs) to manage my data and leverage observers to initialize and update my model views, and select view models in response to data change signals.

Using these two patterns together is extremely powerful. In particular ONMjs’ support for data addressing and introspection allows me to author exceptionally flexible and re-usable Knockout.js code.

You can see a ridiculously complicated and abstract example of this in action in the Encapsule Project Schema HTML 5 SPA that currently comprises several data models, and a dozen or so lines of JavaScript code that initializes ONMjs and connects all the observers that are 100% generic (i.e. they leverage introspection to adapt dynamically to whatever data model you throw into the app). It’s currently kind of a mess (sorry) but at this point it’s really nothing more than a fancy test harness for ONMjs and the observer subroutines I’ve written with Knockout.js.

Comments & Questions?

I would welcome comments and questions on this article but not here on this blog please. If you’re interested in this topic and have questions I’ve set up the ONMjs Google Group for this purpose.

Posted in Compute, Internet, Open Source, Software | Tagged , , , , , , , , , , | Leave a comment

GoIntoTheWoods.com

Here’s a great web app for locating trails in Washington State. According to what little information is available from the authors, they’re leveraging data from the Washington Trails Association website and overlaying on the map with killer search features. Very cool.

http://www.gointothewoods.com/

Posted in Hiking, Outdoors, Sport | Tagged , , | Leave a comment