Tech Thought

Tech tips, hints, and general musings. PHP, Perl, Mysql, Javascript, AJAX, JSON, Linux, Mac OSX

Entries for the ‘How To’ Category

How-To: Automatically sync your iTunes library with all your computers

I’ve come across a problem - my main computer (a MacBook Pro) has all my music on it, and is hooked up to my iPhone. But I’ve just got a nice big flat screen TV and its connected to my stereo. So I want to be able to play music/movies I buy on [...]

Leave a Comment

How-To: Redirect to different URL using Javascript or META tags

If you need to redirect from one page to another, you can achieve this with either a META tag redirection or Javascript.  See below for an example.  You should provide a manual link as not all browsers support META tags - and javascript won’t work if its been disabled:
<html>
<head>
<title>Move my domain!</title>
<meta http-equiv=”refresh” content=”url=http://www.newdomain.com”>
<script language=”JavaScript”>
function Redirect()
{
window.location [...]

Leave a Comment

How-To: Fix Problems with Google Maps and Internet Explorer: Grey Background, Clipping, Off centre etc

We’ve just developed a Google Maps application - all using Firefox - and started to test it in IE.  We were shocked to find that our map looks completely off centre and have a big grey backround across them.  Moving the map with the mouse causes them to clip and look shocking!
See below:

So how do [...]

Leave a Comment

How-To: Add days to a date with Mysql

A common thing you need to do in mysql is add an interval of time to a date in a query.  Here is a simple example of how to do this:
SELECT Risk.*
FROM Risk
WHERE (Risk.Next_Reminder_Due IS NULL OR
Risk.Next_Reminder_Due < DATE_ADD(NOW(), INTERVAL 7 DAY))
This returns all ‘risks’ that either have [...]

Leave a Comment

OS X: Mail Tip - Speedy filing of emails from your inbox

In Mac Mail, I like to file all emails out of inbox when processed. But I have a huge folder tree to traverse to find where to move a messg to. I liked the right-click Move To menu, but its not fast enough.
My newly discovered solution:
1. Select message(s) to move
2. Click on the Help menu [...]

Leave a Comment

How-To: Remotely monitor your server with monit

moint is a fantastic utility that can be installed on Linux or Mac OS X and provides the ability to monitor services running on your server.  These could be apache, mysql, bind or any other service you need to be up and running.  After installing monit, you create a config file containing information about the [...]

Leave a Comment

How-To: Redirect all requests to maintenance page with mod_rewrite

A common requirement when performing maintenance on your website is to redirect all requests to a downtime message. This can be very easily achieve using mod_rewrite and a .htaccess file. Simply create an .htaccess file with the following commands:

RewriteEngine On 

RewriteRule !^site-down\.html$ /site-down.html [L]

This will redirect all requests to the site-down.html file. Once [...]

Leave a Comment

How-To: Embed high-resolution YouTube videos on your site

We had a YouTube video of our product embedded on our website, however it was pretty low-resolution. I wanted to make it display in higher quality, however still making use of YouTube’s servers.
After a little sniffing around, I discovered that you simply add a little bit extra to the embed parameters and it embeds [...]

Comments (1)

How-To: Install Subversion (SVN) 1.5 on Mac OS X

We use CVSDude.org to host all our subversion repositories.  They have recently upgraded to subversion 1.5.0 which is not compatible with 1.4.x clients.  Unfortunately the command line utility that is built into Mac OS X is only at version 1.4.4 on my MacBook Pro - so I needed a way to upgrade to version 1.5.
I’ve [...]

Leave a Comment

How-To: Removing trailing whitespace from a string with php

Need to remove the trailing whitespace characters from a string in php? chomp() is how you do it in Perl, however in PHP it’s just as easy. Simply use rtrim():

// $string = “|my string with trailing whitespace |”
$string = rtrim($string);

// $string = “|my string with trailing whitespace|”

It’s that easy! There is [...]

Leave a Comment

How-To: Check a Reverse DNS Record Lookup (PTR Record) and Solve Email Delivery Issues

More and more mail servers are starting to reject email if your outgoing mail server doesn’t have a reverse DNS record or PTR record. You can check if you have one by issuing the following command:

dig -x 127.0.0.1

Obviously, replace the 127.0.0.1 address with the relevant IP address of your mail server. You should [...]

Leave a Comment

Speeding up prototype.js and scritaculous

We use prototype.js and scriptaculous for a number of our sites and applications - they provide great foundations with which to build advanced javascript applications. However they can be fairly large and take a while to download.
As I’ve previously mentioned on this blog, you can get pre-shrunk versions of both prototype and scriptaculous which [...]

Leave a Comment

How-To Fix: Firefox 3 - Image cannot be displayed, because it contains errors

A number of people have reported problems viewing some images in Firefox 3, where they get the error:
<image> cannot be displayed, because it contains errors
Amazingly enough, there is a very simple fix to this problem - disable the Skype Add-On for Firefox.  This can cause this problem to occur, so disabling it often fixes the [...]

Leave a Comment

How-To Fix: make: yacc: Command not found

I have been getting the following error when trying to compile monit for my CentOS server:
make: *** [y.tab.c] Error 127
To resolve it, I simply installed bison:
yum install bison
Then run configure again:
./configure
make && make install
And that fixed the problem!  Hope that helps someone.

Leave a Comment

How-To: Configure Postfix to Relay based on Domain

We use Postfix as a dropin replacement for Sendmail on our servers.  We wanted to configure postfix to relay email via our internal mail server for internal email addresses, and send directly if the email address was external.
To do this, follow these steps:

Edit the /etc/postfix/transport file and add the following line:
myinternaldomain.com smtp:[ipaddress]:25
Edit the [...]

Leave a Comment

How-To: Read an Excel (.xls) file with Perl

I’ve been working on a data import recently that required me to pull in the contents of a folder full of excel documents, all with the same structure containing data that needed to be collated into a single file.  There really isn’t an easy way to read Excel (xls files) in PHP so I’ve reverted [...]

Comments (1)

How-to Fix: An invalid public movie atom was found in the movie.

Recently I’ve had a problem with Quicktime throwing up the following error when trying to play a video:
“An invalid public movie atom was found in the movie.”
I’ve searched everywhere for a solution, and couldn’t find one in forums or tech hint sites.  However I think i’ve just solved it - for me atleast.  I just [...]

Leave a Comment

Animated Gifs for Mac OSX: GIFfun

I wanted a tool to create animated logos for Mac OS X.  After a little looking around on Google and various message boards, I settled on GIFFun.  Its a simple tool that allows you to plonk a whole heap of images into its window, and turn them into an animated GIF.
You can control the delay [...]

Leave a Comment

How-To: Resyncronise a mysql replication slave

Recently we’ve been having some problems with our production server. Every now and then it just reboots - for no aparent reason. We’re still looking into the reason this occurs (looks like an overheating CPU) however when the reboot occurs, it causes our Mysql replication slaves to get out-of-sync with the master.

Leave a Comment

How-To: Convert Epoch to Normal Time

If you want to covert from epoch (number of seconds since 1970) to a more human readable format, you can use this simple perl script:

#!/usr/bin/perl
$time = localtime($ARGV[0]);
print “$time\n”;

Save it as epoch.sh and make it executable, then simply issue the following command from the command line:

$> ./epoch.sh 1211926097
Wed May 28 08:08:17 2008

It’s that easy!

Leave a Comment