Linux: Fedora 26 major package versions

Fedora 26 has these versions of some core packages:

Package Version
Apache 2.4.26
GCC 7.1.1
Kernel 4.11.8
Perl 5.24.1
PHP 7.1.6
Vim 8.0.662
Git 2.13.0
Leave A Reply

Perl: Variable scoping

Perl allows you scope variables in several ways.

The most common is my which scopes the variable to the surrounding {} (or the entire script/package if there are no {}).

Perl also supports our which is used inside of packages to make a variable global. This allows you to access that variable from a calling script by accessing $Package::variable_name.

Finally there is the local keyword which takes a global variable and makes a locally scoped copy of the variable. Changes to the variable will not be reflected in the global scope.

Name Scope
my Local
our Global
local Temp copy of global
Leave A Reply

PHP: Calculate the percentage difference between two numbers

I need to compare two numbers and see if they're close to each other. Specifically I wanted to see if two numbers were within 3% of of each other. I wrote this simple function to calculate the percentage difference between two numbers, and optionally (with the third parameter) return true or false if they're within a given range. This should allow me to do a "fuzzy compare" on two numbers.

function percent_diff($a, $b, $ok_per = null) {
    $per_diff = abs((1 - ($a / $b)) * 100);

    if (is_numeric($ok_per)) {
        $ok = $per_diff < $ok_per;

        return $ok;
    }

    return $per_diff;
}
Leave A Reply

Linux: Debian 9 major package versions

Debian 9 ships with these versions of some core packages:

Package Version
Apache 2.4.25
GCC 6.3.0
Kernel 4.9.0
Perl 5.24.1
PHP 7.0.19
Vim 8.0.550
Git 2.11.0
Leave A Reply

MySQL: Using if statements for data converstion in a SELECT

I have an integer field in my database that I'd like to display as Yes/No in a report. You can do this conversion in your front end code, or you can use a MySQL if statement to do the conversion for you.

SELECT IF(CustPrimary = 1,'Yes','No') AS CustPrimary FROM Customer;
Leave A Reply

Perl: hashes in list syntax and arrays in hash syntax

Today I learned that Perl list and hash syntax can be used interchangeably. If you use list syntax but assign to a hash Perl will convert the pairs in to hash key/values.

my @array = ("one", "two", "three", "four");      # Create a standard array
my %hash  = ("apple", "red", "banana", "yellow"); # Create a hash using list syntax
my %hash  = ("apple" => "red", "banana" => "yellow"); # Create a standard hash
my @array = ("one" => "two", "three" => "four");      # Create an array using hash syntax

This is also why qw() is able to create hashes. Perl automagically converts lists to hashes if they're being assigned to a hash (and they have an even number of elements):

my %turtles = qw(Donatello Purple Raphael Red Michelangelo Orange Leonardo Blue);
Leave A Reply

Vim: Plugins written in Perl

Vim has it's own internal scripting language called Vimscript, which is complicated and only appropriate in Vim. Most versions of Vim ship with Perl support. I taught myself how to write a simple Vim script in Perl. The following will define a Vim function named CommaToggle, that calls a perl function named comma_toggle. This will toggle spaces after commas on/off.

function! CommaToggle()
perl << EOF

# Get the current line number, and line text
my ($line_num,$column) = $curwin->Cursor();
my $line               = $curbuf->Get($line_num);

if ($line =~ /,/) {
    my $fixed = comma_toggle($line);
    $curbuf->Set($line_num,$fixed);
}

sub comma_toggle {
    my $line = shift();

    if ($line =~ /, /) {
        # Remove spaces after commas
        $line =~ s/, /,/g;
    } else {
        # Add a space after commas
        $line =~ s/,/, /g;
    }

    return $line;
}

EOF
endfunction

Other Vim/Perl commands are available from the documentation. Then you can map a key combination to call that function:

nnoremap <Leader>, :call CommaToggle()<cr>
Leave A Reply

Linux: AC3 is now legally free (patent unencumbered)

The Dolby Surround (aka AC3) audio codec is now legally free, along with MP3.

Leave A Reply

Git: Find the branch that a given commit landed on

If you need to find the branch that a commit was checked in to use the following command:

git branch --contains 26495cfd4ab17d4d685d0d352ed333f73d6d1b96

This should show a list of branches, with the respective branched highlighted and preceed with an asterisk.

Leave A Reply

