Chris Tate-Davies

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

Cisco VPN client on Windows 7 64bit

Posted on | April 8, 2010 | 1 Comment

If you’re trying to get Cisco VPN client installed on Windows 7 – 64bit then you may as well give up. I’ve tried just about every method discussed on the internet.

However, http://www.shrew.net/download have a VPN client that will allow you to import your PCF file and it works!

Export Thunderbird contacts to Outlook

Posted on | April 8, 2010 | No Comments

I wanted to export my Thunderbird Contacts to Microsoft Outlook 2010 beta.

Jesus, if that wasn’t the most stressful export ever! Thunderbird can only export as CSV or tab separated – or LDAP.

Outlook says it can import from CSV and Tab separated, however it just crashes with mapping errors.

I tried dragging them from TB and then dragging into Contacts on Outlook, but that just resulted in a new empty contact, with an attachment of the email address in a text file. Helpful.

Anyway, I found this Thunderbird Addon that will export to vCard (The standard Address Card I feel) and then I could drag these into Outlook.

http://nic-nac-project.de/~kaosmos/morecols-en.html

However, Outlook feels the need to open each vCard as a new Contact screen, so you then have the joys of closing as many screens as you have contacts just imported. So it could be hundred and hundreds!

I do wonder if the designers of these software packages ever have to use this functionality. Perhaps they should.

Programmers Excuses

Posted on | April 8, 2010 | 1 Comment

Programmers Excuses

Programmers Excuses

Installing Tahoma font in Ubuntu

Posted on | April 6, 2010 | No Comments

The stylesheet of our intranet is primarily Tahoma, and Firefox on Ubuntu doesn’t look good.

To install the Microsoft Core Fonts package in Ubuntu, run the following in your terminal:

sudo apt-get install msttcorefonts

And then this should go away and get them. Lovely.

NB, if this doesn’t take immediate effect, you can rebuild the font cache by running

sudo fc-cache -fv

Now, the Tahoma font is excluded these days from this package, so you’ll need to install that one manually, by following the instructions found here

Regex – “The” searching

Posted on | March 26, 2010 | 10 Comments

Say you have a list of movie titles, and you want to either sort them, or search through them, and some of them have “The ” at the start, for example:

  • The Simpsons
  • Simpson Street

When doing a MySQL search:

SELECT * FROM movies WHERE title LIKE "The Simp%";

Would only return the first row. But if you are working in a company where there is no standard set, the movie title could be formatted as “Simpsons, The” – and then, it won’t be found.

To solve this, you could replace the “The ” letters with blank, and then sort out the field contents during the query:

$str_query = preg_replace("/(title like "(the )(.*)%")/i",
    "REPLACE(LOWER(title), "the ", "") LIKE ("$3%")",
    $str_query);

This will change :

"(title LIKE "The Simpsons")"

to,

"(title LIKE "Simpsons")"

But, the (the) in line 2 tells PHP to only replace it if starts with “The ” (case insenstive).

However, what if you want to search for “the”  (not sure why you would…)

You need to do a negative lookahead, to tell the expression to only carry on, if the search phrase is not exactly “the”

