Skip to main content
Ben Nadel at BFusion / BFLEX 2009 (Bloomington, Indiana) with: Bob Flynn
Ben Nadel at BFusion / BFLEX 2009 (Bloomington, Indiana) with: Bob Flynn

Recent Blog Posts by Ben Nadel

Using LATERAL Joins To Get "Top N" Records From Each Group In MySQL 8.0.14

By Ben Nadel on
Tags: SQL

One type of SQL query that has been particularly hard, historically, is getting the "Top N" rows for each group in a MySQL aggregation. When MySQL added LATERAL joins in 8.0.14, however, they opened the door for some simple but rather powerful query techniques. A few months ago, I looked at using LATERAL joins to gather row-specific aggregates. In that post, I used traditional aggregate functions like COUNT() and MAX(). But, as I recently demonstrated, MySQL's JSON aggregates (5.7.22+) can be nested for some pretty exciting outcomes. In this post, I want to look at combining LATERAL joins with JSON aggregates to read the "Top N" rows from a GROUP BY query... read more →

Working Code Podcast - Episode 103: Birdsite Go Boom

By Ben Nadel on
Tags: Podcast

Back in April, Elon Musk offered to buy Twitter for $44 Billion. He then spent months talking about how terrible Twitter was before finally taking control in October. Everyone knew it was going to be a landmark moment; but, no one quite knew how things were going to play out. With mass lay-offs, a voluntary exodus of talent, threats of "extreme" work hours, and a series of fraudulent accounts that created a swing in the stock market, it's safe to say that it's been a wee bit of a shit show. It's also pulled-back the curtain, revealing Elon Musk to be more "toxic boss" and less "technology genius"... read more →

Using Picture And Source Tags To Prevent Loading Hero Image On Mobile Devices

By Ben Nadel on

At the top of this blog, I have a rotating hero image of me hanging out with many of the world's most awesome nerds. This hero image renders on desktop devices; but is—for performance reasons—hidden using display:none on mobile devices. Unfortunately, as I discovered this morning, my hero image is still be loaded by the browser despite it never being rendered for the user. To fix this, I am borrowing a technique that I learned from Niels Swimberghe that uses the <picture> and <source> tags to prevent image loading on smaller viewports... read more →

EventSource And Generating Server-Sent Events In ColdFusion / Lucee CFML

By Ben Nadel on

Many years ago, I took at look at the long-polling technique in ColdFusion. Long-polling creates a persistent HTTP connection that blocks-and-waits for data to be sent down over the network to the client. Eventually, this pattern became codified within the browser's native functionality using EventSource. I've never actually played with the EventSource object; so, I thought it would be fun to put together a simple ColdFusion demo... read more →

Working Code Podcast - Episode 102: Migrating Large Databases

By Ben Nadel on
Tags: Podcast

Migrating databases is always complicated. And, the more data that you have to migrate, the more complex your migration process becomes. This week on the show, Adam shares the lessons that he learned while performing a large, multi-client, multi-cluster, week-long database migration for AlumnIQ. This included moving roughly a dozen different databases from Amazon Aurora (MySQL 5) to Aurora 8 by way of Amazon S3. Late nights, indexes, and UTF-8 MB4 character encodings, oh my!.. read more →

You Can Render Anything In Angular

By Ben Nadel on

The other day, I heard someone say something to the effect of: In an Angular application you're stuck doing it "The Angular Way". The person saying this was implying that it's somehow easier to perform low-level programming in React. If anything, I'd argue that the opposite is more true; however, I don't wish to compare Angular to React - I just want to flesh-out what might be a missing mental for some developers. In case you didn't know, in Angular, you can render anything you want. Breaking out of the Angular application life-cycle and performing custom work is relatively straightforward... read more →

Using A Closure To Encapsulate CFThread Execution And Error Handling In ColdFusion

By Ben Nadel on
Tags: ColdFusion

In ColdFusion, I'm a huge fan of using Closures to create a clean separation of concerns between the business logic and the low-level mechanics required to execute a given algorithm. I've used closures for things like managing temp directories, pulling resources out of a connection pool, and implementing distributed locks. And, when it comes to executing CFThread tags, I almost always split my asynchronous code from my business logic. However, it wasn't until the other day that it occurred to me that I could probably use Closures to simplify the execution of asynchronous CFThread tags in ColdFusion... read more →