Git: Finding all commits that match a given line

If you need to show all the commits that modify a specific line you can use git log and the -G flag like this:

git log -G "version" docs/release_history.txt

This will show every commit that contains "version" in one of the modified lines anywhere the file /docs/release_history.txt

Leave A Reply

Chess notation sheet

This my favorite Chess notation sheet in PDF format.

Leave A Reply

Things we know about Benjels

https://www.youtube.com/watch?v=gdwchohlMjI

Things we know about Benjels:

  1. He's over there making the worst calls
  2. He's one of the players
  3. He's one of the coaches in the division
  4. If he passes through the series, then he'll be a hall of famer
  5. He's in charge
  6. He's not even at 480 yet
Leave A Reply

Tar: Auto detecting the compression type

The Linux tar command has a cool feature to auto-detect the file compression based on the archive suffix.

-a, --auto-compress

use archive suffix to determine the compression program

This allows you to change file compressions by just changing the archive suffix:

tar -cvpaf /tmp/backup.tar.gz ~/
tar -cvpaf /tmp/backup.tar.bz2 ~/
tar -cvpaf /tmp/backup.tar.xz ~/

This saves you having to specify -z -j or -J respectively.

Leave A Reply

Disabling an ethernet port via SNMP

Interacting with ethernet ports on an SNMP device is done primarily with two sections of the SNMP tree. IF-MIB::ifOperStatus is the current layer 1 status of the port (i.e. is the port linked or not) and IF-MIB::ifAdminStatus is whether the port is administratively shutdown.

If you want to shutdown an ethernet port on an SNMP enabled device you need to set IF-MIB::ifAdminStatus to integer 2 (down), and conversely setting it to integer 1 (up) will enable the port again.

snmpset -v 2c -c community 192.168.5.1 IF-MIB::ifAdminStatus.5 i 2
Leave A Reply

Books of 2017

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

2017-01-05 - American Gods - 592 pages
2017-01-14 - Different Seasons - 527 pages
2017-01-25 - The Three-Body Problem - 399 pages
2017-01-30 - Wolverine: Days of Future Past - 3 Comics
2017-01-31 - Rogue One: A Star Wars Story - 319 pages
2017-02-04 - Heroes Anonymous - 6 Comics
2017-02-06 - Funny Girl - 452 pages
2017-02-08 - Wolverine: Xisle - 5 Comics
2017-02-09 - All Star Superman - 12 Comics
2017-02-10 - Old Man Logan - 7 Comics
2017-02-11 - X-Men: Days of Future Past - 184 pages
2017-02-11 - Ultimate Iron Man - 5 Comics
2017-02-13 - Heaven Cent - 324 pages
2017-02-13 - Ultimate Wolverine vs. Hulk - 6 Comics
2017-02-19 - Pet Sematary - 374 pages
2017-02-19 - Marvel 1602 - 8 Comics
2017-02-28 - NOS4A2 - 692 pages
2017-03-13 - The Fifth Season - 468 pages
2017-03-17 - Infinity Gauntlet - 6 Comics
2017-03-22 - Bazaar of Bad Dreams - 495 pages
2017-03-28 - Wolverine & The X-Men - 43 Comics
2017-04-01 - The Obelisk Gate - 391 pages
2017-04-08 - Carrie - 199 pages
2017-04-12 - To Kill a Mockingbird - 323 pages
2017-04-19 - Homo Deus - 402 pages
2017-04-23 - Wolverine: Three Months To Die - Book One - 7 Comics
2017-04-26 - The Alchemists of Loom - 382 pages
2017-04-27 - Wolverine: Three Months To Die - Book Two - 6 Comics
2017-04-29 - Schism - 6 Comics
2017-05-03 - Man from Mundania - 344 pages
2017-05-10 - A Long Way Down - 333 pages
2017-05-17 - Petals on the Wind - 448 pages
2017-05-26 - The Wind Through the Keyhole - 307 pages
2017-06-06 - Gwendy's Button Box - 171 pages
2017-06-08 - Startup - 292 pages
2017-06-10 - Death of Wolverine - 4 Comics
2017-06-14 - Seveneves - 861 pages
2017-06-30 - Too Like the Lightning - 430 pages
2017-07-07 - Ninefox Gambit - 317 pages
2017-07-15 - The City of Ember - 270 pages
2017-07-18 - The Handmaid's Tale - 311 pages

Leave A Reply