Tech Thought

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

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 iTunes through my stereo and on my shiny new TV.

Unfortunately my laptop is used for work and isn’t always at home, so I can’t just share my library and play music etc over the air (this doesn’t work for movies anyway).  So I’ve come up with a solution that works really well, and is completely automated.

[Read the rest of this entry...]

iPhone 2.0.2 Available on iTunes Now - Fixes optus iPhone issues?

Apple has just released iPhone firmware version 2.0.2 via iTunes. Simply plug your iPhone into your computer and you will be prompted to update. As usual, all we know at this stage is that it contains bug fixes however hopefully we’ll find out more as time goes on…

Update: it’s rumoured that this update will fix the issues that customers around the world (including Optus here in australia) have been experiencing.

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 = 'http://www.newdomain.com';
}
</script>
<body onLoad='Redirect()'>
</body>
</html>

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 we fix this?  It turned out that IE doesn’t like you writing script inside a <table> tag - which we were doing.  So we simply changed this code to run on the onLoad() event of the page, and it was all fixed!

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 Reminder Due of NULL or within the next week.

Read more about Mysql’s date functions on the Mysql Date & Time Functions Manual Page.

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 in menubar
3. In Search (which is selected already) just type some letters of the folder I want to move it to
4. Because of super-cool menu-search built into help, it it finds my folders matching, and down-arrow+enter does the move

Its fast. And faster if you use Help’s shortcut key (shift+command+?).

(Thanks to John C for this tip!)

WSP Offers Australian Based iPhone Application Development

WSP Online Solutions, a division of WSP Environmental, today launched its Australian based iPhone development services.  iPhone application development is somewhat of a niche market, given that Objective-C (the language used to development native iPhone applications) is not commonly used outside of the Mac community.  As a result, the Australian based iPhone development community is fairly small.

WSP Online Solutions is looking for iPhone development projects, partnerships and R&D projects both large and small.  If you have a need for either web based or native iPhone application development - or simply have an idea you’d like to see turned into an application, head over to their site and send them an email!

iPhone 2.0.1 Firmware update causes Carrier Update 0xE8000001 Error

I’ve just updated the firmware on my iPhone to version 2.0.1 (after much buzz on the web about its speed improvements).  The update applied fine, and my phone does seem a bit more responsive - however it throws an error regarding my carrier settings update failing each time I connect the iPhone to my computer.

See below:

Not sure what the update is or why it failed… however it seems that others are having the same problem.  I’ll be trawling the web - if anyone finds a solution or reason for the problem, post a comment!

Update: This has now appeared on ars technica and on the Apple Support Forums as well.  We are all still waiting for a fix from apple!

Further Update: This problem seems to have resolved itself (please comment if its still effecting you).  I am no longer receiving this error - however this may just be my location - I’m on Telstra 3G in Australia.

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 services you want to monitor.  Monit with then dutifully monitor the service, and email you if they go down.  You can even configure it to restart the service if it fails.

Running on top of monit is m/monit, which is a web based service which pools information from all your servers running monit and provides information in a easily accessable format on a web page.  You can use this as your monitoring station for your website for instance, as it also includes information such as load average, disk usage and uptime - in addition to the services you are monitoring.

Highly recommended.

How-To: Create a mysql friendly date with php

This is really simple - and quite useful if you are trying to insert a date into mysql and you can’t use the “now()” mysql command (due to say a timezone difference):

$date = date("Y-m-d G:i:s");

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 your maintenance period is over, remove the commands above (or comment them out with a # character) and you are back up and running.

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 a high-resolution version of your video:

&ap=%2526fmt%3D18

Adding the above line to the end of the two references to your video’s URL will embed the high resolution version of the video. For example:

<object width="425" height="344">
    <param name="movie"
    value="http://www.youtube.com/v/bQsV7MxQSWQ&hl=en&fs=1
    &ap=%2526fmt%3D18">
    </param>
    <param name="allowFullScreen" value="true"></param>
    <embed src="http://www.youtube.com/v/bQsV7MxQSWQ&hl=en&fs=1
    &ap=%2526fmt%3D18"
    type="application/x-shockwave-flash" allowfullscreen="true"
    width="425" height="344">
    </embed>
</object>

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 found two ways to do this:

Either of these methods allow you to access SVN 1.5.0 repositories.
 

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 also the trim() function which does the same at the start of the line. You can view the manual reference here.

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 receive a response like this:

; <<>> DiG 9.4.1-P1 <<>> -x 67.192.127.21
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17269
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;21.127.192.67.in-addr.arpa.	IN	PTR

;; ANSWER SECTION:
21.127.192.67.in-addr.arpa. 3600 IN	PTR	myserver.mydomain.com.

;; Query time: 217 msec
;; SERVER: 203.50.2.71#53(203.50.2.71)
;; WHEN: Thu Jul 10 11:09:58 2008
;; MSG SIZE  rcvd: 79

If you don’t have one setup, you won’t get a response in the ANSWER SECTION - so contact your host and ask them to set one up for you. It can help save a lot of headaches when you get bounce-back messages such as:

Could not deliver the message in the time limit specified.  Please
retry or contact your administrator.

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 significantly reduce the time it takes for your users to download the libraries.

However in addition to this, you can now use Google’s servers to provide users with a central location for the libraries which allows them be downloaded and SHARED between your applications (or other’s applications). This is a huge advantage as it allows everyone to share the same downloaded libraries from a single location hosted for free by Google, and means your users have a drastically reduced load time as they are all pre-shrunk.

How do you use these libraries? You use the Google google script api like this:

<script src="http://www.google.com/jsapi"></script>
<script>google.load("prototype", "1.6.0.2");</script>

The above command will load the prototype library version 1.6.0.2 in pre-shrunk form.  Further information is available from Google’s API site.

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 problem!

Optus announces iPhone 3G Pricing Plans

Optus has just announced iPhone plans including pre-paid and post-paid plans for those who registered on their iPhone site.

To summarise these:

  • $79 a month gets you an iPhone for free
  • Include 800MB of data per month.
  • Unlimited data usage in the first month applies.
  • Prepaid the phone costs $729 for 8GB and $849 for 16GB phone

These are pretty good, however Optus’ coverage doesn’t better that of Telstra’s Next-G network.  More details are available at the Optus iPhone site.

3 Australia launch iPhone petition!

The 3 mobile network is trying to convince apple to let 3 sell the 3G iPhone in Australia.  They have launched a new website, three.com.au/iphone, which is now live and allows you to register your interest in the iPhone on 3.

If you’re a 3 customer (like me) then head there and register your interest and get help get Apple on side!

You can access their blog directly here.

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.