Archive for the ‘Coding’ Category

MySQL won’t reboot

Sunday, October 11th, 2015

After the 100% full hard disk problem I couldn’t get MySQL to restart. I looked at the error logs and found these lines.

151010 16:51:18 [ERROR] /usr/sbin/mysqld: Table './SS_connellsville/alerts' is marked as crashed and should be repaired
151010 16:51:18 [Warning] Checking table:   './SS_connellsville/alerts'
151010 16:51:56 [ERROR] /usr/sbin/mysqld: Table './SS_greensburg/values_RSSI_3' is marked as crashed and should be repaired
151010 16:51:56 [Warning] Checking table:   './SS_greensburg/values_RSSI_3'
151010 16:51:58 [ERROR] /usr/sbin/mysqld: Table './master/node_groups' is marked as crashed and should be repaired
151010 16:51:58 [Warning] Checking table:   './master/node_groups'

A stackoverflow post recommended using mysqlcheck. It must be used when the mysqld server is running. I couldn’t see how to set it to just repair the databases that were causing problems, but I figured that it wouldn’t hurt to run it on all of them. I was a bit concerned that it would run into problems when the cron jobs ran, but I set it running anyway. It changed the record count on all of the databases and ran for many hours. At least six, but I stopped monitoring and let it run overnight. I stopped MySQL and did a restart and it started without errors.

mysqlcheck --repair --use-frm --all-databases

Grep Tricks

Thursday, October 1st, 2015

Often I need to mess with the content of arrays. They often look like this.

“99”, ”

And I’ll want to delete the contents of one section.

^"([0-9]*)"(,"")(,"[a-zA-Z0-9 ,-/'&#ñéá]*")

This says, start at the beginning of each line ^, look for double quotes, then a number—repeated as many times as you want, then another double quote,

Look for any letter, number, and a bunch of special characters that don’t include double quotes “.

([a-zA-Z0-9 ,-/’&#ñéá]*)

QA Engineer walks into a bar.

Thursday, July 30th, 2015

QA Engineer walks into a bar. Orders a beer. Orders 0 beers. Orders 999999999 beers. Orders a lizard. Orders -1 beers. Orders a sfdeljknesv.

Bill Sempf

Find all the files in a directory.

Saturday, April 25th, 2015

When I find a comic amusing, I grab a screenshot of it. I thought it would be nice to display one comic on my home page each day, so I wrote a little code to look in the comics directory and find all the files, then randomly choose one to display.

There are a few interesting things about the code. First up is scope. Notice that I initialized the two arrays outside of the while loop. That way when I add elements to the arrays, they are not local to the loop. Second, notice that I don’t use an index to add to the arrays. In PHP the preferred way to add an element to an array is with the $arrayName[] notation. Third, I define $location to be the directory handle of the directory. Since I assign it in an if statement, if it fails to find the directory, none of the rest of the code runs. Fourth, I use a similar pattern to read the files in the directory. I read files until there aren’t any more. Finally, I use a flag in my URL so I can proof all of the comics— $all = $_GET[‘all’];.


$title = array();
$comicsLst = array();

$title = array();
$comicsLst = array();

if ($location = opendir('./Comics')) {

    while (false !== ($entry = readdir($location))) {
        if ($entry != "." && $entry != "..") {

            $titleArray = explode(".", $entry);
            $title[] = $titleArray[0];
            $comicsLst[] = $entry;
    $numComics = count($comicsLst);

    $randomComic = rand(0,$numComics);

    $all  = $_GET['all'];

    if (is_null($all)) {
        echo "<p>";
        echo "<img class='align-left' src='/Comics/$comicsLst[$randomComic]' ";
        echo "alt='$title[$randomComic]' title='$title[$randomComic]' /> ";
        echo "</p>";
        echo "<p class='attribution'>";
        echo "<a href='index.php?p=Comics&all=y'>Display all comics.</a>";
        echo "</p>";
    } else {

        for($i=0; $i<$numComics; $i++) {
            echo "<p>";
            echo "$title[$i]<br />";
            echo "<img class='align-left' src='/Comics/$comicsLst[$i]' alt='$title[$i]' /> ";
            echo "</p>";

I frequently find new comics and add them to my local folder. To keep them synchronized with the server, I wrote a little rsync script.

rsync -a -H -vv -z -l --update --delete --exclude \ Comics --exclude .DS_Store ~wellgolly/Documents/Comics/ \
wellgolly@ wellgolly:/www/WellGolly/Comics/ > \
~ wellgolly/Sites/rsync-backup-comics-`date +%F`.log

Remove all the files in a directory with a specific name

Friday, April 24th, 2015

I have a web app that generates temporary files as part of a shell script. The files start with ‘frequency’ and have a hash appended. Sometimes the app doesn’t clear them out. This line does it. At some point I need to put this in a cron job, but I haven’t done it yet.

sudo find /tmp -iname "frequency*" -exec rm -f {} \;

By the way, I think the reason that the files are not cleared out is that they are generated by SpamBots. The code for clearing temporary files is on the display page. It never executes because the page that displays the results is never loaded.

Well Golly

Atheism Plus

Buy from Amazon