FizzBuzz

We’re hiring a new developer in my group at work, and my boss is including me in the interviewing process. It’s been a few years since I’ve done developer interviews, so I’m a bit rusty. I suggested having candidates do a FizzBuzz test on a whiteboard as part of the interview.

Jeff Atwood wrote a good post about FizzBuzz on his blog back in 2007. It seems like an overly simple test, but it can be quite useful. I’ve only been asked to do FizzBuzz once myself, and it was a good experience. The interviewer was really sharp and asked me a lot of good questions about how I could do it differently or why I chose to do something a certain way. He turned a simple 12-line program into a good conversation.

At very least, FizzBuzz should help filter out candidates who are exaggerating on their resumes. If you say you’ve got five years of C# experience and you can’t write a FizzBuzz program, you’re lying. The two candidates we’ve looked at so far both have an MS in Comp Sci, so they’re both better-educated than I am, at least, and they should both be able to handle FizzBuzz.

Anyway, it occurred to me that I never wrote a FizzBuzz program in X++. So here’s a short job to solve FizzBuzz in X++. I might post it to RosettaCode, if I get around to it. Not that the world really needs one more FizzBuzz solution.

static void AjhFizzBuzz(Args _args)
{
    /* Write a program that prints the numbers from 1 to 100. 
    If it’s a multiple of 3, it should print “Fizz”. 
    If it’s a multiple of 5, it should print “Buzz”. 
    If it’s a multiple of 3 and 5, it should print “Fizz Buzz”. 
    */
    int i;
    
    for (i = 1; i <= 100; i++)
    {
        if (i mod 3 == 0 && i mod 5 == 0)
            info("Fizz Buzz");
        else if (i mod 3 == 0)
            info("Fizz");
        else if (i mod 5 == 0)
            info("Buzz");
        else
            info(int2str(i));
    }
}

The Internet Archive

Right now, if you donate to the Internet Archive, there’s a 2-for-1 match. I’ve been using links from the Wayback Machine to replace a lot of the broken links on my site recently, so I’d been meaning to send them a few bucks. A 2-for-1 match is a good excuse to actually do that. It’s easy to take something like archive.org for granted, but it’s not cheap to keep a site like that running.

Speaking of broken links, I’m continuing to clean them up, slowly. My broken links list is currently at 660. I’ve recently hit a vein of broken links related to “best of” lists from 2004. Some of those are gone forever. And John Vanderslice’s puttanesca recipe seems to have disappeared from the internet. No, wait, I found a copy. (I need to stop now and go to work…)

Illegitimi non carborundum

Here’s an oddball digression for a rainy Sunday morning: Somehow or other, the phrase “don’t let the bastards get you down” came into my head this morning. I vaguely remember my dad using it in a letter he wrote me when I was in college. Or possibly seeing it used in a Kurt Vonnegut novel. Anyway, in the old days, this would have been a passing thought, but the internet exists now, so a passing thought can become an hour-long trip down the internet rabbit hole…

I first found a song titled Don’t Let The Bastards Get You Down by Kris Kristofferson. That’s clearly not where I first heard it, but it’s not a bad little song. Then I found a reference to Illegitimi non carborundum, a “mock Latin” phrase that’s meant to mean “Don’t let the bastards grind you down.” I remember seeing that Latin phrase before, probably in a book, though I still can’t find a reference to it in a Vonnegut book. (And reading the Wikipedia page for it, I see that John Boehner is apparently fond of the phrase, so that’s kind of disappointing.)

Searching further, I found a song by The Toasters called Don’t Let the Bastards Grind You Down, which is very different from the aforementioned Kris Kristofferson song, but still a pretty good song, if you like late-90s ska. And also definitely not where I first encountered the phrase.

And after even more searching, I found a reference to Nolite te Bastardes Carborundorum, which is apparently an alternate version of the phrase, used in Margaret Atwood’s The Handmaid’s Tale. I did read that book in college, so I might remember it from there. And the phrase is used prominently in the season 2 finale of The Handmaid’s Tale TV show, so that explains it’s recent popularity as a tattoo. I haven’t watched that show, and I’m so far behind with TV that I probably won’t be watching it any time soon, but I’m curious about it.

