Joe’s 2016 Holiday shopping guide

2016 has been a unique year.  I know my post is a bit late for Christmas shopping, but here it is none-the-less.

Giving our one and only planet some help:

Giving the gift of civil rights for all (not just old white men):

Giving the gift of a free and open Internet where I can make posts like this:

Posted in environment, government, health, internet, tech, world | Leave a comment

Setting up a work queue with jQuery deferred

So I had an interesting use case and solution this past week with Backbone, collections and server synchronization. The details aside, I needed to keep the backbone collection in sync with what was stored on the server.

It seemed simple at first, just send events back to the server as they occur, right?


Everything in javascript is asynchronous. The UI is asynchronous, the network calls are asynchronous and of course user behavior is asynchronous. A user can edit a field in a row, then quickly remove that row, and you have no control over when the callback to the server completes. The user may have an edit and then delete in process, or worse, a delete then an edit of the same row if the network is busy and the UI has yet to be updated to reflect network transactions in progress. How should the server handle an edit on a deleted row?

So I needed a generic queue that can accept disparate tasks, execute them serially and watch the state of the queue. I needed to potentially not allow some actions until the queue is empty. Thankfully the folks at jQuery provide a nice set of functions to help resolve this issue.

Attached below is a sample queue. I create what will be a linked list of deferred jQuery objects. Each introduced job is followed by a “waitJob”. The queue will pause on each waitJob until it is resolved. The current wait job is stored in the “waitJob” variable, to start, this is the first deferred object.

    var queue = $.Deferred();
    var waitJob = queue;

