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: 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 a Next [...]

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 [...]

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 [...]

Comments (1)

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 (3)

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. [...]

Comments (1)

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 [...]

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 [...]

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 (5)

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.  [...]

Comments (3)

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 [...]

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 [...]

Leave a Comment

How-To: Setup Mysql Replication – A simple guide

The following is a simple guide to help you setup Mysql replication – a fantastic way to ensure you have an up-to-date backup of your production databases. This guide only describes a single master-slave relationship, however you can use mysql in various modes which include additional slaves as required.

Comments (1)

How-To: Read an RSS Feed with PHP

An easy way to read an RSS feed with PHP is to use the MagpieRSS library. This provides a simple API to read an RSS feed, and elegantly deal with the issues of timeouts and caching. It’s as simple as: require(‘rss_fetch.inc’); $rss = fetch_rss($url); echo “Site: “, $rss->channel['title'], “<br> “; foreach ($rss->items as $item ) [...]

Leave a Comment

How-To: Determine Real hostname in php

If you need to know the real host name of your server using php, use the following command: <? echo gethostbyaddr (gethostbyname ($_SERVER["SERVER_NAME"])); ?> This will return the server’s hostname, not the address that the script is being accessed by. Very useful if you have a script that needs to run on multiple servers.

Leave a Comment