Books of 2019

List of books I read in 2019. Also see the list of 2018. The date indicated denotes the date I started reading the book.

2019-01-05 - The Subtle Art of Not Giving a F*ck - 206 pages

Leave A Reply

C++: Foreach over an array

If you have an array of elements that you want to iterate over you can do this:

int dpins[] = { 2, 4, 7, 12 };

for (int i = 0; i < (sizeof(dpins) / sizeof(dpins[0])); i++) {
    int pin  = dpins[i];
    int pval = digitalRead(pin);

    printf("%i = %i", pin, pval);

There is also a newer syntax adopted in C++11 (and supported by Arduino) that is more readable:

int dpins[] = { 2, 4, 7, 12 };

for (int pin : dpins) {
    int pval = digitalRead(pin);

    printf("%i = %i", pin, pval);
Leave A Reply

C/C++: Appending to a string with sprintf()

I'm a big fan of sprintf() and use it in a lot of projects. Often I will want to append to a string instead of creating a new one. This solution will create an "end of string" function named eos() that returns a pointer to the end of a given string. If you feed that to sprintf() it will effectively append to the existing string.

char *eos(char str[]) {
    return (str) + strlen(str);

int main(int argc, char *argv[]) {
    char tmp_str[50] = "";

    sprintf(eos(tmp_str), "Weird");
    sprintf(eos(tmp_str), " Al");
    sprintf(eos(tmp_str), " Yankovic");
Leave A Reply

Simpsons: Marge be not Proud

Episode 11 of season 7 of the Simpsons is titled Marge be not Proud and is one of my favorite classic episodes. Bart gets caught trying to shoplift Bonestorm because his family won't buy it for him for Christmas. I did a freeze frame on the video game case and found these hilarious video game titles.

  • Swim Meet
  • Save Hitler's Brain
  • Canasta Master
  • Operation Rescue
  • a Streetcar Named Death
  • Bonestorm
  • Angus Podgorny's Caper Toss
  • Celebrity Tutopsy
  • Robot Stampede
  • Sim Reich

For the record, I would play the heck out of both Save Hitler's Brain and Angus Podgorny's Caper Toss.

Leave A Reply

Reddit: Gandalf was really just fighter with INT18

Reddit user TheGlen made a great post about Gandalf being a fighter not a wizard.

Gandalf lied, he was no wizard. He was clearly a high level fighter that had put points in the Use Magic Device skill allowing him to wield a staff of wizardry. All of his magic spells he cast were low level, easily explained by his ring of spell storing and his staff. For such an epic level wizard he spent more time fighting than he did casting spells. He presented himself as this angelic demigod, when all he was a fighter with carefully crafted PR.

His combat feats were apparent. He has proficiency in the long sword, but he also is a trained dual weapon fighter. To have that level of competency to wield both weapons you are looking at a dexterity of at least 17, coupled with the Monkey Grip feat to be able to fight with a quarter staff one handed in his off hand at that. Three dual weapon fighting feats, monkey grip, and martial weapon proficiency would take up 5 of his 7 feats as a wizard, far too many to be an effective build. That's why when he faced a real wizard like Sarumon, he got stomped in a magic duel. He had taken no feats or skills useful to a wizard. If he had used his sword he would have carved up Sarumon without effort.

The spells he casts are all second level or less. He casts spook on Bilbo to snap him out his ring fetish. When he's trapped on top of Isengard an animal messenger spell gets him help. Going into Moria he uses his staff to cast light. Facing the Balrog all he does is cast armor. Even in the Two Towers his spells are limited. Instead of launching a fireball into the massed Uruk Hai he simply takes 20 on a nature check to see when the sun will crest the hill and times his charge appropriately. Sarumon braced for a magic duel over of the body of Theodin, which Gandalf gets around with a simple knock on the skull. Since Sarumon has got a magic jar cast on Theodin, the wizard takes the full blow as well breaking his concentration. Gandalf stops the Hunters assault on him by parrying two missile weapons, another fighter feat, and then casting another first level spell in heat metal. Return of the King has Gandalf using light against the Nazgul and that is about it. When the trolls, orcs and Easterlings breach the gates of Minos Tiroth does he unload a devastating barrage of spells at the tightly pack foes? No, he charges a troll and kills it with his sword. That is the action of a fighter, not a wizard.

Look at how he handled the Balrog, not with sorcery but with skill. The Balrog approached and Gandalf attempts to intimidate him, clearly a fighter skill. After uses his staff to cast armor, a first level spell, Gandalf then makes a engineering check, another fighter skill, to see that the bridge will not support the Balrog's weight. When the Balrog took a step, the bridge collapsed under its weight. Gandalf was smart enough to know the break point, and positioned himself just far enough back not to go down with the Balrog. The Balrog's whip got lucky with a critical hit knocking Gandalf off balance. The whole falling part was due to a lack of over sight on behalf of the party, seriously how does a ranger forget to bring a rope? Gandalf wasn't saved by divine forces after he hit the bottom, he merely soaked up the damage because he was sitting on 20d10 + constitution bonus worth of hit points.

So why the subterfuge? Because it was the perfect way to lure in his enemies. Everybody knows in a fight to rush the wizard before he can do too much damage. But if the wizard is actually an epic level fighter, the fools rush to their doom. Gandalf, while not a wizard, is extremely intelligent. He knows how his foes would respond. Nobody wants to face a heavily armored dwarf, look at Gimli's problem finding foes to engage in cave troll fight. But an unarmored wizard? That's the target people seek out, before he can use his firepower on you. If the wizard turns out to actually be a high level fighter wearing robes, then he's already in melee when its his turn and can mop the floor with the morons that charged him. So remember fighters, be like Gandalf. Fight smarter, not harder.

Leave A Reply

Popular Vote vs Electoral College

The Electoral College has "skewed" several elections in the past, which has spurred a movement to abolish it. The Electoral College is mandated by the federal government, and changes at the federal level are very unlikely to happen.

There is a collection of states that are banding together to try and overturn the Electoral College system. The National Popular Vote Interstate Compact is a legally binding agreement between states that when enough states have joined to insure the 270 Electoral College votes required to elect a president, those states will give all of their Electoral College votes to whichever candidate wins the popular vote regardless of how voters in their respective state voted.

This is a creative state based method to work around the antiquated Electoral College system.

Leave A Reply

Linux: Fedora 29 major package versions

Fedora 29 has these versions of some core packages:

Package Version
Apache 2.4.34
GCC 8.2.1
Kernel 4.18.16
Perl 5.28.0
PHP 7.2.11
Vim 8.1.483
Git 2.19.1
Leave A Reply

Linux: Configuring CDP for mapping physical network ports

We're turning up a lot of servers, with a lot of Ethernet ports, and it's hard to keep track of what's where. Our network guy turned me on to the concept of CDP to list out what's connected to certain ports. On a modern CentOS or Fedora box you simply need to install lldpd and enable it for CDP mode and you're off to the races.

yum install -y lldpd
perl -pi -e 's/LLDPD_OPTIONS=""/LLDPD_OPTIONS="-c"/' /etc/sysconfig/lldpd
systemctl enable lldpd ; systemctl start lldpd

This will start the lldpd service and begin broadcasting on all ethernet ports. After 30 seconds or so you should be able to run the following command to see what your local Ethernet neighbors are.

lldpcli show neighbors
Leave A Reply

SSH to hosts with older ciphers

We have some older Cisco equipment that runs SSH with some untrusted ciphers. Specifically the key exchange is still using SHA1, which modern Linux distributions have deprecated. You may see something like this:

Unable to negotiate with port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1

You can work around this by putting this in your ~/.ssh/config

    KexAlgorithms +diffie-hellman-group1-sha1

Borrowed from StackExchange.

Leave A Reply

Linux: Fedora 28 major package versions

Fedora 28 has these versions of some core packages:

Package Version
Apache 2.4.33
GCC 8.0.1
Kernel 4.16.3
Perl 5.26.1
PHP 7.2.5
Vim 8.0.1788
Git 2.17.0
Leave A Reply

Fedora: Enable h264 video on Firefox with Fedora 28

The h264 video codec is the most popular codec on the internet right now. Unfortunately it's patent encumbered so it cannot be included in Firefox unless Mozilla were to pay a licensing fee. To enable h264 support in Firefox on Fedora 28 you'll need to enable the RPM Fusion repository.

dnf install$(rpm -E %fedora).noarch.rpm \$(rpm -E %fedora).noarch.rpm

After you've configured RPM Fusion you'll need to install some FFMpeg libraries to handle the actual h264 decoding:

dnf install ffmpeg-libs compat-ffmpeg28
Leave A Reply

Floating point rounding errors

Computers store floating point numbers in IEEE-754 format. This is imprecise and can result in rounding errors after the 8th or 9th decimal place. The following example shows the error in a simplified manner:

perl -E 'say 0.1 + 0.2 == 0.3 ? "true" : "false"'

python -c 'print 0.1 + 0.2 == 0.3'

ruby -e 'puts 0.1 + 0.2 == 0.3'

php -r 'print 0.1 + 0.2 == 0.3 ? "true" : "false";'

All of these print out false which is obviously the incorrect answer. Most languages recommend some type of rounding or comparison library when comparing floating point values for this reason.

This rounding error is present in JavaScript too:

console.log(0.1 + 0.2 == 0.3 ? "True" : "False");
Leave A Reply

Kevin Smith on his (almost) death

Kevin Smith had a heart attack yesterday and wrote, what I feel, is a really well worded interpretation human mortality.

I was trying to do a killer standup special this evening but I might’ve gone too far. After the first show, I felt kinda nauseous. I threw up a little but it didn’t seem to help. Then I started sweating buckets and my chest felt heavy. Turns out I had a massive heart attack. The Doctor who saved my life at the #glendale hospital told me I had 100% blockage of my LAD artery (also known as “the Widow-Maker” because when it goes, you’re a goner). If I hadn’t canceled the second show to go to the hospital, the Doc said I would’ve died tonight.

For now, I’m still above ground! But this is what I learned about myself during this crisis: death was always the thing I was most terrified of in life. When the time came, I never imagined I’d ever be able to die with dignity - I assumed I’d die screaming, like my Dad (who lost his life to a massive heart attack). But even as they cut into my groin to slip a stent into the lethal Widow-Maker, I was filled with a sense of calm. I’ve had a great life: loved by parents who raised me to become the individual I am. I’ve had a weird, wonderful career in all sorts of media, amazing friends, the best wife in the world and an incredible daughter who made me a Dad.

But as I stared into the infinite, I realized I was relatively content. Yes, I’d miss life as it moved on without me - and I was bummed we weren’t gonna get to make #jayandsilentbobreboot before I shuffled loose the mortal coil. But generally speaking, I was okay with the end, if this was gonna be it. I’ve gotten to do so many cool things and I’ve had so many adventures - how could I be shitty about finally paying the tab.

But the good folks at the Glendale hospital had other plans and the expertise to mend me. Total strangers saved my life tonight (as well as my friends @jordanmonsanto & @iamemilydawn, who called the ambulance). This is all a part of my mythology now and I’m sure I’ll be facing some lifestyle changes (maybe it’s time to go Vegan). But the point of this post is to tell you that I faced my greatest fear tonight... and it wasn’t as bad as I’ve always imagined it’d be. I don’t want my life to end but if it ends, I can’t complain. It was such a gift. #KevinSmith

via Kevin Smith's Instragram

Leave A Reply

FFMPEG: Using VBR encoding for MP3s

I'm a big fan of using VBR for MP3s. I use FFMPEG to convert video (and sometimes audio) files to different formats. If you want to utilize VBR with LAME when you do FFMPEG conversions you need to specify the libmp3lame encoder, and then a given quality level:

ffmpeg -i input.wav -codec:a libmp3lame -qscale:a 2 output.mp3

ffmpeg -i video.mp4 -codec:a libmp3lame -qscale:a 6 /tmp/output.mkv
Leave A Reply

Pale blue dot

"Look again at that dot. That's here. That's home. That's us. On it everyone you love, everyone you know, everyone you ever heard of, every human being who ever was, lived out their lives. The aggregate of our joy and suffering, thousands of confident religions, ideologies, and economic doctrines, every hunter and forager, every hero and coward, every creator and destroyer of civilization, every king and peasant, every young couple in love, every mother and father, hopeful child, inventor and explorer, every teacher of morals, every corrupt politician, every "superstar," every "supreme leader," every saint and sinner in the history of our species lived there-on a mote of dust suspended in a sunbeam.

The Earth is a very small stage in a vast cosmic arena. Think of the endless cruelties visited by the inhabitants of one corner of this pixel on the scarcely distinguishable inhabitants of some other corner, how frequent their misunderstandings, how eager they are to kill one another, how fervent their hatreds. Think of the rivers of blood spilled by all those generals and emperors so that, in glory and triumph, they could become the momentary masters of a fraction of a dot.

Our posturings, our imagined self-importance, the delusion that we have some privileged position in the Universe, are challenged by this point of pale light. Our planet is a lonely speck in the great enveloping cosmic dark. In our obscurity, in all this vastness, there is no hint that help will come from elsewhere to save us from ourselves.

The Earth is the only world known so far to harbor life. There is nowhere else, at least in the near future, to which our species could migrate. Visit, yes. Settle, not yet. Like it or not, for the moment the Earth is where we make our stand.

It has been said that astronomy is a humbling and character-building experience. There is perhaps no better demonstration of the folly of human conceits than this distant image of our tiny world. To me, it underscores our responsibility to deal more kindly with one another, and to preserve and cherish the pale blue dot, the only home we've ever known."

-- Carl Sagan, Pale Blue Dot

Leave A Reply