Chris Tate-Davies

An archive of helpful tit bits of information for development, and probably some stuff that is incomplete, wrong or boring…

Linux – Viewing Processes and Process Threads

Posted on | November 1, 2010 | No Comments

If you need to know about viewing processes on Linux, then there is an excellent page here:

http://www.cyberciti.biz/faq/show-all-running-processes-in-linux/

I shan’t steal all the information as its very nicely laid out already.

Using custom sounds for iPhone SMS notification

Posted on | October 22, 2010 | 1 Comment

I quickly go bored of the default iPhone SMS sounds. But its relatively easy to switch them to your own.

I used the following apps to do this.

  • www.zedge.net – for downloading a suitable replacement sound.
  • iFile – for navigating through the iPhone file system. You can also use iPhoneExplorer too if you’re on Windows.

First of all, find the new sound file you require. This has to be of AAC format, which is an MPEG4 standard audio file. This is the default format for iPhones. The extension will generally be .m4a, or .mp4. Bear this in mind if you are creating your own sound file from an existing MP3. You can import an MP3 into iTunes and have it convert it to AAC, or if you use Zedge (and tell it your using an iPhone) it will download in AAC format automatically.

Then, using the file browser of your choice, navigate through the iPhone’s folder structure to

/System/Library/Audio/UISounds

In here are the default sound files for the iPhone. The new SMS sounds are named as follows:

sms-received<x>.caf

where <x> is a number from 1 to 6. They are not named “Chime” or something easy to play with.

  1. Tri-Tone
  2. Chime
  3. Glass
  4. Horn
  5. Bell
  6. Electronic

So, decide which of the 6 you are going to replace. And rename the file to backup-sms-received<x>.caf.

Copy your new file into this folder, and rename it to the original file that you have just renamed to backup.

In your sound settings now, you’ll need to choose the file from the above list – and remember which one you chose to replace, as the names will be the same as they were before. I know its not the easiest thing to do, but its Apple’s fault I’m afraid. So, on my phone, I have Tri-Tone selected, but it has been replaced with Super Mario.

Easy.

Setting up postfix on Ubuntu for mailing from PHP

Posted on | October 5, 2010 | No Comments

To allow your Ubuntu server to send emails from PHP, then you need to install postfix. Postfix is a mailer for *nix platforms.

So, to install it:

sudo apt-get install postfix

When this is installing, you’ll need to enter some options, like what sort of server you’re connecting to. I use my companies details in here, and this means I need to enter the domain into the origins so that we don’t get refused mail.

sudo nano /etc/postfix/main.cf

Un-comment the line that states myorigin = /etc/mailname

Also, I have to enter the ip address of my mail server in the relayhost section.

CTRL X and save the file.

Now, we need to create the file /etc/mailname

sudo nano /etc/mailname

In this empty file, enter the domain name for your mailserver.

christatedavies.co.uk

CTRL X and save the file.

Now, just restart postfix:

sudo /etc/init.d/postfix restart

Job’s a goodun.

Sorting a SELECT with JQuery

Posted on | October 4, 2010 | 2 Comments

Just a simple function to sort an already populated list. Obviously it would be easier to sort before populating, but there are the odd occasion where this is more complicated than you thought.

Requirements : JQuery

var selectOptions = $("#selectId option");

Then, we just run the sort command on the options array – and this easily sorts the items.

selectOptions.sort(function(a, b) {
    if (a.text > b.text) {
        return 1;
    }
    else if (a.text < b.text) {
        return -1;
    }
    else {
        return 0
    }
});

Then, at the end empty the select object and re-append the sorted options array

$("#selectId").empty().append(selectOptions);

Zend_Date – difference between 2 dates

Posted on | October 1, 2010 | No Comments

I keep having trouble with this simple calculation! So, here is a little example to get the amount of days between now and the next occurance of July 1st.

//set up the 2 date objects
$now = new Zend_Date();
$next = new Zend_Date();
//we want July 1st
$next->setDay(1)->setMonth(7);
//if we are currently after july this year
if ($now->get(Zend_Date::MONTH) >= 7) {
//we need to work it out til next July
$next->setYear($now->get(Zend_Date::YEAR) + 1);
}
else {
//this july is fine
$next->setYear($now->get(Zend_Date::YEAR));
}
$diff = $next->sub($now)->toValue();
return $diff / 60 / 60 / 24;

