Validate Dollar Amount with PHP

3 comments

It can be hard when conducting interviews for a web developer position to really know a candidates skill level.  Recently a company presented me with the following problem, which I thought stood head and shoulders above the usual multiple choice quizzes and simple logic problems I’ve been presented with.

In the language of your choice, write a function that accepts a string. The string is a dollar amount, which may start with a dollar sign, and may have commas in it. Output should be a number, or false if there are illegal characters in the string.

My first instinct was to look for a PHP built in that would do the above, but surprisingly enough, there was none!  So on to my solutions.

Read the rest of this entry »

July 14th, 2009 at 12:06 pm  

Posted in PHP

ERROR 1146 (42S02): Table ‘mysql.servers’ doesn’t exist

2 comments

I’m not sure what caused this error in the first place, as it cropped on a server I don’t admin..

ERROR 1146 (42S02): Table ‘mysql.servers’ doesn’t exist

This cropped up on Server version: 5.1.36 MySQL Community Server (GPL) by Remi, installed on CentOS whenever I would execute the ‘FLUSH PRIVILEGES’ command.

The solution?  Try this.

USE mysql;
 
CREATE TABLE `servers` (
`Server_name` char(64) NOT NULL,
`Host` char(64) NOT NULL,
`Db` char(64) NOT NULL,
`Username` char(64) NOT NULL,
`Password` char(64) NOT NULL,
`Port` int(4) DEFAULT NULL,
`Socket` char(64) DEFAULT NULL,
`Wrapper` char(64) NOT NULL,
`Owner` char(64) NOT NULL,
PRIMARY KEY (`Server_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='MySQL Foreign Servers table';

Apparently this issue arises sometimes with an incomplete MySQL upgrade.  Beyond just installing new binaries you’ll often need to run scripts/mysql_fix_privilege_tables to ensure the ‘mysql’ database contains all the needed stuff.

July 10th, 2009 at 6:53 pm  

Posted in Databases

Running a Cron Job on Windows

one comment

Working with a Windows based web server recently, I ran into a bit of a puzzle when a software package I was using required a regular PHP script to be run.  On POSIX based operating systems like Linux or BSD, this is something you could easily accomplish by running what is known as a ‘cronjob’.

As Windows has no cron daemon, I had to come up with another solution.

Read the rest of this entry »

June 20th, 2009 at 12:13 pm  

Posted in Discoveries, Webmastering, Windows

My Windows Keymap Keeps Changing Itself!

no comments

For months now I’ve been struggling with an issue, where at seemingly random intervals, my keymap would get all scrambled up. Instead of a question mark, an E with an accent would be typed. Normal single quotes turned into backticks, etc.  Very frustrating.  The problem would persist in an application until I closed and reopened it.  With no idea what was causing it, and such a painful fix, I spent some time Googling and have discovered the cause and solution.

My Windows Vista system had a French Canadian keymap installed.  A keyboard shortcut to toggle keymaps must be getting accidentally pressed.

The Fix

  1. Open up the Control Panel
  2. Select ‘Regional and Language Options’
  3. Select the ‘Keyboards and Languages’ tab
  4. Press the ‘Change Keyboards’ button
  5. Select any keymaps you don’t want.  
  6. Click Apply, problem solved!

Unless you regularly switch languages your system should only have one keymap installed.

In the same area of the Control Panel on the Advanced Key Settings tab I discovered a keyboard shortcut for ‘Left-Alt + Shift’ that was part of my problem.  Altering the keyboard shortcut would fix the issue here as well, although deleting the extra keymaps was my preferred solution.

May 18th, 2009 at 4:58 pm  

Posted in Discoveries, Windows

Fixing Scrambled Curl Output.

no comments

I ran across a website tonight that would give me scrambled output when I pulled it down with cURL.  Where I was expecting to see html content, I was instead getting what looked like a binary file.  (Try running ‘cat’ on a jpg and you’ll see what I mean).

What exactly was happening, and how did I fix it? 

Read the rest of this entry »

May 12th, 2009 at 10:04 pm  

Posted in Coding, PHP