Working Code Podcast - Episode 101: Error Messages

By Ben Nadel on
Tags: Podcast

Web application developers are notoriously bad about building resilient applications. All too often, we implement the "happy path" and then forget (or simply ignore) the many things that can go wrong for any number of reasons. However, even if we do account for the "sad path", and we do catch and handle errors, it's not always clear how those errors should be presented to the user. Luckily, Tim has some very practical guidance on the matter that he shares with us:.. read more →

Generating Fallback Avatars Using CFImage And ColdFusion

By Ben Nadel on
Tags: ColdFusion

Earlier this week, I talked about proxying Gravatar images in order to serve more aggressive Cache-Control headers in ColdFusion. Another benefit of proxying Gravatar is that I can exert more control over what happens when the given user doesn't have a Gravatar image. Meaning, instead of using the current, default Arnold Schwarzenegger avatar, I might be able to generate a per-user custom avatar. As a first step in this exploration, I wanted to see if I could use the CFImage tag / image functions in Adobe ColdFusion 2021 to generate name-based images... read more →

Working Code Podcast - Episode 100: The Spicetacular

By Ben Nadel on
Tags: Podcast

It's hard to believe that we made it to episode 100! When we, four, started out on this journey almost two years ago, we were convinced that we'd either get sick of each other or quickly run out of topics to discuss. But, here we are, still loving it and having a great time. And, to celebrate this milestone in the most masochistic way possible, we've decided to ignite our guts and destroy our butts with a Hot Ones-inspired Spicetacular! Come for the AMA (Ask Me Anything) and stay for the schadenfreude!.. read more →

Only Solve One New Problem At A Time

By Ben Nadel on
Tags: Life, Work

A few months ago, CodePen co-founders Chris Coyier and Alex Vazquez spent an hour reflecting on the top 10 lessons they've learned over the last decade of work at CodePen. The entire episode is value-packed; but, the one lesson that has haunted me is 6: One thing at a time (jump to track). And, I just wanted to take a moment and amplify their message... read more →

Proxying Gravatar Images For Better Avatar Caching In ColdFusion

By Ben Nadel on
Tags: ColdFusion

When readers leave a comment on this blog, I render an avatar next to their authorship information. This avatar is served from Gravatar, which is (probably) the most popular avatar system on the web (brought to us by the same people who built WordPress). Unfortunately, serving avatars from Gravatar was hurting my Chrome LightHouse scores due to Gravatar's very short caching controls (5-mins). To help improve my LightHouse score, I'm starting to proxy the Gravatar images on my ColdFusion server, applying a custom Cache-Control HTTP header... read more →

Nesting JSON Functions Inside JSON_ARRAYAGG() And JSON_OBJECTAGG() In MySQL 5.7.38

By Ben Nadel on
Tags: SQL

The other day, Joel Hill and I were pair-programming on some complex SQL queries, attempting to figure out how to group rows while simultaneously limiting the aggregation and extracting portions of it. I don't believe that what we were trying to do was possible within a single query (at least not in MySQL 5.7); but, it got me noodling on JSON aggregation. I've looked at using JSON_ARRAYGG() and JSON_OBJECTAGG() in the past; but, I wanted to follow-up with some inspiration from Scott Steinbeck on nesting JSON functions inside JSON aggregates in MySQL 5.7.39... read more →

Working Code Podcast - Episode 99: Technical Debt Isn't Romantic

By Ben Nadel on
Tags: Podcast

This week, I'm super excited to be getting the band back together! After several weeks of personal and professional obligations, Adam, Carol, Tim and I are all back at it again. And today, we're talking about Technical debt. When engineers talk about technical debt in public, they often try to use financial metaphors; such as taking out a loan (debt) in order to buy a house (value)... read more →

Preventing Unbounded Full-Table Scans In My ColdFusion Database Access Layer

By Ben Nadel on
Tags: ColdFusion, SQL

