While playing with my /etc/hosts file for testing a new server setup I needed to flush my DNS cache. As ever, terminal came to my aid.
dscacheutil -flushcache
Now all is well in the world of DNS.
The last couple of days I’ve been thinking about setting up a local copy of my websites on my laptop so that I can develop them before I make them live.
Last night I enabled PHP on the apache server built into Mac OSX on my new laptop and installed MySQL on it. I also set up some bash aliases to rsync commands so that I could synchronise the websites from the server to the laptop and back again.
Now that I had local copies of the sites that are synchronised it was time to turn my attention to synchronising the databases between the server and my local machine. I could of configured the server’s MySQL installation to allow remote connections, however, I did not want to do this for security reasons. I decided that I would connect to the MySQL server over SSH by forwarding a port on my local machine to a remote port on the server.
First I needed to create an SSH tunnel using the following command
ssh -fNg -L 3307:127.0.0.1:3306 server.host.name Read the rest of this entry »
If you have never set a root password for MySQL, the server does not require a password at all for connecting as root.
To setup root password for first time, use mysqladmin command at shell prompt as follows:
$ mysqladmin -u root password NEWPASSWORD
However, if you want to change (or update) a root password, then you need to use following command
$ mysqladmin -u root -p’oldpassword’ password newpass
To Test POP3
telnet xxx.xxx.xxx.xxx 110 (xxx = mailserver)
+OK Hello there.
user USERNAME
+OK Password required.
pass PASSWORD
+OK logged in.
stat
+OK (Information about your mail)
quit
+OK Bye-bye.
I’ve recently registered for accesss to the NHS’s dictionary of medicines and devices (dm+d). This was primarily to see what format the data was stored in and then to see if there was a way of utilising it in a cool webapp.
I downloaded the current release (its updated weekly) and unpacked the 5MB archive to reveal some XML and related files. Some of the files are huge (up to 32MB each and ~70MB in total) and there was no way a traditional program was going to mannage. I tried a few in fact and they all devastated my 2GB RAM and were generally unusable.
Time for a command line solution… VIM the open source text editor. Its extremely powerful and customisable but using it takes a little getting used to. VIM was able to open with only a slight delay and navigate these huge files. The next problem for me was being able to read them.
In theory it shouldn’t matter what indenting there is in an XML file as it doesn’t contain any data but I find its a lot easier to read the files if they’re ‘cleanly’ indented. I began wondering how I was going to solve the problem and thought of a few ideas… a script (PERL, PHP, shell, other…) but none of those came to fruition. After some searching I came across libxml.
You can download and compile from source if you wish but I decided to download a pre-built version from explain.com it was pretty good and another page I came across on entropy.ch explained how to use it within Vim to indent my files super quick.
Here’s what you do…
- To format type this sequence
- :%!xmllint –format -
- Or mark the area visually and then type
- !xmllint –format -
I’ve been doing some work involving an application that needs to query databases on separate servers however one of the servers will only accept mysql connections locally so the way round it is to forward connections from a port on one system to a port on a remote system. That way the connection to the remote database will appear as though it originated locally and be accepted.
To set up a tunneled connection you issue the following command on any client:
ssh -fNg -L 3307:127.0.0.1:3306 myuser@remotehost.com
The first command tells ssh to log in to remotehost.com as myuser, go into the background (-f) and not execute any remote command (-N), and set up port-forwarding (-L localport:localhost:remoteport ). In this case, we forward port 3307 on localhost to port 3306 on remotehost.com.
I’ve set up SMS Server Tools on my Mac Mini so that I can send text messages from my PC and I thought someone might be able to use the Applescript I’ve created or even suggest a better way of doing things.
If you’re not familiar with SMS Server Tools it’s a really great utility for sending text messages from your PC (I use the term generically) it works on (almost?) all UNIXs and Windows too. It works by having folders which it monitors for text message files and then sending them via the phone. It was very easy to set up just download the source, make, make install, edit the config file and away you go.
A while ago I had an old Nokia N-95 plugged into a Gentoo box and I was using SMS Server Tools to send myself text message alerts. I got rid of that sim and so stopped using it. The phone has been sat in a drawer since then along with a couple of others.
I recently decided I wanted to set it all up again, this time on my Mac Mini. I was trying out different phones and settings but I couldn’t get the N95 or an old Motorola V series phone to do anything even after plugging them both in! Read the rest of this entry »
Last night I was working on determining how long a user had been logged into a PHP application but was having a problem with subtracting timestamps and this is how I solved it.
I was storing two timestamps (as a UNIX timestamp) in the database. One designating the date-time the user logged into the application and the other the date-time of the last activity the user performed. Because I was using UNIX timestamps, which are just the number of seconds sine the UNIX epoch, I subtracted one from the other and used that difference as the input to the PHP function date().
I couldn’t for the life of me work out why the date function was saying that I was logged in for an hour longer than I should have been and it was driving me crazy. It turns out that the reason was that my timezone locale setting in PHP is ‘Europe/London’ and that this causes the date function to adjust for British Summer Time (GMT + 1) thus when I used my timestamp difference in the date() function it translated the difference into a readable format but also added an extra hour.
The solution is to use gmdate() which is identical to the date() function except that the time returned is in Grenwich Mean Time format.

Recent Comments