In this function I add a callback and a wait job to the stack that will need to be resolved prior to executing the next item on the stack.

    var addJob = function(newJob) {
        queue = queue.then(newJob).then(function() { 
            waitJob = $.Deferred();
            return waitJob;

Now we need a method to mark the current wait job as complete. This will resolve the state of the current waitJob, and jQuery will execute the next deferred in the linked list.

    var resolvePending = function() {

Now we just add work:

  addJob(function() { console.log('Hello world, my work is done'); resolvePending(); }); 

Here is sample fiddle of this in action:

And there complete source: deferredTest.html

Cheers and yeah for the jQuery folks!

Posted in internet, javascript, programming, tech | 3 Comments

A year in Seattle

So it’s been about a year since I moved to Seattle from the bay area. (FYI, I am and always will be from Philadelphia, I lived in the bay area for five years.) Now that I’ve spent some time here, I thought it might be good idea to reflect a bit on the experience of being here so far.

You know, It’s hard moving to a new city in the middle of life (ok, maybe one third of the way through). It’s hard being thousands of miles away from all those that you know and love. It’s hard starting a new job and starting over again without any community. My last big move I had roommates and people that worked hard to make me feel welcomed. It was an amazing experience. Seattle is not a welcoming place, especially in winter. But frankly, I wouldn’t want it any other way.

The people here are pragmatic, smart, open minded, very kind and patient. It seems rare to find people in a rush to get anyplace. People complain a lot about traffic and parking, but drive everyplace and refuse to use public transit, it’s really strange. People are obsessed with biking. (as compared to other American cities). People are friendly, but in this weird aloof way. Most of the friends I’ve met aren’t from here. The natives seem to have little interest in showing the new guy around. (I’ll bet my experience would be different if I had breasts) People here are proud of their small city and invest in the relationships they have, and it’s a good thing. To place more value on existing relationships versus forge new ones is a ethos I value greatly, one seemingly missing from the bay area. They also love their coffee and beer, and rightly so, they do it right. They love sunlight and will call in sick when they see it. They love to read. They are dog friendly. They don’t let bad weather stop them. They work hard and are quick to smile even with the drizzle.

The city is very green as a metaphor and not. Most of the energy comes from hydroelectric. There are trees everywhere, the air is fresh and smells of pine and the sea. It’s clean, probably the cleanest city I’ve ever lived in. (except for the gum wall, seriously, that thing is horid). Farmers markets abound, rain or shine they are crowded, everyone recycles. You actually can get fined if you don’t. Hybrid cars seem almost to be the norm. On a clear day you can see 3 national parks from high points in the city. They treasure their natural resources, though it hasn’t always been that way. There is history here, but it’s not all European and colonial, it’s native and the names and many urban spaces reflect it.

So yeah, a hard but amazing and rewarding first year. I’ve made many new friends, learned a lot and grown a bit as well. It’s been an adventure for sure and I’m still excited to be here so long as Seattle will have me.

Posted in culture, life, seattle | Leave a comment

We should work less, not more

I’m paraphrasing a recent Slashdot comment that really stuck a chord with me and galvanized some thoughts I’ve been having for a while.

We have the technology and resources so that people don’t need to work as much as they do, but instead we choose to continue with this outdated concept of “40 hours a week for everyone”. So, what do you do with all these people? Well, you make them spend exorbitant amounts of time in meetings generating data and reports to make them look productive. We are squandering the most glorious time in history in terms of energy resources, technology and machinery in order to maintain an out of date social construct.

  • So many are productive in today’s world, but doing what?
  • What are we producing and for who?
  • What bennefit do these products provide?

We should work and consume less and spend more time being creative.

Posted in environment, government, internet, jaded, life, world | Leave a comment

Working with Apache SOLR SynonymFilterFactory filter

I spent a bunch of time playing with Apache SOLR trying to get multiword synonyms to work. I have a very specific use case where the field I wanted to create synonyms for was a collection of tags applied to the document which could be multiword. I don’t believe this solution would work for an open text field but for replacing one tag for another appears to work perfectly. I had to play with the configuration quite a bit to get the replacement working for phrases of more then one word. So I’ve documented my solution below. Your mileage may very.

I added the filter on the query side of the field definition. If you want to use the filter at index time, you’ll have to use a slightly different syntax in the synonym file. One thing to mention is the use of the tokenizer factory property. You’ll need to set this to “solr.KeywordTokenizerFactory” to stop it from tokenizing the value before doing the synonym replacement. The KeywordTokenizerFactory is weirdly named as it doesn’t actually tokenize anything.

<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="false"

For the synonyms.txt file:

# List of synonyms need to be defined as below if the filter is defined at query time
# Searching for "Replaced Term" will yield documents that contain "Test" or "Two Words".  "Test" and "Two Words" will continue to work as well.
Test, Two Words => Replaced Term
Test => Replaced Term Two
# ....etc....

# List of synonyms need to be defined as below if the filter is defined at index time
# This is so that "Original Term" continues to work as a term
Original Term => Original Term, Test, Two Words

Some links to check out:

Hope this helps some one!

Posted in internet, programming | Tagged | 2 Comments

Programming the NS-500UR Led Sign

I recently purchased the NS-500UR Led Sign from an Amazon reseller for the PLOS Office. I wanted to have it display the latest 10 terms users have searched for given the search engine on our website. It was a bit of headache tracking down documentation on how to communicate to the sign, so I’m publishing my results below.

I did my work in java, code samples below are in java, you could probably however, adapt it to any language. Also note, that this is my no means comprehensive, there is a lot more you can do with this sign then I am going to cover below. All I cared about was display a bunch of short text messages.

First: I used the commapi library to abstract serial communications to java. On linux, this is the command you want to get the source, compile and install into your local java jre:

cvs login
CVS password: (blank)
cvs checkout -r commapi-0-0-1 rxtx-devel
cd rxtx-devel
sudo make install

Once that is set up, you’ll need to figure out what port to use. Code below, compile and execute. It will tell you availible ports, and confirm the above library is working.

package org.plos.ledstatus.util.gnuio;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

public class SerialPort {
  private static final Logger log = LoggerFactory.getLogger(SerialPort.class);

  public static String[] getPorts() {
    List ports = new ArrayList();

    Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();

    while(portIdentifiers.hasMoreElements()) {
      CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();


    return ports.toArray(new String[ports.size()]);

Now that you have a list of ports, and you’ve plugged your sign into one of them. Here is a bit of code to open the port: (I placed this method in the above class)

  public static CommPortIdentifier getPort(String name) {
    CommPortIdentifier portId = null;  // will be set if port found
    Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();

    while (portIdentifiers.hasMoreElements())
      CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();"PID: {}", pid.getName());"PID Serial: {}", pid.getPortType() == CommPortIdentifier.PORT_SERIAL);

      if(pid.getPortType() == CommPortIdentifier.PORT_SERIAL && pid.getName().equals(name))
        portId = pid;

    return portId;

Pretty simple so far eh? This bit of code will send a string to the serial port. Again, I added this static to method to the same class

  public static void sendMessage(CommPortIdentifier portId, String message) {
    try { port = (
        "led-status", // Name of the application asking for the port
        10000   // Wait max. 10 sec. to acquire port


      log.debug("Sending message: {}", message);

      PrintStream ps = new PrintStream(port.getOutputStream(), true, "UTF-8");


    } catch(PortInUseException e) {
      throw new RuntimeException(e.getMessage(), e);
    } catch(UnsupportedCommOperationException e) {
      throw new RuntimeException(e.getMessage(), e);
    } catch(IOException e) {
      throw new RuntimeException(e.getMessage(), e);

Ok, so now we get to the LED specific sign language. There is a lot more here then I am covering, and your mileage may very pending your exact model and release date.

I had to reverse engineer a bit, but the language is quite simple and a message looks a bit like the following. Disclaimer, this was all totally guess work on my part, after watching how their window’s software behaves.


That will display one message with the text “test”. (/r represents a line feed)

    “~128~” Represents “begin message”

    “~f01” Represents “Message 1” (The unit has the ability to display multiple message sets)

    “N” is the transition type. More listed below

    “Z5” sets the transition speed (in seconds) values 1 to 8 are valid

    “Y2” sets the staytime of the message (in seconds) values 1 to 8 are valid

    “s” sets the font size of the message valid values are “s” or “q” (for smaller)

    “rr” End of message

Now I was able to append multiple messages to a given set like so:

NZ5Y1stest one/r
NZ5Y1stest two/r
NZ5Y1stest three/r

Here below are a list of available tranistions:

  • A – Cyclic
  • B – Immediate
  • C – Open from right
  • D – Open from left
  • E – Open from center
  • F – Open to center
  • G – Cover from center
  • H – Cover from right
  • I – Cover from left
  • J – Cover to center
  • K – Scroll up
  • L – Scroll down
  • M – Interlace to center
  • N – Interlace to cover?
  • O – Cover up
  • P – Cover down
  • Q – Scan line
  • R – Explode
  • S – Pacman (very cool!)
  • T – Fall and stack
  • U – Shoot
  • V – Flash
  • W – Random
  • X – Slide in

And that’s pretty much it! Here is a java enum of the transitions:

public enum TRANSITIONS {
    FLASH("V"), RANDOM("W"), SLIDE_IN("X");


  //Annoying: FLASH
  //Takes too long, but cool: SCAN_LINE, SHOOT, SLIDE_IN

  private final String stringValue;

  private TRANSITIONS(final String s) { stringValue = s; }

  public String toString() { return stringValue; }

And another helper class for building up a message to send to the serial port:

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Message {
  private List lines = new ArrayList();

  public static Message create() {
    return new Message();

  public Message addLine(String message, int speed, int staytime, boolean small) {
    TRANSITIONS t = TRANSITIONS.preferred[(new Random()).nextInt(TRANSITIONS.preferred.length)];

    this.lines.add(new MessageLine(message, speed, staytime, t, small));

    return this;

  public Message addLine(String message, int speed, int staytime, TRANSITIONS transition, boolean small) {
    this.lines.add(new MessageLine(message, speed, staytime, transition, small));

    return this;

  public Message addLine(String message, TRANSITIONS transition, boolean small) {
    this.lines.add(new MessageLine(message, 7, 6, transition, small));

    return this;

  public String render()
    StringBuilder s = new StringBuilder();

    //Only support one message for now

    for(MessageLine line : lines) {


    return s.toString();

  private class MessageLine {
    String message;
    int speed;
    int staytime;
    TRANSITIONS transition;
    boolean small;

    public MessageLine(String message, int speed, int staytime, TRANSITIONS transition, boolean small) {
      this.message = message;
      this.speed = speed;
      this.staytime = staytime;
      this.transition = transition;
      this.small = small;

    public String toString() {
      StringBuilder s = new StringBuilder();




      if(this.small) {
      } else {



      return s.toString();



Posted in programming, tech | 3 Comments


I created my first github project. Log4Couch. It’s an appender for log4j that will write logging messages directly to a couch server.

Posted in internet, programming, stoopid | Leave a comment