IDEA – IKEA Style Instructions for algorithms

IDEA a unique project that uses IKEA style of instructions to explain algorithm assembly instructions. From their about page:

IDEA is a series of nonverbal algorithm assembly instructions by Sándor P. Fekete, Sebastian Morr, and Sebastian Stiller. They were originally created for Sándor’s algorithms and datastructures lecture at TU Braunschweig, but we hope they will be useful in all sorts of context. We publish them here so that they can be used by teachers, students, and curious people alike.

All IDEA assembly instructions are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license, or CC by-nc-sa 4.0 for short.

Quick Review of Andy Weir’s Artemis

Artemis by Andy Weir came out at the end of last year and as a big fan of the Martian I decided to grab the Audible version, which is arguably the best way to consume fiction, and after finishing it I wanted to share my thoughts.

First, the narrator, Rosario Dawson, was brilliant. I loved her in the Luke Cage and Iron Fist shows and she didn’t disappoint​ with this book. However, outside of her,​ I was really let down by this book.

Everything was way too convenient​ for the main character, Jazz Bashara, and the teenage sexual humor annoyed me. This book was very different from the Martian and I’m sure by piggybacking​ on the success of that book this one will be made into a movie, but I’m hoping this was just a sophomore slump for Andy Weir and he’ll be back on his game for the next one.

If you haven’t tried an Audible book before you can get two free Audiobooks through their current promotion. I’d recommend getting a different book for first though.

Thanks to Cloudflare

Finding services to complain about is always easy and it’s easy to look for things that annoy, much harder to find things that please.

Today I want to give a shout out to Cloudflare for helping me save money on hosting, and protecting my sites. Based on their dashboard in the past month they’ve helped with the following:

  • 10,371,929 SSL requests served in the last month!
  • 3,217 malicious requests blocked or challenged in the last month
  • Helped me save 157 GB of bandwidth in the last month
  • Cached 7,583,021 out of 10,832,286

All this is great, but this month I had am unexpected billing issue that wasn’t my fault, and their entire support staff handled it brilliantly. ​It’s great dealing with people that care, especially on the support side.

My Annoyance with WordPress.com Themes

Late last year I switched this domain from self-hosted WordPress back to wordpress.com that way I didn’t have to deal with updates, running a server, paying for hosting, and everything else.

The ease of use is superb and having it as a SAAS is wonderful for me. I can just write and share things when the inspiration hits and I don’t have to worry about anything.

However, one of the downsides is the themes available on WordPress.com. It currently shows 310 available and I’ve literally been through every single and not been happy with any and its always minor stuff.

For example, I found one that was perfect. It had a standard blog layout, my content looked great, but then it didn’t support featured images on the post details page. Then I’ll find an awesome grid theme, only to see my content look like crap in its demo. Then others where I think it’s going to work based on the theme screenshot only to find out it actually looks nothing like that.

Tonight I’ve spent so much time trying to find one that would work for me that I eventually just gave up and went back to twenty-fourteen.

I really do wish WordPress would normalize themes further or at least explain what is expected. Take the featured image. What is it for? Only for the archive lists, or for post details too? The answer seems to be whatever the theme designer decides. Another one is what is the home page? Some preview images show what I believe is a portfolio, but then when you try to just a standard blog home page it looks like crap.

Honestly, I think the crux of the issue for me is I want an old school simple blog where every theme now feels overly designed and the designers are expecting you to​ be able to add awesome images to every post.

Simple PHP Refactoring

Today I needed to write some code to grab a list of CC addresses from an email, and I thought showing the steps I took could make for an entertaining blog post.

I know everyone works differently and when I’m facing a coding challenge the first thing I do is try my best to just get it to work. I don’t care how the code looks or anything. The only goal is to make it work. Here is my first working attempt at solving the problem of grabbing the CC’s:

/**
 *
 * Returns an ​array of email addresses
 * ['john@example.com', 'jane@example.org'];
 *
 */
public function getCC() 
{
    if ($ccs = $this->getHeaderByKey('cc')) {
        $adrListArray = imap_rfc822_parse_adrlist($ccs, null);
        $ccs = [];
        foreach ($adrListArray as $item) {
            $ccs[] = $item->mailbox.'@'.$item->host;
        }
        return $ccs;
    }
    return false;
}

This code is using PHP’s imap_* functions to first see if the CC header is set in the .eml file, then the imap_rfc822_parse_adrlist function to parse an email address string. This is useful to normalize​ the output of an email address list. The getHeaderByKey either returns the string of the header or false.

After I got it working the temporary variable was really annoying me, so I next refactored to the following:

public function getCC() 
{
    if ($ccs = $this->getHeaderByKey('cc')) {
        $adrListArray = imap_rfc822_parse_adrlist($ccs, null);
        return array_map(function($item){
            return $item->mailbox.'@'.$item->host;
        }, $adrListArray);
    }
    return false;
}

That started feeling better, but I really don’t like that all that code nested inside the if.

public function getCC() 
{
    if (! $ccs = $this->getHeaderByKey('cc')) {
        return false;
    }

    $adrListArray = imap_rfc822_parse_adrlist($ccs, null);
    return array_map(function($item){
        return $item->mailbox.'@'.$item->host;
    }, $adrListArray);
}

Now it feels cleaner to me and could be further simplified by removing the $adrListArray temporary variable:

public function getCC() 
{
    if (! $ccs = $this->getHeaderByKey('cc')) {
        return false;
    }

    return array_map(function($item){
        return $item->mailbox.'@'.$item->host;
    }, imap_rfc822_parse_adrlist($ccs, null));
}

Personally, I think it’s cleaner than what I had the start, but even now I’m not 100% happy with it. I don’t like the $ccs variable assignment in the if statement, I think the method name should be changed to better represent this returning an array of email addresses. It’s not a single CC.

I think it’s a fun exercise writing out why you made the improvements that you did and thinking through how to make your code readable. I know this is subjective, but I find the last example easier to grasp vs. ​the first. What do you think? Do you see any other improvements that could be made?