As I've continued to evolve my approach to building ColdFusion applications, one pattern that I've begun to embrace consistently in my data access layer / Data Access Object (DAO) is to block the developer from running a SQL query that performs a full-table scan. This is really only necessary in DAO methods that provide dynamic, parameterized SQL queries; but, it offers me a great deal of comfort. The pattern works by requiring each query to include at least one indexed column in the dynamically generated SQL statement... read more →

CFCookie "Expires" Can Use CreateTimeSpan() In ColdFusion

By Ben Nadel on
Tags: ColdFusion

As I've been trying to build-up my knowledge of how Cookies interact with ColdFusion applications, I noticed that the CFCookie tag accepts a "number of days" in its expires attribute. And, the moment I see "days", I think "time-spans". As such, I wanted to see if I could use the createTimeSpan() function to define the cookie expires attribute in ColdFusion - turns out, you can!.. read more →

Looking At How Cookies And Domains Interact In ColdFusion

By Ben Nadel on
Tags: ColdFusion

In my previous post on leading dots (.) in Cookie domains, I mentioned that my mental model for how Cookies work leaves something to be desired. Along the same lines, I don't have a solid understanding for when Cookies with explicit / non-explicit Domain attributes are sent to the server. As such, I wanted to run some experiments using different combinations of setting and getting of cookie values in ColdFusion... read more →

Leading Dots On HTTP Cookie Domains Ignored

By Ben Nadel on
Tags: ColdFusion

I've been using Cookies in my ColdFusion web applications forever. But, I honestly don't have the best mental model for how the low-level intricacies of cookies work. For most of my career, I only ever defined cookies using a "name", "value", and an "expires" attributes — I didn't even know you could define a "domain" until we had to start locking down enterprise-cookies (by subdomain) at InVision. And even now, I'm still fuzzy on how the domain setting operates; which is why something caught my eye when I was reading through the Set-Cookie HTTP header docs on MDN:.. read more →

A Database Column For "Date Updated" Has No Semantic Meaning, Nor Should It

By Ben Nadel on

When I create a new relational database table in my ColdFusion applications, my default operation is to add three columns: the primary key, a date/time for when the row is created, and a date/time for when the row is updated. Not all entities fit into this model (such as rows that can never be updated); but, for the most part, this core set of columns makes sense. The "updated" column has no semantic meaning within the application - it is simply a mechanical recording of when any part of a row is updated. The biggest mistake that I've made with this column is allowing the customers to attach meaning to this column. This never works out well... read more →

Working Code Podcast - Episode 98: In Defense Of Working On The Legacy Platform

By Ben Nadel on
Tags: Podcast

If you've listened to the Working Code podcast for any period of time, you've no doubt heard me mention the fact that I work on maintaining a legacy platform at InVision. My role on the legacy team was originally focused on security, stability, and bug-related fixed. However, over the years, I've become increasingly aggressive about adding features and actively improving the legacy experience. This has caused no shortage of controversy both internally to the company, and more broadly within the Working Code community. In this episode, Adam plays Devil's advocate and gets me to justify a mode over operation that seems to be—at times—almost in opposition to my company's larger goals... read more →

Considering The "Bounded Context" Of Error Messages In A ColdFusion Application

By Ben Nadel on
Tags: ColdFusion

Error handling in a web application is a deceptively hard concept. I've been building ColdFusion applications for two-decades, and I'm only just now starting to feel like I'm finding helpful patterns that balance complexity and utility. And, I still have so much to figure out. As I've been refactoring / modernizing the code for my ColdFusion blog, I keep running in to unanswered question. My blog has both a public facing system and an admin facing system; and, I'm starting to wonder if these are two distinct bounded contexts for errors and error messages... read more →

Base Tag HREF Doesn't Affect Document Root-Relative URLs

By Ben Nadel on
Tags: HTML / CSS

At work, one of the things that our platform does is generate an offline version of a prototype. The code for generating this offline prototype has to jump through a lot of hoops in order to adjust file-paths for various images, CSS, and JavaScript files. I briefly wondered if I might simply this process by including a <base href=""> tag in the offline template. However, after some experimentation, it seems that the base tag's href property does not affect "Root-Relative" URLs... read more →

