I recently had the pleasure of presenting at Bethel Middle School’ yearly career day. It was the same fare as last year: explain front-end and back-end programming, describe my own job, show some examples, deal with students that were either too loud or too quiet, and make cryptic remarks how my sister was likely their English teacher.

Something I made specifically for this was a tic-tac-toe game written with JavaScript. My goal was more than the opponent randomly selecting open squares - it actively tries to block the player’s wins and take its own. We played a couple rounds, I explained some of the code, showed them said code, got uncomprehending stares, felt a bizarre satisfaction, and repeated.

In this post I thought I’d explain the general structure of the game’s code. I could explain the specifics, but that’d take away the fun of discovering it yourself, wouldn’t it? But I will write how, despite the complexity, I kept it maintainable, organized, and DRY.

Using Containerized JS

Containerized JS is a pattern a past colleague taught me to keep JS functionality from leaking out. While working on a Pattern Library, we had issues where one component’s JS was inadvertently affecting others. This happened even more with multiple component copies on that page, and click events hit each one in the DOM.

This pattern fixes that by limiting all JS to the DOM within that component, “containing” it to stop leaks. The basic structure I use is below:

function containerized_function(patternId) {
    let pattern = $("#" + patternId);

    // Consistent component variables
    const v = {};

    // Reusable functions, used frequently the component
    const f = {};

    // What to do when the page loads
    function init() {}

    // Events triggered by the user, mostly click events
    function setEvents() {}

    // Running the initial and event functions when page loads
    function docReady() {

    $(document).on({ ready: docReady() });

$(".component").each(function() {
    var id = $(this).attr("id");

    if (typeof id === typeof undefined && id !== false) {
        id = "IDUNIQUE_" + Math.floor(Math.random() * 999999999999 + 1);
        $(this).attr("id", id);


First is the “containerized function” - that’s where the most important stuff happens. There’s a few important parts to be aware of:

  • pattern is declared right from the start, storing the components entire DOM for easy reference. We’ll come back to common uses for it in a bit.
  • const v stores any consistent variables for the component. For example, if an array of strings must be used or mapped in several events, I’d place them here. It’s stored in the variable v so it’s easy to reference. When someone sees v.bank_limit, they’ll know it’s a consistent variable outside of that specific event.
  • const f is the same as above, but with consistent functions. Any frequently used mapping or calculation functions go here, stored in a similar variable for the same reasons.
  • init() is for any functionality triggered when the component first loads before anything else. I access the DOM through the pattern variable, such as pattern.find('.element').text('new text here'); This ensures I change the DOM of that specific component and nothing else.
  • setEvents() is where most of the important stuff goes - click events. Triggers are also set through the pattern variable. For example, pattern.on('click', '.element', function(){ ... }); sets a click event for the targeted element only in this component. This syntax works even if the initial DOM changed.

After that, that small bit of code below does the rest. It scans the page, finds every components for the function, gives them unique IDs (if they need them), and runs the function.

There you go! Each component has that functionality contained in its own DOM. Even with several on one page, the functions and variables are independent of each other.

There’s some obvious benefits to all this:

  • It’s very modular, easy to add and remove into a project without complications. In the containerized function itself, each piece - variables, functions, events - are separate and easy to organize.
  • The pattern’s scope is limited to avoid accidental triggers in anything else.
  • It can be easily used as a JS module. The code triggering the containerization can be separated like this:
exports.component_init = function(selector, component_function) {

    var id = $(this).attr('id');
    if ( typeof id === typeof undefined && id !== false ) {
      id = 'IDUNIQUE_' + Math.floor((Math.random() * 99999999999999999) + 1);;
      $(this).attr('id', id);

In the JS file with the containerized function, it can then export the function:

let f = require('./functions');

function containerized_function(patternId) {
    // Function stuff goes here!

exports.activate = function(selector) {
  f.component_init(selector, containerized_function);

Finally, you’d require and use it in your main file with the selector:

let component = require('./component');


There it is - easy, portable, and customizable.

Containerizing the Game

The final result using this pattern worked nicely and is on CodePen. Here’s a broad overview of what’s in each part of the containerization:

  • The variables have frequently referenced game data: all the board positions, winning combinations, and near-winning combinations. I wound up writing out all 24 near-wins, along with how to win them, so it’s the largest variable by far - but also the most important for a challenging game.
  • Functions is vital since it has several key pieces: checking if the match is over, letting the player or opponent select a square, finding what spaces are open, and so on. Most are simply shortcuts for getting info, often using the variables and board DOM, and only a few change the visible game.
  • No init functions needed here.
  • As you may have guessed, there’s only one click event: when the player makes a move. It references variables and functions already made, so creating the event itself is easy.

The final game is below - scroll through the JS and play a round or two!

See the Pen Tic Tac Toe by Maxwell Antonucci (@max1128) on CodePen.

In Conclusion

This containerization pattern didn’t make the code for key game functions any easier to figure out. Having the computer play smarter than some random square selection still gave plenty of puzzles to solve and walls to bang my fist on. But it did give an easier structure for laying out all the different puzzle pieces and putting them together.

So if you’re coding in a modular environment, especially something like a pattern library, and need a reliable JS component pattern, this one’s definitely worth a try!


To this day, one of my favorite online articles is The Oatmeal’s comic on being “Perfectly Unhappy.” For a while I wasn’t sure why. Could have been his usual humor and insight was better than usual. Or I read it for the first time while in a good mood.

But I’ve found the real reason: I’m not a happy person either.

This doesn’t mean I’m miserable or don’t like my life. But the parts of my life I enjoy the most don’t fit common definitions of happiness.

I remember going to a typical party event in college. There was a big crowd of students, a band playing music, alcohol passed around, and lots of visible skin. It all felt pleasant, but I didn’t feel happy. Instead I felt stale and self-indulgent. I was zoning out in my own little world. I’m not saying it was boring and others should have felt that way. That’s how I reacted to it.

The basic gist of my thoughts during it was I felt the gathering lacked meaning. Lots of people indulging in whims and pleasures was enjoyable. But it was also meaningless. People were just following their base desires. I realized I cared more about meaningful activities than happy ones.

But I had no idea what I found meaningful.

Tear Myself Apart, Put Myself Back Together

Since leaving college, I’ve been searching out activities I find meaningful. Whether they make me happy is secondary.

And I’ve found that meaningful activities are ones that make me a better person. Even if I’m not too happy doing them. Even if it’s painful.

Sometimes it’ll feel like I’m beating myself down or tearing myself apart. But I’ll put myself together and be a little better than before. In a physical, mental, or emotional way. But it makes what I did feel meaningful. Like I made good use of my time on Earth. It wasn’t wasted remaining the same while everything else around me kept on moving. I moved forward in some way. Any way.

All the things I love the most fit this in different ways:

  • Coding - Coding is puzzle-solving. There’s an endless supply of puzzles it gives that may or may not be possible. With most I likely can’t tell which it’ll be from the start. It’ll be a rough time figuring it out. So I need to prune and update my knowledge constantly. Learning nothing will make me useless in a few years. I whack my body of knowledge with a hammer to check for weak spots. I feel the stress, repair them, and do it again.
  • Reading - I enjoy reading things many people wouldn’t like. Things that make my heart squirm and my brain yell. New ideas I’d never considered that shake up my head. They make me question my core philosophical, political, and religious views. They push my mind into turmoil. I discard everything I’d accepted as normal and start building again. Only to break it all again later for something stronger.
  • Boxing - Boxing is an easy sport to push myself in. Each workout lasts eight rounds. At the end of each I’m covered in sweat, I’m sore, and sometimes fall over. My knuckles will be cut, my core aching, my legs trembling. The rest of the day, I pull my body back together. Then I do it again in a day or two.
  • Volunteering - I helped at a soup kitchen a few times in college. I’ve started doing so again after work. It’s tough to see another side of society I’m rarely exposed to, even if it is to help. To see people struggling, and be greeted with everything from thanks, indifference, or hostility. But it makes me question my own perspectives on life as a whole. What matters to me, what I should care about, and how I should (and shouldn’t) judge others. My heart gets twisted and I try to straighten it out before I return.

All these meet my definition of meaningful, so I’m drawn back to them. But they usually don’t make me happy.

They make me feel frustrated and inadequate, insecure and lost.

They make me feel astounded and intrigued, busy and complex.

They make me feel like a human going headfirst into the turmoil of existence. Seeing a spectrum of ideas and feelings that push me up, drag me down, and toss me somewhere else. To find something new. To struggle with a new obstacle. To discover a new strength.

Most of all, they make me feel I’m making the best possible use of my time alive.

So like The Oatmeal, I’m not happy by the typical definition. And that’s okay.

It's easy to see why pattern libraries are useful, but tough to successfully maintain them over time.

Before you share an opinion on any topic, ask yourself the following questions.

  1. Have I invested enough research into this opinion? Did I take the time to research relevant info by myself? Or did I hear something once with little support and abruptly agree with it? Is this an opinion I take seriously myself, or am I just following a herd?
  2. Have I used reliable sources for my data? Am I referencing sources with none or minimal bias? Did I check if there’s any proven, verifiable conflict of interest that’d make me distrust this source? Do this source’s fact justify their viewpoint, or does their viewpoint justify their facts? Am I checking these resources against other reliable ones? Am I holding this view just because someone who seems reliable said it, and didn’t check if they really are?
  3. Did I look at any opposing arguments? Have I looked at serious, reasonable counter-arguments to this viewpoint? Were the counter-arguments serious or resort to childish arguments like attacking the one making the argument instead? Am I willing to concede good points from the opposing side and moderate my position accordingly?
  4. Did I check my biases? Do I have any beliefs affecting my judgment? Am I looking for selective facts to justify a viewpoint I already have? Am I avoiding arguments that make me question my beliefs? Am I examining where my biases come from and how valid they are? Did I make sure I don’t have a strong emotional attachment to my opinion that keeps me from doing any of this?

Most importantly, am I willing to critically re-examine my views and admit I’m wrong?

If you didn’t do any of the above, but still feel you have a right to your opinion, so be it. But know I’ll have the right to take your opinion as seriously as you have and ignore it.

January 20, 2017

Rest is not Laziness

Rest is not laziness. Rest is long-term productivity.

Short-term productivity is cramming as much work into as little time as possible. It leads to burnout and no good habits are built. It often stems from a burst of inspiration that doesn’t last, and can’t be sustained. One feels so good after that burst, they often stop and lose all their progress.

People focus on short-term productivity when they don’t rest. No work happens when one rests, so it’s easy for rest to feel wasteful. How can one be productive when they waste time doing nothing useful?

But rest is productive, since rest is what turns the snipped thread of short-term productivity into the continuous, winding thread of long-term productivity. The progress builds into serious change, habits form to keep this change growing with little effort, and that burst of inspiration becomes a steady stream of principle.

Productivity is an endless jog. Go full speed and you’ll soon collapse and lose your momentum. To get moving again it feels like you’re starting over and will likely never finish. It’s important to go at a reasonable and steady pace, taking deep breaths, and hydrating and slowing down when needed. That’s how muscle gets built, large progress is made, and the finish line is reached.

Resting doesn’t make someone lazy. Productive people know proper rest, at the right time and place, and makes them more productive in the long run.

Don’t feel lazy and undeserving for taking the time to rest. As long as you remember to get back to work once you’re rested.


I’ll be honest, I prefer being an adult.

Some of my friends were so anxious about adult life, they considered studying more just to avoid it. I was a third through senior year at Syracuse University and was eager to graduate. I’d found a new career I enjoyed, and was tired of required classes and resume polishing. I wanted to give the adult side of life a shot.

Plus, my nightmares about getting lost in high school hallways before class, not studying for tests, or forgetting projects by due dates become much less scary.

Now I’m relieved adult life is actually better than school life for me. I focus more on what I enjoy, work deadlines are still important but happen less, and I don’t get meals from vending machines. Some bits I don’t like, such as paying for food and insurance, dealing with car issues, and being more “responsible.” But overall the pros outweigh the cons.

But there’s still some parts I wasn’t prepared for - lessons it taught me I wish I’d learned beforehand. So for my year-and-a-half celebration of adulthood, these are the five most important lessons I learned post-school. I pass them onto you, reader of a presumably similar age, in the hopes you learn them for your adult life too.

If you already know them, or are young enough to not care, please continue reading anyway as a birthday present to me!

You Don’t Need the Answers Right Away

My most frustrating times have been when I felt my life wasn’t exactly what I wanted, which was:

  • a career that’s financially secure, challenging, and helped others in need.
  • part of a professional community that kept me active, engaged, and networking.
  • a social life with new experiences and interesting people.
  • a popular online presence for creatively expressing myself.

If you feel lost for the first years as an adult, that’s fine as long as you still keep moving.

That’s a tall order, and I believed it’d come right after graduation. Turns out, progress is ongoing but (utterly) slow. Many in my generation likely feel the same. Either that expectation bubble pops, or one grows up increasingly frustrated that their high expectations aren’t met.

I can’t say when this realization will, or can, happen for my fellow millennials, but it happened for me early this year. I still haven’t given up on reaching this better life, but I’ve accepted three things:

  1. I won’t get there fast, if at all.
  2. I won’t know how to get there right away.
  3. It won’t be perfect.

Maybe someday I’ll get that “amazing” life. Maybe not. One thing I’m sure of is I don’t need to know how it’ll all happen right away. That’ll come in time, if at all.

This tough lesson leads right to the next one…

Count Your Blessings

Every person has certain things to be thankful for, some more than others. No matter where one falls on the spectrum, they shouldn’t take them for granted.

In my case I have lots to be thankful for. I went to a good school, have a steady job I enjoy, don’t have any major health or legal concerns, have a decent car for my own transport, have the time and resources to enjoy some hobbies, and know where my next meals are coming from.

I’ve got plenty of privileges, both in my identity and upbringing, and most outside my control. I owe where I am now to them. The more I think about how I got to this point, the more I realize I have little to truly be upset about.

While I have more than many, most people have at least a few blessings in their lives, whether its how they live or who it’s with. Whatever they are, be thankful while they’re around, because…

Assume Things Will Change

It’s easy to think that, once things are going well, they’ll stay that way. I’d get into a pleasant routine for a week before something throws it off - a car issue, a deadline change, or a sudden meeting. These frustrations have been the roughest of my young adult life.

The best way around them is to always assume change will happen at any moment. Be prepared for as many situations as possible. Most importantly, keep your thoughts and plans flexible.

Keep your thoughts and plans for life flexible.

This has helped in most of my life. I don’t get attached to any new technology since a better once often arrives later. I frequently reshuffle my schedule to avoid wasting time. I try to get the most important 20% of my day done as early so I’m freer for the rest. It’s all about freeing up options and possibilities so whenever the unexpected hits, one doesn’t falter (as much).

Our Habits Define Much of Us

Most people likely don’t think much about their habits. It’s not surprising, since by definition they’re actions we do with almost no awareness. This makes up almost half of what we do each day. Habits are worth caring about.

The biggest reason habits matter, in my opinion, is their effects build up overtime and will define a person. Over time, someone in the habit of walking every day will be much healthier than someone in the habit of watching TV each day. Habits of willpower, reading, and creativity helps a lot in the long run. Habits of impulsiveness, video watching, and consumption do the opposite.

Habits are the building blocks to one’s foundation. As a young adult, now is the time to change them. Otherwise much of life will be a struggle against them.

Live Authentically

Perhaps my favorite lesson is living authentically. But it sounds generic - what does it mean? A section from “The Seven Habits of Highly Effective People” sums it up well.

The author Stephen Covey says people have a center we get our values from. There’s many possible centers: family, money, work, church, possessions, pleasure, even ourselves. Our center affects our decisions, opinions, motivation, and happiness.

Some are arguably better than others, but all have a common downside: our value and happiness all come from elements ultimately outside of our control. For example, someone money-centered is only as fulfilled if they have lots of money, and circumstances often limit this. No matter what we do, Covey argues these centers have limits built into them, and we risk not being fulfilled. We’re surrendering some degree of control over our happiness and value.

Live more by your own principles instead of letting people, items, or institutions control how you live.

Covey argues we should be principle-centered - living by prime principles to guide our beliefs, motivations, decisions, happiness, and value. This avoids the other centers’ issue - living based on principles means our value comes more from one’s actions and less than one’s circumstances. No matter the outcome, or where we go in life, we can still have a sense of happiness and value.

While I don’t believe one should base 100% of their lives around principles, I believe the majority of one’s happiness should be. We can’t ignore money and friendships, after all, but our lives shouldn’t fall to pieces if we struggle with them. Making principles the prime center of ones life helps ensure we live a stable, meaningful life that’s true to one’s identity, despite struggles or changes.

You may be curious the principles I base my life around. Well…that’s a post for another birthday!