HOWTO get the real host name of your server in PHP

In PHP, to get the name of the web server, you can print $_SERVER[“HTTP_HOST”]. However, if you use round-robin DNS or a load balancer, this will give you the name Apache thinks your machine is.

What if you want the real hostname — what you’d get from hostname or uname?
print gethostbyaddr("127.0.0.1");

That’s all. It sure beats the pants off:
print trim(`hostname`);

keywords: php hostname local computer server HTTP_HOST

JavaScript: how to unescape HTML entities

I was searching the web for JavaScript HTML entity unescaping code. I found lots of really bad ideas. Sound familiar? Some were quite complicated.

It looked like the scriptaculous guys had the right idea. However, all I could find was a cached page with no code. A quick peek inside prototype set me on the right track.

String.prototype.unescapeHtml = function () {
    var temp = document.createElement("div");
    temp.innerHTML = this;
    var result = temp.childNodes[0].nodeValue;
    temp.removeChild(temp.firstChild);
    return result;
}

And the code in action:

var hello = "Hello José";
alert(hello.unescapeHtml());

How to create a self-signed SSL certificate for Dovecot on Debian

Here is how you create a self-signed SSL certificate for the Dovecot IMAP/POP server on Debian Linux:

openssl req -new -x509 -days 1000 -nodes -out "/etc/ssl/certs/dovecot.pem" -keyout "/etc/ssl/private/dovecot.pem"

The default is 365 days, but I upped it to 1000, so I don’t have to do this so often.

Dovecot does this on installation via /var/lib/dpkg/info/dovecot-common.postinst; you can force this script to re-run by issuing these two commands:
find /etc/ssl -name dovecot.* -exec rm {} \;
dpkg-reconfigure dovecot-common

Stop FISA “compromise” sham and telecom immunity

Please call today and oppose the FISA Amendments Act (HR 6304).

It is not acceptable to give away our civil liberties. Granting retroactive immunity to telecom companies is wrong.

This bill is not a “compromise.” It is a get-out-of-jail-free card bought by lobbyists for large phone companies. No matter how illegal, offensive or intrusive a company’s invasion of your privacy has been, it won’t make a difference if this legislation passes. If the president gave the company a note claiming their behavior was legal, they’re completely off the hook.

If we want to change Washington, it starts by telling Verizon, AT&T and Sprint that buying votes after they broke the law will not be tolerated:

All House Members (June 20th vote:)
Verizon, AT&T, and Sprint gave PAC contributions averaging:
$9,659 to each member of the House voting “YES” (105-Dem, 188-Rep)
$4,810 to each member of the House voting “NO” (128-Dem, 1-Rep)

Here’s what you can do:

  1. Go to Stop The Spying and find your Senator’s contact information. Call them now.

    California people: Dianne Feinstein’s office numbers are:
    202-224-3841 (DC)
    310-914-7300 (LA)
    619-231-9712 (SD)
    415-393-0707 (SF)
    559-485-7430 (Fresno)

    Barbara Boxer’s office numbers are:
    202-224-3553 (DC)
    213-894-5000 (LA)
    619-239-3884 (SD)
    415-403-0100 (SF)
    559-497-5109 (Fresno)
    916-448-2787 (Sacramento)
    909-888-8525 (Inland Empire)

  2. Call the Obama offices. Tell them not only must Senator Obama oppose this bill, but he needs to join in any filibuster.
    866-675-2008 (campaign headquarters)
    202-224-2854 (DC)
    312-886-3506 (IL)

  3. Join the Senator Obama Please Vote Against FISA group on my.barackobama.com. It’s currently the #5 biggest group on barackobama.com. Let’s make it #1.

HOWTO disable overlays in Boinx FotoMagico standalone players

FotoMagico is program that lets you create amazing slideshows. In FotoMagico, slides advance in one of two ways:

  1. automatically, after a set time period
  2. after a mouse click

If you’ve picked option (2), you see a “fast forward” overlay when you click the mouse:

I dislike this. Fortunately, there’s a preference to turn this off.

FotoMagico lets you export your slide shows as standalone player applications, and distribute them to anyone with a Mac.

I found one problem, however. Even when you turn off “Visualize Interactive Control,” the standalone player does not respect this preference. That means you always get the “fast forward” overlay. Yuck.

Fortunately, there is a workaround. If you peek inside the bundle for FotoMagico, you’ll notice it has a CFBundleIdentifier of com.boinx.fotomagico.

If you run defaults read com.boinx.fotomagico before and after setting the preference, you’ll see one line appear:
"PrefsKey_DisplayOverlays" = 0;

Now, look at the Info.plist inside the player. Its CFBundleIdentifier is com.boinx.fotomagico.player.

This means, the fix is simply:
defaults write com.bound.fotomagico.player PrefsKey_DisplayOverlays 0