So anyway, that was my internet digression for this morning. I’m not sure I learned anything useful, but it was kind of fun. The sun is up now, so I should probably brush my teeth and find something useful to do.

1&1 Ionos

I’ve been using 1&1 for web hosting since 2003. The cost went up last year, but I’ve stuck with them, partly out of laziness and partly because they’ve been reliable. They recently went through a merger and renamed themselves as 1&1 IONOS. I’m all for this rebranding; searching for “1&1” has always been a crapshoot, whether it’s in Google, my email, or my Evernote database. Whoever decided to name the company using one digit, an ampersand, and no actual letters clearly did not run that past an SEO guy. I think that maybe the guy who named the company “1&1” was stuck in the old “telephone book” mindset, where he wanted a name that would float to the top of most sort orders.

“IONOS” is a name that actually contains enough letters to form a unique search term, so for that alone, it’s way better than 1&1. I’m not entirely on board with the whole name being in capital letters though. That makes it seem like it’s an acronym, and (as far as I can tell) it’s not.

Black Friday

There was no repeat of the Christmas music incident last night, so I got a good night’s sleep (or at least as good as I can manage these days). So I may actually be in shape to do a few of the things that I was too frazzled to do yesterday. However, it’s still very cold out: 12° this morning. And Raritan Valley trains are running about 30 minutes behind schedule right now. So, combining those two factors, going into NYC today might be a bad idea. I’m not going to completely rule it out, but I’m definitely not heading out to the train station right now to stand outside in the cold for a half-hour, hoping the train eventually shows up. If I see the trains get back to normal, and if it gets up into the twenties, maybe I’ll go in later.

I started my online Black Friday shopping yesterday, and I think it might be amusing to list out some of the stuff I bought, yesterday and today.

  • I picked up some random comics on Comixology, from DC’s big Black Friday sale. I got Batman: White Knight, which I’ve heard a lot of good things about. And Tales of the Batman: Gene Colan Vol. 2. I really liked Colan’s run on Batman, back in the 80s, after he left Marvel for DC. And I got Grant Morrison’s Wonder Woman: Earth One Vol. 1 and Vol. 2. I generally like anything Morrison does, so I’m pretty sure I’ll like these. (These were $5 each.)
  • I bought Blade Runner 2049 and Isle of Dogs from Vudu. I hadn’t previously bought any digital movies from Vudu, but with the whole Movies Anywhere thing, I can buy from Apple, Amazon, or Vudu and the movies show up in all three libraries, so it makes sense to buy from whichever service is cheapest. (I was originally thinking about going out to see a movie today, but I think that, instead, I’ll likely stay in and watch one or both of those.)
  • I picked up Fantastical 2 for iPad for $3. (It’s regularly $10.) I’ve been using the iPhone version for years, but never got around to picking up the iPad version.
  • I bought a $100 iTunes gift card for $80 from Costco. It seemed like a good deal.
  • This morning, when I went into Lose It to log my breakfast, I got a popup offering a deal on a lifetime subscription. I’m always a bit leery of lifetime subscription deals, but I’ve been using Lose It for five years, and renewing my premium subscription every year, so I went ahead and paid $75 for a lifetime sub. Since I did that in-app, that came out of my iTunes account, nicely using up most of that gift card I bought last night. (Maybe I’ll pick up another $100 card today.)

