ZSTD compression level with tar

I've been using zstd more and more for general compression. Using it with tar is pretty straight forward:

tar -cvpf -I zstd /tmp/etc.tar.gz /etc

This does not allow you to set the compression ratio however. After some digging I found an environment variable that controls the default compression level. If you run tar like this you can change the default compression level.

ZSTD_CLEVEL=19 tar -cvpf -I zstd /tmp/etc.tar.gz /etc

GZip has a similar variable, but it will allow any command line variable (not just compression ratio).

GZIP=-9 tar -cvzpf /tmp/etc.tar.gz /etc
Leave A Reply

Restricting SSH sessions to a single command

Using SSH keys to allow passwordless logins to a server allows cool scripting opportunities. You may want to allow a user to login via SSH, but restrict them to a specific command. This can be done with a command option in your authorized_keys file. If you prepend a command="" option to your SSH key line, SSH will force that command to run that command every time a user with that key connects.

command="/usr/bin/ls /etc -lsa" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDunzvfGJi4qcHixaoCQ0k1kociSYfIlwhXzI1ywtltA user@desktop
Leave A Reply

Javascript: Get a unixtime value

I need a Unixtime in Javascript. This is the simplest way I came up with to get that value:

var unixtime = parseInt(new Date().getTime() / 1000);
Leave A Reply

HTML5 + CSS toggle slides

I was looking for a mobile friendly slide toggle but not having much luck. There a lot of options but I want something flexible, something I could modify with JavaScript, and something that is HTML form compliant. I ended up modifying this W3C example and bundling it in a CSS file. It uses CSS calc() and CSS variables so it requires a semi-modern browser.

SlideToggle demo

Leave A Reply

Git: Show all commits that affect a certain line

I found a bug on a particular line, and need to track down the history for that line. This is easy enough with git blame, but in this case I'm getting false positives. There was a previous check-in that changed whitespace on that line. Obviously that was not the commit that introduced the bug.

Using git log with the -L flag you can specify a file and and range of lines to search through.

git log -L 57,57:index.php

This will show all the commits in index.php where there was a change on line #57.

See also: Finding commits that match a search term

Leave A Reply

How Lovecraft's Old One's drive people mad

Reddit user thomascgalvin has an amazing summary of why encountering one of Lovecraft's Old Ones would almost instantly drive you mad.

When you were a child, you were probably taught that you have five senses: sight, sound, touch, taste, and smell. This is true, but it's incomplete.

You have plenty of other senses. A sense of balance. A sense of time passing. A sense of changing temperatures. A sense of where your body is in space. A sense of acceleration. A sense of pain. A sense of loss. A sense of joy. A sense of agency. A sense of belonging.

You perceive the world around you in a dozen different, subtle ways, many of which you can't even name, and most of which you are completely unaware of, unless something goes wrong.

The right (or wrong) stimulus can completely change our psychology. When someone sees the Grand Canyon for the first time, they often report a feeling of overwhelming awe at the sheer size and spectacle. When astronauts return from space, return from seeing this great world of ours reduced to a tiny blue marble out the window, the report a sense of overwhelming concern for, and oneness with, humanity. When someone takes psilocybin or DMT, they report an expansion of their mind that fundamentally alters who they are as a person.

But what about people who have seen the horrors of war? People who have suffered at the hands of an abusive lover? Or people who have suffered something as simple as a car crash, and now break out in a cold sweat every time they drive? The wrong stimulus, applied to our normal, human senses, can irreparable harm us.

When someone sees a Great Old One, the sheer monstrous nature of it, the impossibility, the implacability, the inhuman and inhumane otherness of the thing that they have laid eyes on, is enough to shatter, completely and forever, their sense of who and what and why they are. It's like looking at the splendor of the Grand Canyon and realizing that it will absolutely destroy you, not because it hates you, not because it needs to, but because that is simply what it is.

Just as you were unaware of the fact that you aren't falling until I just mentioned it, you are not aware of the fact that you believe that you are important, that you matter, that you have any hope at all of making a difference in this vast and careless universe until something forces you to confront that fact. And that is what the Great Old Ones do. When you look upon them, you are looking at a power so vast and ancient and amoral that any sense of normalcy you once had will be forever torn away.

And that's just what we can explain with out current understanding of the human mind. Who's to say that we don't have some other sense, a sense of the cosmic, a sense of the psychic, that is triggered by the presence of a Great Old One? Who's to say that some sense, long dormant in the safety of our comfortable little world, isn't woken up as soon as one of those eldritch abominations appears before us?

Leave A Reply

Perl: Open a serial port at a given speed

I needed to open a serial port to read and write data from my Arduino. The after much digging I was able to come up with the following function to get a file handle for a given serial port at a specific speed.

use Fcntl qw(O_RDWR);

# Open a serial port at a given speed and return a filehandle
sub open_serial_port {
    my $dev   = shift();
    my $speed = shift();

    sysopen(my $fh, $dev, O_RDWR) or die("Unable to open $dev\n");

    # Figure out the integer that maps to a given speed
    # perl -E 'use IO::Tty qw( B115200 ); say B115200'
    my $speed_map = {
        9600   => 13,
        19200  => 14,
        38400  => 15,
        57600  => 4097,
        115200 => 4098,

    my $speed_int = $speed_map->{$speed};
    if (!$speed_int) {
        die("Unable to find speed $speed\n");

    # Set the baud on the FH
    my $attr = POSIX::Termios->new;


    return $fh;
Leave A Reply

Perl: Check if a pid is active

If you need to see if a pid is currently active you can use send the process a null signal using kill(). You can create a function to check the status of a pid like this:

sub is_running {
    my $pid = shift();

    # Check if the pid is active
    my $running = kill(0, $pid);

    return $running;
Leave A Reply

Expanding a QCOW disk image

If you're using qcow VM images and need to expand storage capacity it is very easy. Simply shutdown the VM, and run the following command on the VM image file.

qemu-img resize /mnt/server/server.qcow +10G

This will add an additional 10GB to the image. Next, boot the VM back up and resize the partitions to use the newly added space. As your / partition is usually last you can just delete your existing partition, and immediately create a new partition with the added 10GB of space. Then you can use resize2fs for ext3/ext4 file systems, or xfs_growfs for xfs file systems to expand the partition to file the added space.

Borrowed from positon.org.

Leave A Reply

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
2019-01-22 - Infected - 382 pages
2019-02-08 - Hitchiker's Guide to the Galaxy - 210 pages
2019-02-17 - The Restaurant at the End of the Universe - 217 pages
2019-02-24 - Good omens - 354 pages
2019-03-24 - Myth Adventures - 599 pages
2019-05-06 - Xenocide - 592 pages
2019-06-24 - Roll of Thunder Hear My Cry - 210 pages
2019-07-01 - White Fang - 180 pages
2019-07-17 - Flying Solo - 138 pages
2019-07-29 - Outsiders - 192 pages
2019-08-17 - The Right Stuff - 352 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 United States 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. To truly abolish the electoral college would require a constitutional amendment, the last of which was passed in 1992, and I think very unlikely.

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 national 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