Skip to content

Mixing old and new streams in Node.js

Streams in node are awesome. I’ve heard one of the core node contributors say, “if you’re not using streams, you’re doing it wrong”. Why are streams awesome? I’m glad you asked.

  • improve performance for large data sets—stream from source to response without buffering it all in memory
  • improve perceived responsiveness—start responding as soon as any data is available, rather than waiting for it all
  • clean service composition pattern—make a request to another service and stream its response back to the user, filtering or modifying it in some way in the process

However, streaming in node isn’t straightforward. This is more true with the introduction of Stream2, aka “new streams”, since module writers try to support both old and new streams.

I ran into this challenge the other day. After hours of debugging, I realized that mixing stream modes was the cause and I somehow stumbled onto a stupid simple solution. Continued…

Posted in Tutorials.

Smart Scales and Body Fat Measurements

Earlier today, I read a post by Daniel at Needless Pounds where he references a Full Body Sensor Monitor Scale. I commented about their lack of accuracy, but wanted to follow-up on my comment with data justifying my claim. This argument is based on data I’ve personally collected over the last few years. Continued…

Posted in Commentary.

Automating Cloud Applications Using Open Source

Ever wonder about the best patterns for the design, deployment, and monitoring of cloud applications? This presentation describes the current best practices used at BrightTag. Its from a talk given with two colleagues last year at CloudConnect.

Posted in Tutorials.

Fighting Salesforce Web-to-Lead Spam

I was recently tasked with fighting spam coming from contact forms on a website that uses Salesforce web-to-lead feature.

The contact form in question had previously posted to another PHP page which checked for a hidden field with a known value and, if the received value matches the known value, emailed the lead to the team. This is a very basic but effective spam deterrent, as bots tend to change the value of the field. But then the form was redone to post directly to Salesforce with all the data Salesforce needs to create a lead. While this resulted in a much simpler lead-creation process, it also resulted in a lot of spam as the “spam detection” facility was no longer used.

As I was rolling up my developer sleeves to write a simple PHP proxy to do spam detection and then post from PHP to Salesforce, I stumbled on this bit of documentation from Salesforce on their web-to-lead feature:

Salesforce runs field validation rules before creating records submitted via Web-to-Lead and only creates records that have valid values.

Inspired, I decided to try a pure-Salesforce spam deterrent hack. Continued…

Posted in Tutorials.

Urban Opportunities, or Why I Love Chicago

Everyone has heard folks say cities have more opportunities than suburbs or rural areas. Well, until I moved to Chicago 1.5 years ago, I didn’t really know what this meant. I always assumed it referred mostly to jobs, and maybe something about exposure to arts and culture.

But now that I’ve experienced these opportunities, I may never go back. My favorite analogy to describe the phenomenon takes us back to our high school days. In high school, we had a breadth of experiences Continued…

Posted in Ramblin' Thoughts.

Finding Generic Type Parameters with Guava

Over the last year, I’ve ran into a number of cases where refactoring led to a generic abstract base class that accepted its parameter type class in its constructor. Something like this-

public abstract class BaseClass<T> {
    private final Class<T> type;
    protected BaseClass(Class<T> type) {
        this.type = type;
public class ConcreteClass extends BaseClass<String> {
    public ConcreteClass() {

Note the duplication of the type in the generic parameter declaration and in the call to the superclass constructor. Sadly, this is the usual workaround pattern.

Until Guava, finding the parameter type of a generic wasn’t easy Continued…

Posted in Tutorials.

Automating Your Job Search

A friend of mine recently asked about my process when I was searching for a job. Although I briefly described my system, I’m afraid I really didn’t give the time to do it justice. This post is my penance.

When I was preparing to graduate in Fall 2011, I was undecided between building my own startup, joining the corporate world, and academia. Worse yet, I was undecided between four very different fields (education, architecture/engineering, computer science, and electrical engineering) and several focus areas in each (e.g., controls/robotics engineering, telecom/network engineering, software engineering, and sometimes computational cognitive science).  This breadth of interests means I had to cover a lot of ground to figure out my next step.

My first piece of advice: don’t make this mistake – narrow your search. But that’s probably obvious to most people. And if its not, just remember that your first job will not be your last, and in today’s society its common to switch between jobs and even fields numerous times during your life. I mean, I still have no idea what I want to do when I grow up :)

Now onward to the tactical stuff. My goal was to automate as much of the job search as possible. Continued…

Posted in Tutorials.

Automatic model validation using Jersey, Jackson, and Hibernate Validator

So you have a RESTful Java webapp built using Jersey, some POJO/JAXB models that you’d like to serialize using Jackson, and think it’d be sweet to validate models using annotations (JSR 303 – Bean Validation)? And you like your objects to be immutable (Effective Java Item #15). You’ve come to the right place. Hibernate Validator is the reference implementation for JSR 303 and arguably the best currently available, so we’ll use it along with Jersey and Jackson to form the backbone of this recipe.

The general idea behind the ValidatingJacksonJsonProvider is that we can annotate any of the parameters used in our resource classes with @Valid to have the object automatically validated during the Jackson JSON serialization process.

So, first, annotate your POJO/JAXB object with some constraints, like @Min(0) and @NotEmpty. Continued…

Posted in Tutorials.

Mocking static java.util.Logger with EasyMock’s PowerMock extension

We have a class that needs to limit the number of logged messages to avoid DDOSes. But this particular piece of software is still using JULI (yes, I know, not my decision though). Since JULI doesn’t support NDC or MDC, we needed to get creative to test this logging limit.

You probably create a static logger for your class, something like

public class LoggingClass {
    private static Logger logger = Logger.getLogger(LoggingClass.class.getName());

or the equivalent with SLF4J’s LoggerFactory.

PowerMock can help you mock this logger. Yes, its that powerful. First, Continued…

Posted in Tutorials.

Book Review: Forging Truth

After a number of years away, my love of reading (non-textbooks) has returned. In the last two months, I’ve finished 6 or 7 books. Last one was probably five years before. Ok, maybe an exaggeration, but you get the picture.

One of the books that got me back into fiction was Forging Truth, by Raymond Masters. (disclaimers below)

Although I expected Forging Truth to be a typical fantasy/sci-fi piece, it ended up being a big mystery as well. It was this aspect that hooked me from the end of Chapter 2. The protagonist (and the reader) go through a journey of discovery, trying to recover his lost memories that are key to solving a crime against humanity. The book twisted and turned til the end, feeding you just enough information and back-story to keep you intrigued but not so much that the next pages were obvious.

Situated in present-day America, the novel was centered around subjects normally reserved for other (usually more medieval) contexts. This juxtaposition made for a very interesting read. Given this modern context, the language was easy and the approach to magic was “light” (i.e., unrestricted, not manna-based, etc.). However, the actual content/subject matter was a bit darker in nature, with some moderately graphic scenes. Action-packed til the end, this book left me hanging for more. Can’t wait to read the second book!

disclaimers: the links above are Amazon-affiliate links and the author is my uncle. :)

Posted in Commentary.

Log in here!