And here are some things I’m looking at today:

  • Pluralsight has their usual Black Friday sale going on, where you can renew your subscription for $200 instead of $300. I’ll probably do that again this year. I don’t get a ton of use out of Pluralsight, but I guess I get enough that it’s worth the $200.
  • Jetpack has a 30% discount off all plans for Black Friday. I’m currently only using the free Jetpack services on this blog, but I could step up to their “personal” plan. About all that really gets me, beyond what’s in the free plan, is site backups, but that could be useful.
  • Apple’s Black Friday weekend event has started. As usual with Apple, it’s not that compelling. But it might be worthwhile for me, since I was looking at getting some new Apple stuff anyway. On the iPhone front, they only have deals on iPhone 7 & 8, and I was thinking about the XR, so I’ll probably skip those. Their Apple Watch deal is for a $50 Apple Store Gift Card when you buy a Series 3. That’s not much, but might be a good deal for me. My current watch is a “Series 0,” so a Series 3 would be a good step up. I can use the $50 towards my eventual iPhone purchase.
  • I’m thinking about picking up a second Sonos One speaker, either from Sonos directly, or from Amazon or Costco. I get a fair bit of use out of the one I bought earlier this year, and it would nice to have two, for stereo. I don’t know if I really need that, though.
  • It’s not exactly a Black Friday thing, but a friend of mine has a story in this anthology about… cannibalism. On the one hand, I’d like to support him, on the other hand, I don’t much like reading about cannibalism. But hey, it’s only $4 for Kindle.

Since I started writing this blog post, I see that the NJ Transit delays are now at almost an hour, so things on that front are definitely going in the wrong direction. And the temperature is up to 22°, so that’s going in the right direction, but maybe not far enough to motivate me to spend much time outdoors today.

Happy Thanksgiving

My Thanksgiving day this year is off to a rough start. They play Christmas music on Main St here in Somerville now, normally from noon to 8pm, but something threw off the timer a couple of weeks ago, so we’ve had a few instances of overnight Christmas music recently. And last night, it played all night.

It all started after the big snowstorm a week ago. (You might say that it wasn’t that much of a snowstorm, but as the linked article points out, it was “the biggest one-day November snowfall in 136 years.”) That night, the music didn’t end at 8pm, and kept playing until around midnight. My guess is there was a brief power interruption that screwed up the timer. So that wasn’t too bad. Either the timer stopped it at midnight or someone managed to turn it off.

Then, Saturday night, the music started at midnight, and stopped around 2am. My guess on that is that someone screwed up the AM/PM setting on it. (And I guess someone managed to shut it off after a couple of hours.)

I thought we were over all of that, since it’s been fine the last few days. But last night, again, it started at midnight. And never stopped. The last time this happened was back in 2012. That time, I called the police, but there was nothing they could do about it. And I sent an email to the group that’s responsible for the music, and they apologized, which is nice, but none of that gets me back a lost night of sleep. My best guess as to what happened this time is that somebody tried to change the schedule for Thanksgiving and screwed up the AM/PM setting again.

So I got out of bed at 5am this morning and I’m now eating breakfast and listening to some quiet music by Hugar, just loud enough to drown out the Christmas music. (Which is still playing.) It’s looking to be the coldest Thanksgiving since 1871, according to the NY Times. (It’s 20° right now, with a “feels like” temp of 11°, here in Somerville.) I’ve been trying to talk myself into going into New York today, and the continuing Christmas music assault might be enough to force me out of my apartment, even in 20° weather. I don’t really know what I’d do in NYC today; all the museums are closed. I’d probably go see a few movies, I guess.

I did put earplugs in last night, but they didn’t help much. On one of the previous nights, I also turned on my air cleaner, hoping the white noise would help. (It turns out that the earplugs do a good job of filtering out the air cleaner noise, but don’t help much with the music.)

So now I’m thinking about options for better earplugs, noise cancelling earphones, white noise generators, and stuff like that. Here’s a thread from Hacker News from earlier this week, about brain.fm and similar products/services. I’ve been wondering if I could actually use Max Richter’s eight-hour work Sleep to get through the night. I think I also need to look at some of the stuff in this NY Times article from 2011. Bose makes something called Noise-Masking Sleepbuds that might be good, though they cost $250. That got me thinking about whether or not I could sleep with AirPods in. That led me to a reddit thread; results on that seem to be mixed. (And battery life on the AirPods is only five hours, so they wouldn’t last all night.) I’m not at all sure what will work best. I may go on a bit of an Amazon binge today, ordering a bunch of random earplugs and stuff.

Now, it’s almost 7am, and I’ve moved from Hugar to Relaxation Tape for Solo Space Travel by The National Pool (which is quite good). There’s a lot of good ambient music on Bandcamp, but that’s a subject for another day.

