Beutelevision

by Thomas Beutel

Extract TTF Font From Mac Font Suitcase

I recently needed to extract a TTF version of a Mac font suitcase and after trying a bunch of different methods, I found a tool called Resource Finagler.app. It is available from this page on StackOverflow:

Using OS 9 resource fork fonts in CSS

Basically, you open the font suitcase, find the sfnt part, and drag it out to your Desktop and you will have a TTF file ready to use. Here is a screenshot of me dragging the sfnt part out of Resource Finagler.

Resource-Finagler-example

Brother HL-L2340DW, Windows 7 can’t see Airport Extreme wireless network

I was helping a friend install a new Brother HL-L2340DW laser printer today and I had a heck of a time getting the WIFI to work on it. All the Macs and my iPhone could see the wireless network just fine, but the printer and a Windows 7 laptop just didn’t see it, even though they saw a bunch of other wireless networks from around the neighborhood. I discovered that they were using an Airport Extreme so I opened up Airport Utility on one of the Macs to see if the Airport Extreme was somehow hiding the network, even though I could see it on my iPhone. The network wasn’t hidden but I found that the Radio Mode was set to 802.11a compatible.

airport-utility

I changed it to 802.11b/g compatible and then everything worked. Once this was fixed, setting up the laser printer was a breeze.

Datatables in a Colorbox iframe with Selected Row Returned to Parent Window

I recently created a form where one of the questions was asking for a specific code (specifically, a NAICS code). The problem was that there are almost 20,000 codes to choose from, so it was not practical to use a pulldown. I hit upon the idea of using the wonderful Datatables table plugin for jQuery. I didn’t want the table to be in the form, so I decided to display it in a Colorbox iframe.

The challenge was how to report back the selected code. I decided to have datatables add a column of radio buttons and then use a regular button to report back the value to the parent window.

Here is how I set up the datatable:


<script>
$(document).ready(function() {
  $('#naics').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": "/main/NAICSTableData", // see Server Side Processing
    "createdRow": function ( row, data, index ) { // add radio buttons
    $('td', row).eq(0).html('<input name="codeid" value="'+data[1]+' '+data[2]+'" type="radio" class="code-select">');
    }
  });
  $('#use-selected').click( function() {
    var selected_code = $('input[name=codeid]:checked').val();
    parent.UpdateCode(selected_code); // this function must be defined somewhere in parent
    parent.jQuery.colorbox.close();
  });
});
</script>
<table id="naics" class="display" width="100%" cellspacing="0">
<thead>
<tr><th></th><th>Code</th><th>Description</th></tr>
</thead>
<tbody>
</tbody>
</table>
<input id="use-selected" type="button" value="Use Selected Code" />

The UpdateCode function in the parent window looks like this:


