Google Analytics

Wednesday, November 18, 2009

Whitelist Twitter emails on Postfix

Unfortunately it seems that Twitter's email servers often end up listed on RBLs like SpamCop, which I use for spam filtering. This means my email account holders don't get emails about direct messages, new followers and other ego-building things like that.

Here's a simple way to white-list these emails for Postfix:
  1. Create a new file /etc/postfix/ip_whitelist with the following contents:

    128.121.146.141 OK
    128.121.146.142 OK
    128.121.146.143 OK
    128.121.146.144 OK
    128.121.146.150 OK
    128.121.146.151 OK
    128.121.146.152 OK
    128.121.146.153 OK

    These map from mx001.twitter.com to mx008.twitter.com, which seem to be all they have for now.

  2. Run: postmap /etc/postfix/ip_whitelist

  3. Edit your /etc/postfix/main.cf file to include the IP whitelist. Find the line where you have your RBL checks, e.g.:
    reject_rbl_client bl.spamcop.net
    and add the following line above them:
    check_client_access hash:/etc/postfix/ip_whitelist

  4. Restart Postfix.

These vital emails should now get through to your psychologically fragile account holders.

Monday, August 03, 2009

Apache segfaults after enabling the Zend Framework on Ubuntu Jaunty

After installing the Zend framework on an Ubuntu Jaunty server (PHP 5.2.6-3ubuntu4.1 Suhosin-Patch 0.9.6.2):

# aptitude install zend-framework

I uncommented the line with the include path to make it usable:

# vim /etc/php5/apache2/conf.d/zend-framework.ini

[Zend]
include_path=${include_path} ":/usr/share/php/libzend-framework-php"


Then restarted Apache. Unfortunately it crashed straight away:

Aug 3 11:42:44 the-lake kernel: apache2[17487]: segfault at 0000000000000008 rip 00002b3c755d5070 rsp 00007fff3d94c1c8 error 4

Some searching revealed it was this bug.

Setting an initial include_path in /etc/php5/apache2/php.ini worked around the problem.

Wednesday, June 03, 2009

A fix for Windows Vista not connecting to a wireless network

Today my girlfriend's laptop (running Windows Vista) would not connect to my wireless network. It connected to her uni wireless network fine and was connecting to mine fine up until now. It had recently been upgraded to Service Pack 2, so this may have triggered the problem.

I unsuccessfully tried
  • rebooting,
  • removing the access point from its list of 'remembered' points, and
  • reinstalling the wireless card driver.
After some Googling the solution that worked for me was to create a new 32-bit DWORD value called ArpRetryCount in:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\
and leaving its value at 0. After rebooting it connected as normal.

Here is a .reg file to automatically apply the fix.

Monday, June 01, 2009

Installing the Passenger gem on Ubuntu

I just tried to install Passenger on my Ubuntu-based Linode. I like to use the gem (as opposed to distro packages) to make sure I keep up with new version releases. Unfortunately when I tried I got this error:

# gem install passenger
Building native extensions.  This could take a while...
ERROR:  Error installing passenger:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install passenger
extconf.rb:8:in `require': no such file to load -- mkmf (LoadError)
        from extconf.rb:8

Since the machine is a VPS I like to try and keep the number of unnecessary packages down to a minimum. It turns out the only extra package I needed to install was ruby1.8-dev.

After Passenger built successfully, I had to add /var/lib/gems/1.8/bin into my $PATH and run passenger-install-apache2-module (which contained cushy step-by-step instructions from that point on).

Friday, May 15, 2009

Fixing the infamous Amavis + SpamAssassin cron messages

I'm using Amavis and SpamAssassin together on an Ubuntu server. For some reason, a cron email was being generated every 3 hours that looked like this:

bayes: synced databases from journal in 0 seconds: 811 unique entries (1420 total entries)

There is a bug report filed about it here but the solution didn't help me.

The file responsible for generating this message is /usr/sbin/amavisd-new-cronjob. I was able to stop the annoying messages by changing line 26 from:
exec ${CMD}
to
exec ${CMD} >/dev/null 2>&1
While this may clobber useful error messages as well, my care factor is low after being spammed so much.

Tuesday, May 12, 2009

Hiding windows with Ruby and appscript on OS X

At the moment I'm writing a Ruby script that interacts with iTunes on OS X. Fortunately this is fairly easy to do using the AppleScript bridge rb-appscript.

My problem was that I needed to hide the iTunes window (the same as using the ⌘H shortcut) so that the Ruby application didn't lose focus. Unfortunately it took me a long time to find out how to do it.

I didn't need to deal with OSAX. Here's a snippet of code that demonstrates the necessary incantation:
require 'rubygems'
require 'appscript'

itunes = Appscript.app('iTunes')
itunes.activate()
itunes.stop
# Hide the iTunes window
Appscript.app('System Events').processes['iTunes'].visible.set(false)
Here is what the actual AppleScript (which I was able to find easily) looks like:
tell application "System Events"
    set visible of process "iTunes" to false
end tell
You can see how the 'Rubyised' version maps to it, although it took a lot of Googling to translate!

Friday, May 08, 2009

Cryptic MySQL Error Message

I came across an interesting but cryptic MySQL error message today that took me a while to figure out.

After creating a bunch of InnoDB tables on this particular server, I tried to create some indexes and insert some data. Both types of operations failed with an error message that looked like this:

ERROR 1025 (HY000): Error on rename of './dbname/tablname' to './dbname/#sql2-12bb-9474d' (errno: -1)

After some looking around I came across this amusing bug report, which explained that this message could be due to the innodb_force_recovery setting being set to a non-zero value.

Sure enough, running SHOW VARIABLES LIKE 'innodb_force_recovery'; revealed that it was set to '4' instead of '0'. I now have a sys-admin to kill.

Thursday, February 05, 2009

406 Not Acceptable error using jQuery AJAX

I was scratching my head over a problem today where a jQuery ajax request was failing on one particular web server with a '406 Not Acceptable' error. It had been tested on many other servers without any trouble, but this seemingly normal Apache server wasn't having a bar of it.

It turned out the problem was that I was submitting the ajax request using the POST method but not actually sending any post data. For example:

$.ajax({
   type: "POST",
   url: "index.php?action=foo",
   success: function(msg){
     // ...
   }
 });

Changing it to a GET sorted out the problem.