This blog post is probably a bit scattershot, since it’s being written on zero sleep, but writing it has helped me get through breakfast and lower my stress level a bit, so that’s something. I’m hoping the Christmas music will stop at 8am, assuming my theory about the AM/PM screw-up is correct. If that happens, I may just go back to bed. (Though the three cups of coffee I just had might get in the way of that.)

a little more on Stan Lee

I feel like I need to add a second post with some links related to Stan Lee’s passing.

Adding an exception logger to a Web API project with Autofac and Serilog

I just spent way too much time figuring out how to add a catch-all logger for exceptions to an ASP.NET Web API project, so I figured I’d write up my experience as a blog post, for anyone else who needs it (and for my own future reference).

The goal, specifically, is to log any unhandled exceptions using Serilog. I don’t want to mess with them in any way, I just want to record them in the log. (For this API, most exceptions are already properly handled, but sometimes something falls through the cracks, so I just want to be able to see when that happens, so I can fix it.)

First, this is an old-fashioned ASP.NET Web API project, not a .NET Core project. I’m using Autofac for dependency injection and Serilog for logging.

And I’m using the Autofac.WebAPI2 package to integrate Autofac into the API. My Autofac configuration looks pretty much just like the example in the “Quick Start” section of the page linked above.

Serilog is linked in like this:

builder.Register((c, p) =>
{
    var fileSpec = AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "\\log\\log-{Date}.log";
    var outpTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Properties:j} {Message:lj}{NewLine}{Exception}";
    return new LoggerConfiguration()
        .WriteTo.RollingFile(fileSpec, outputTemplate: outpTemplate)
        .ReadFrom.AppSettings()
        .CreateLogger();
}).SingleInstance();

I won’t get into how that works, but you could figure it out from the Serilog docs easily enough.

ASP.NET Web API provides a way to hook into unhandled exceptions using an ExceptionLogger class. This is described a bit here. I found several blog posts describing various permutations on this functionality, but I had to mess around a bit to get it all to work right for me.
I created a class that looks like this:

public class MyExcLogger : ExceptionLogger
{
    public override void Log(ExceptionLoggerContext context)
    {
        var config = GlobalConfiguration.Configuration;
        var logger = (ILogger)config.DependencyResolver.GetService(typeof(ILogger));
        if (logger != null)
            logger.Error("Unhandled exception: {exc}", context.Exception);
    }
}

and I hooked it up to Web API by adding this line to my WebApiConfig Register() method:

config.Services.Add(typeof(IExceptionLogger), new MyExcLogger());

There’s not actually much to it, but I went down the wrong path on this thing several times, trying to get it to work. The (slightly) tricky part was getting the logger instance from the dependency resolver. Constructor injection doesn’t work here, so I had to pull it out of the resolver manually, which I’d never actually tried before.

Stan Lee

I was sad, but not surprised, to hear about Stan Lee’s passing today. He’s been in poor health for a while, and he was 95 years old. The NY Times has posted a surprisingly length obituary. I took a look at my Twitter timeline this afternoon, and it was full of people posting about him, both comics industry folks and, well, everyone else. I could link to a bunch of other stuff about Stan, but I’ll limit myself to one more thing: Paul Chadwick’s Stan the Mensch blog post from 2010. Just a little story about Stan being kind to a fan; look around the web today, and you’ll find a bunch more like it.

Tom Malinowski

I just watched a segment from Amanpour & Co with Tom Malinowski, my newly-elected congressperson. My local House district has been in Republican hands for as long as I’ve lived here, so it’s kind of a big deal that a Democrat got elected. I actually didn’t see much of Malinowski in the news during the campaign, and I have to admit that I didn’t know that much about him. I never really bothered to do much research. I knew the basics: he worked in the State Department under the Obama administration, and had previously worked for Human Rights Watch. I don’t think I’d ever even seen him speak during the campaign. He seems to be a soft-spoken, reasonable, guy. It’ll be interesting to see what happens over the next couple of years, with the House back under Democratic control. I don’t want to go too far down the politics rabbit-hole, so I’ll leave it there.