<script>
function UpdateCode(selected_code){  $('#naics-code').val(selected_code);
</script>
<input type="text" name="naics-code" id="naics-code" value="" />

Here is what the table looks like in its colorbox:

Screen Shot 2015-01-23 at 4.03.42 PM

Overall I’m really happy with the performance of the searching and the fact that the value is fed back to the form in the parent window.

Patch old Fedora 8 server for Shellshock Bash bug

I had an old Fedora 8 server running legacy code that I needed to patch for the Shellshock Bash bug. I proved that bash was vunerable by running this command:

env X="() { :; } ; echo busted" /bin/bash -c "echo stuff"

I saw the word “busted” in the output, meaning I needed to upgrade bash.

While newer systems have a patch available, I was not able to find one for Fedora 8, so I patched it manually by building a patched version of bash 4.2. Here is what I did:

yum install bison # in case yacc is not installed

cd /usr/src

curl -O http://ftp.gnu.org/gnu/bash/bash-4.2.tar.gz
tar xvfz bash-4.2.tar.gz
cd bash-4.2

for i in $(seq -f "%03g" 0 48); do curl https://ftp.gnu.org/pub/gnu/bash/bash-4.2-patches/bash42-$i | patch -p0; done

./configure --prefix=/usr \
--bindir=/bin \
--htmldir=/usr/share/doc/bash-4.2 \
--without-bash-malloc \
--with-installed-readline

make && make install

Once this was done, I ran the following command again:

env X="() { :; } ; echo busted" /bin/bash -c "echo stuff"

The output now reports an error, showing that bash is patched.

/bin/bash: warning: X: ignoring function definition attempt
/bin/bash: error importing function definition for `X'

Your mileage may vary. As with all updates of this sort, be sure you have a backup plan in case something goes awry.

Apple Mail – Archive IMAP Emails

I get about 3000 emails a month (a lot of them are server notifications if you are wondering) and I like to keep all my email because I do frequently refer to older emails. I think of my emails as a database that I can search for conversations, attachments and personal history. Gmail is a great way to keep all of your email but Gmail has limits, beyond which you need to pay a fee. Other IMAP type accounts like iCloud have similar limits.

What I like to do  is to keep all email older than 2 months on my computer rather than paying for more storage. To do this in Apple Mail I set up a simple rule like this:

archive mail ruleTo use this rule, I do a Select-All on my inbox every month or so and then do Message->Apply Rules and let it run. All emails older than 2 months get moved from my Gmail account into an archive folder on my Mac. I create a new archive folder every year and update the rule to use the new one.

It is important to note that even though this rule is applied to every incoming email (as are all rules in your rules list), no incoming email will ever be moved because incoming email will never be older than 2 months old. That is why you need to Select-All and Message->Apply Rules manually. I suppose you could schedule this activity in your calendar but for me it’s just one of those things I do when I see that the number of emails in my inbox is getting large.

 

Suppress Test::More Output For Use In Nagios

I needed a quick way to check for XML well-formedness in a Perl Nagios script and I found that Test::XML has a test called is_well_formed_xml($xml) that does the job nicely. The only problem was that as part of the Test::More framework, Test::XML outputs test results (as it should). In my case though, I just wanted to perform the test. So I was able to suppress the output like so:

Test::More->builder->output('/dev/null');

Here is a larger code fragment if you are interested:

use Getopt::Euclid;
use Test::XML;
use Test::More;

Test::More->builder->output('/dev/null');

my $warning = $ARGV{'-w'};
my $critical = $ARGV{'-c'};

my $xml = `curl --silent 'http://example.com/some-xml-source.xml'`;

my $well_formed = is_well_formed_xml($xml);
done_testing();

if (!$well_formed) {
print "CRITICAL - XML not well formed\n";
exit(2);
}

# ... checking XML content for OK and WARNING states not shown here

I’m sure there are other quick ways to check for well-formedness but this is working well for me.

Updated WordPress, PayPal IPN no longer works

I recently updated a client’s WordPress to 3.9.2. There was a page on that WordPress that served as the PayPal notify_url and it had been working fine up until I updated. The page simply used a shortcode that I created in the functions.php file to process the incoming PayPal parameters.

After the update, what I noticed is that when I tested the page myself, the Apache log reported that 44810 bytes were being sent to the requester (me), which is the full rendered page. And the shortcode function was running properly. I added logging at the head of the function so that I could verify that it was being called.

But when PayPal requested the page, only 16620 bytes where being sent and the shortcode function was not being called. The only difference that I could see was that I was using HTTP 1.1 and PayPal was using HTTP 1.0.

I never did figure out why the difference in response bytes. And I ran out of ideas of what to test.

So what I did instead was to implement the notify_url as a standalone PHP script and that took care of the problem. It now works fine with PayPal.

It is clear to me that there was something subtle that I was missing now that WordPress was at 3.9.2. But what it is, I have no idea.

South Napa Earthquake Surface Rupture Mapped

Mike Oskin (@mikeoskin) from U.C. Davis tweeted on late Sunday that PhD students Alex Morelan and Chad Trexler had gone out in the field in the Napa area and mapped several surface ruptures related to the South Napa earthquake of Aug 24, 2014. Additional tweets showed pictures of the ruptures.

Update: Here is an announcement regarding surface rupture mapping by USGS geologists: Update on the Magnitude 6 South Napa Earthquake of August 24, 2014

Nagios, Belkin WeMo and a Plasma Globe

Plasma GlobeI monitor a number of servers using nagios and I always thought it would be neat to be able to have some sort of ambient device light up when there was a critical problem.

Yes, I get email and text alerts, and nagios is always up in one tab on my browser, but I wanted to have something there in the periphery of my vision just as an extra queue. Well a couple of years ago I got a small plasma globe and it’s really cool, but I wasn’t using it much just by itself. So it occurred to me that it would be the perfect device to have light up when nagios detected a problem. I’ve been wanting to do this for the longest time but it wasn’t until Belkin came out with WeMo that I figured out how to do it and it was pretty easy.

I plugged the plasma globe into a WeMo Switch and configured the switch with the free WeMo iPhone app. Then I created the following Perl script that I call nagios_wemo.pl:

#!/usr/bin/perl
use warnings;
use strict;

# Get the following packages from CPAN
use WebService::Belkin::WeMo::Discover;
use WebService::Belkin::WeMo::Device;

# Create connection to my WeMo switch
my $wemo = WebService::Belkin::WeMo::Device->new(ip => '192.168.1.13', db => '/etc/belkin.db');

# Grab HTML of Nagios status page
my $html = `curl --user nagiosadmin:<password> --silent 'http://<my-server>/nagios/cgi-bin/status.cgi?host=all'`;

# Look for serviceTotalsCRITICAL or hostTotalsCRITICAL
if ($html =~ m/(serviceTotalsCRITICAL|hostTotalsCRITICAL)/i ) {
$wemo->on();
} else {
$wemo->off();
}

Then I added the script to my crontable:

* * * * * /Users/thomas/code/nagios_wemo.pl

Now, any time a server or service goes critical, the plasma globe turns on, and when the problem is resolved, it turns off.

I used Perl for the script, but you could also just use a shell script such as this one here.

Poor Design – Yahoo Asks You To Upgrade Firefox Within Safari

Every so often I have the opportunity to help a friend with a seemingly intractable computer problem. More often than not, the problem is not really a problem at all, it is just plain awful design. Case in point:

Screen shot 2013-11-11 at 5.28.23 PM

My friend was using Safari and this appeared every time he wanted to access his email. And he desperately wanted to do the right thing, which was to upgrade and make this recommendation go away. So he tried to upgrade Safari, which he can’t because he is still on Snow Leopard. So then he tried upgrading Firefox, thinking that perhaps that it might be a plugin issue. So he downloaded Firefox, installed, and rebooted. And every time he opened up Safari, this message appeared. Being determined, he did this seven times. He was really upset and frustrated because he tried to do the right thing but couldn’t, and so he called me.

The point is not that my friend didn’t know that Firefox was an alternative to Safari. The point is that you should not be asking your users to upgrade a browser different from the one they are using. Safari has no knowledge of whether Firefox is up to date, nor should it.

My friend is not only person struggling with this:

http://answers.yahoo.com/question/index?qid=20131102090133AABf6R1

What did I advise my friend to do? Just ignore Yahoo’s recommendation and continue on to Mail.