Using MailHog SMTP Server With ColdFusion And Docker

By Ben Nadel on
Tags: ColdFusion

At work, we've been using an email testing tool called MailHog. I first learned about MailHog from my co-worker, Shawn Grigson, who added it to our Lucee CFML docker-compose.yaml file some years ago. MailHog provides both an SMTP server for receiving emails and a rather elegant user interface (UI) for reading and deleting said emails. Yesterday, I went to add MailHog into my personal blog's ColdFusion Docker setup; and, I was blown away at just how easy it was to get going... read more →

Working Code Podcast - Episode 97: Expectations Of Professional Software Engineers

By Ben Nadel on
Tags: Podcast

This week on the show, we review Mike Acton's talk, "Everyone Watching This Is Fired", by way of Adam Johnson's article, Expectations of Professional Software Engineers. This talk outlines 50 characteristics - both technical and non-technical - that go into making you and your team fit for building products and dealing with customers. Some of these line-items make us feel seen while others leave us feeling attacked! Listen to find out which ones are which!.. read more →

Rotating Table Headers With CSS Transform

By Ben Nadel on
Tags: HTML / CSS

At work, I have a feature grid (ie, a data table), that is running out of horizontal room. While the icons that denote the features are narrow, the column headers that describe those features are relatively wide. As such, I wanted to start playing around with rotating table headers using CSS transform as means to reduce the horizontal space requirement of each column... read more →

Trying To Get The Most Trustworthy IP Address For A User In ColdFusion

By Ben Nadel on
Tags: ColdFusion

On a recent Penetration Test (PenTest), one of our systems was flagged for not properly validating the X-Forwarded-For HTTP header, which is a recording of the various IP addresses along the network path being made by an inbound request. To be honest, I've never really thought deeply about IP addresses from a security standpoint before; but, having this show up on a PenTest sent me down a bit of a rabbit hole. And, I thought it might be worth talking a bit about why IP addresses pertain to security in ColdFusion... read more →

Router's loadChildren Callback Doesn't Have To Be A Fat-Arrow In Angular 14

By Ben Nadel on

With the release of standalone components / optional modules in Angular 14, I've been trying to dip my toe back in the Angular pool. But, as I was reading up on the Router's loadChildren property for lazy-loading routes, something in the documentation struck me as odd. It states that the loadChildren property needs to use the Fat-arrow syntax:.. read more →

Working Code Podcast - Episode 96: Why Do You Write?

By Ben Nadel on
Tags: Podcast

A year ago, on Episode 36, we talked about blogs and digital gardens. Today, Adam and I, the show's resident authors, dive deeper into how we got started writing, what keeps us writing today, and how the act of - and the engagement with - writing has changed over the years. The advent of Social Media, along with the doubling of new programmers every 5-years, has certainly created a contentious relationship with long-form content. And, is at times, antithetical to our hope of bringing readers along for the journey... read more →

Converting A Query Into A Human-Readable CSV In Two Phases In ColdFusion

By Ben Nadel on
Tags: ColdFusion

The other day, I was having a chat with Adam Cameron regarding a very old (2008) post that I wrote for converting a ColdFusion query into a CSV payload. The code in that post makes me cringe; and represents both a style and a mindset that feels archaic. As such, I wanted to go about modernizing that code. But, as I was rewriting it, I kept running into hurdles. What I realized is that converting a ColdFusion query directly into a CSV is simply not something I do that often. Instead, I use a two-phase process that first builds an Array-based representation of the "report data"; and then, I serialize this intermediary value as CSV (Comma Separated Values)... read more →

Working Code Podcast - Episode 95: Unpopular Opinions

By Ben Nadel on
Tags: Podcast

This week on the show, we tip our hats to the Go Time podcast and have ourselves an Unpopular Opinion potluck. This means sharing ideas in which we feel strongly; but, which may not be so popular in the broader programming community. Topics include password rotation policies (which are dumb), relational databases (which are stupendous), the technical ability of an executive leadership team (which is important), the user experience (UX) of forms (which is often over-thought), automated deployments (which should be based on tags), and code duplication (which can certainly be the right approach)... read more →