if (preg_match("/(title like "(?!the)(.*)%")/i", $str_query)) {

The (?!the) is the readahead.

(.*) matches any string but it is greedy and you have to be carfeul that it doesn’t just accept everything to the end of $str_query. (but its okay in our case, as we are looking for % (the LIKE wildcard))

After all this, we can run:

SELECT * FROM movies WHERE $str_query;

But what about sorting? All the titles beginning with “The” will appear in the T section. Whereas really, we want the Simpsons to appear in the S section.

Add an easy ORDER BY clause here:

SELECT * FROM movies WHERE $str_query ORDER BY (REPLACE(title, "the ", "") ASC;

Sorted!

MySQL – Order by certain value first

Posted on | March 23, 2010 | 1 Comment

Ever wanted to sort a resultset of data, by value, but I wanted a couple of exceptions to appear at the top?

SELECT country, population,
CASE country
WHEN 'United Kingdom' THEN 0
WHEN 'United States' THEN 1
WHEN 'New Zealand" THEN 2
ELSE country
END AS countrySort
FROM countryList 
ORDER BY countrySort ASC;

This will sort the results by country, but with UK, US, NZ as the top three.

Javascript Language Translation

Posted on | March 18, 2010 | 2 Comments

On a project I am working on, I need to enable language translation. Thinking about it, turned into something quite complicated. But then I found the Google Language API which allows developers to hook into the Google Languages services.

So, I start a page – enabling UTF-8 character sets:

< meta content="text/html; charset=UTF-8" http-equiv="content-type">

And then hook into the Google API itself:

< script type="text/javascript" src="http://www.google.com/jsapi"></script>

Finally, a function that will pick up the text to translate. This function will automatically attempt to discover the source language for you.

< script type="text/javascript">
google.load("language", "1");

function translateLanguage() {
    var sourceText = document.getElementById("sourceText").value;
    google.language.detect(sourceText, function(lang) {
        if (lang.language != '') {
            document.getElementById('language').innerHTML = 'Source language: ' + lang.language;
            google.language.translate(sourceText, lang.language, 'en', function(result) {
                var translated = document.getElementById("translation");
                if (result.translation) {
                    translated.innerHTML = result.translation;
                }
            });
        }
    });
}
</script>

MySQL Incorrect String value “x/80″

Posted on | March 18, 2010 | No Comments

MySQL Incorrect String value replication error.

We use ANT for releasing versions of our PHP applications. Its very smart and takes a lot of the problems related to releases out of the equation.

However, everytime we performed a release, our replication server would break, and I’d have to skip a load of database delta error messages with this command:

SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1

The error we received is:

Error 'Incorrect string value: 'x9CxF37x12[k...' for
column 'applied_by' at row 1' on query. Default database:
'<databasename>'.
Query: 'INSERT INTO changelog (change_number, delta_set, complete_dt,
applied_by, description)
VALUES (35, 'Main', CURRENT_TIMESTAMP, USER(),
'<database_delta_filename>')'.

I’d been getting these errors for a while.

Basically, the MySQL server was replicating the changelog table down to the slave, but for some reason it just would not accept the replicated query.

After a bit of scrummaging around, and changing field values/character sets, I discovered that in the string was “x80″ which is a padding character as set out in http://en.wikipedia.org/wiki/ISO_8859-1 and shouldn’t be used in a string. I’m not really sure how it got there, or why, but I basically changed the “applied_by” field to be a BLOB – which is generically a VARCHAR with no character set and there fore ignores this.

Help in using Ubuntu Terminal Console

Posted on | March 18, 2010 | No Comments

Help in using Ubuntu Terminal Console


Remote connection

To ssh to another Lunix terminal, use this command:

ssh username@host -p port

The default SSH port is 21, but you could change it to anything, i.e. 9100

Remote teminal will prompt for your password, and job done.


File/Folder functions

cp – Copy file

cp /usr/bin/file /tmp/location

mkdir – Create directory/folder

mkdir /home/chris/newfolder

rm – Delete files in folder

rm -rf /home/chris/foldertoremove

The -rf tells Linux to remove files in the folder. This will remove all files and sub folders though, so be careful. There is no undelete.

mv – Rename a file, or move a file

mv /home/chris/index.htm /home/chris/home.htm
mv /home/chris/index.htm /home/chris/site/index.htm

The first command will rename a file, and the second will move it (effectively renaming it into another directory)

pwd – see what folder you are in

pwd
/home/chris/Desktop

 

Ubuntu Console commands for SVN

Posted on | March 18, 2010 | No Comments

Console commands in Ubuntu for use with subversion

Checkout a branch:

svn checkout url@revision path

To update your local source:

svn up

And to commit a single file:

svn ci -m "message for commit" <files>

Multiple committing is just without the <files>.

To download a revision

svn co -r 1671<remotefolder> <localfolder>
<remotefolder> could be any folder in the svn structure, i.e.
http://www.mydomain.com/svn/project/trunk/folder

Getting a list of revisions for a page (if you’re trying to find when you changed a page)

svn log -g <files>

Merging a branch into another

svn merge http://svn.branch.url localfolder .

That will merge the specified url into the localfolder. Ensure that your local changes in your working copy have been committed before you do this.

« 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