Regex – “The” searching
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. [...]
MySQL – Order by certain value first
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 [...]
Javascript Language Translation
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 [...]
MySQL Incorrect String value “x/80″
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 [...]
Help in using Ubuntu Terminal Console
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 [...]
Ubuntu Console commands for SVN
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 [...]
REGEX – Remove Letters from string
Removing letters from a string using Regular Expressions. Very simple. but brain bending – All I wanted to do was remove a prefix from a string. The prefix was always letters, and I only wanted the numerical suffix returned, so though, preg_replace was my best bet. echo preg_replace(“/[a-zA-Z]*/”, ”, ’12345MystrING67890′); This returns : 1234567890 Perfect.
TabIndex in HTML
TabIndex is an attribute to HTML elements that tells the browser which control takes focus next when TAB is pressed. <input id=”one” tabindex=”3″ /> <input id=”two” tabindex=”1″ /> <input id=”three” tabindex=”2″ /> <input id=”four” tabindex=”4″ /> Here, once the page is loaded, the first TAB press will set focus to input two, and then subsequent [...]
Dependency Injections
Dependency Injections When creating PHP classes, particulary when utilising Unit tests, its a good idea to use dependancy injections. This enables us to use a robust reliable class which is not hard coded to rely (depend) on certain factors. If you were to use the Zend_Mail_Service in your class, it would work fine, but we [...]
MySQL REPLACE
I’d not come across REPLACE as a MySQL function before. I’d always used a combination of concatination of LEFTs and RIGHTs and the occasional MID. Unbelievable that I’d not found this function before… SELECT REPLACE(fieldname, “look for”, “replace with”) FROM tablename; So simple…
keep looking »