Piwik – open source alternative to Google Analytics

Posted on | September 27, 2010 | No Comments

I used to use Google Analytics for my visitor tracking and reporting. I find that sometimes I get a bit of slow down when the browser is accessing the google.com site. So I decided to try and find an alternative. I stumbled across Piwik.

It is an application that I can install on my own server, cutting out the reliance on google’s servers. This allows me to change whatever I want, so if I need to report on something else, I can – without waiting for Google to decide if its necessary or not.

Also, in Google’s small print on their T&C – it states that they may start charging at any point in time. I don’t like relying on something that might “change at any time”. – I have Piwik and its running, and will never change (unless I change it. I have control).

In short, its on my server, and its my install, my data. Its mine. Google don’t hold my data and me hostage.

The user side of it, is very simple and intuitive. Its silly easy to set up a new site to log/monitor.

You can get Piwik from here if you feel like having a look. I highly recommend it.

ThreadSMS – Review

Posted on | July 28, 2010 | No Comments

My Nokia doesn’t have threaded SMS view – and its very annoying. So, after searching about for a suitable application for this, I came across ThreadSMS by eHandySoft (http://ehandysoft.com/threadsms.htm)

Functionality:

Quick to load, and quick to navigate. On my N97 mini the scrolling was very smooth and precise. The threads are loaded with contact pictures next to the corresponding people (if you have contact pictures assigned). Clicking on a thread will open it up in a sort of bubble outline. Here you can read the flow of the thread easily.

If you want to reply, you have to click on a message, and then a text entry box appears. It would seem better to me to have the box always there, or at least an option to choose.

There’s even a method of locking your SMS so that prying eyes cannot view them (if you’re upto no good)

If you regularly receive spam SMS messages, then you can filter these out, and silence them. Another great idea.

Looks:

I looks very slick. There are around 7 bubble themes you can choose, that changes the design of the thread view.

The different threads are grouped by sender, so in the main window you get a list of your contacts with their little pictures, ordered by the most recent first. Logically.

Overall:

A good bit of software that expands the Nokia’s limited SMS functionality.

Reading the MySQL binary log

Posted on | July 27, 2010 | No Comments

Having MySQL dumping out binary logs is a very good failsafe for backup redundancy. But, how do you get any of the information out of them?

If you know a time span that you need to investigate, then you can easily use the mysqlbinlog utility:

mysqlbinlog --start-datetime="2010-07-27 14:30:00" --stop-datetime="2010-07-27 15:00:00" > backup.txt

This will export all the recorded SQL Statements performed between 2:30pm and 3pm on the 27th July 2010 to the text file “backup.txt”. I can then browse at my convenience.

If you need to re-create any of the statements, you can copy and paste into your MySQL client of choice.

Accessing the Zend_Application from a page

Posted on | July 27, 2010 | 1 Comment

If, like me, you need to access some Zend_Application resources (such as multidb resources) – then you need a reference to the Zend_Application and the bootstrap. I use this:

if (null == $this->_application)
{
    $this->_application = Zend_Controller_Front::getInstance()
         ->getParam('bootstrap');
}

Retrieve email using regex

Posted on | June 23, 2010 | No Comments

ThisĀ horrendousĀ regular expression will parse a string and return a valid email address from it.

$email = "<'Freddy'> fred@live.com";
preg_match('/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/', $email, $match);
echo $match[0];

This will return:

fred@live.com

Basically, if you pass an array as the third parameter of the preg_match method, it will be filled with the preg_match results, and the first item of the array will be the matching string. If you use capturing groups, these will also be filled. Read more about preg_match at the PHP site here.

I am told that this expression will match 99.9% of valid email addresses in the wild.

« go backkeep looking »
  • Chris Tate-Davies

    Hello there. This is my little "repository" on the world wide web. Its for nothing more than documenting things that I might need again in the future. You could describe it as an extension to my memory.

    Also an online collaboration of my thoughts through the day. I'll try to keep the real random stuff out and keep the blog on course.

    Thanks for stopping by... Hope you find what you're looking for...

  • Tags