Password Generator

I wrote a password generator today to help me whenever  I need to create passwords for myself or a user.  It’s pretty easy to use – just enter the password length and character set to use. Enjoy!

http://tools.thewebsiteguy.com.au/password.php

PHP Pluraliser

I wrote a pluraliser in PHP.

final class Pluraliser
{
     private static $alreadyPlural = array("sheep","people","deer","moose","premises","series","fish","chassis","alms","amends","cattle","clothes","doldrums","ides","pants","pliers","scissors","shorts","smithereens","trousers");
     public static function MakePlural($word)
     {
 	$returnWord = "";
 	// If the word is in the list of words that are both singular and plural
 	if (in_array(strtolower($word),self::$alreadyPlural))
 		$returnWord = $word;
 	else
 	{
 		if (substr($word,-3) == "ess")
 			$returnWord = $word . "es";
 		elseif (substr($word,-3) == "sus" || substr($word,-3) == "ews")
 			$returnWord = $word;
 		else
 			$returnWord = $word . "s";
 	}
 	return $returnWord;
     }
}

So a test app of:

echo Pluraliser::MakePlural("Jesus") . "<br />";
echo Pluraliser::MakePlural("Sheep") . "<br />";
echo Pluraliser::MakePlural("Building") . "<br />";
echo Pluraliser::MakePlural("Band") . "<br />";
echo Pluraliser::MakePlural("Guitar") . "<br />";

Produces the correct output:

Jesus
Sheep
Buildings
Bands
Guitars

If requires some tweaking still, such as custom plurals for “men”, “women” and other tricky words, but for the time being they can be added to the if statement.

MySQL limit by variable

I have been writing a special web application framework around the n-tier pattern, and in the database layer I ran into a problem with MySQL.  Within a stored procedure you can order by a variable but not limit by a variable, which puts a small damper on pagination.  There are many threads on the Internet of outraged MySQL users, with several solutions but I didn’t really like them all.

The first solution I saw was to prepare the SQL statement as a string and execute it in the proc, replacing the limit parameters as such:

create procedure myProcedure (myLimitFrom, myLimitNumber, ....)
.....
set $sqlStmt = 'select myFields from tTable limit ?,?';
set @myLimitFrom = myLimitFrom;
set @myLimitNumber = myLimitNumber;
prepare STMT from @sqlStmt;
execute STMT using @myLimitFrom, @myLimitNumber;
drop prepare STMT;
....

The biggest problem with that one (besides how messy it is to look at) is that it is very inefficient.  The SQL will have to compile on-the-fly within the proc each run.

Another solution I saw was to assign a rowcount variable that increments each row and have a where clause that is in the rows needed.

set @n=0;
select myFields from tTable where (@n:=@n+1) between a and b;

That is nasty as well since it is allocating and working with a variable for each row in the table.  Over thousands of records with multiple database transactions it could become expensive.
Yet another solution was to select where the ID’s are between a range, but if a field is physically deleted, then it would skip a row.

The best I can come up with is to create a temporary table and insert the ID’s into it with an auto_number column, then select out again in the range of the auto_number column joined to the table (Thanks for the hint, Paul G).


create procedure sptCitySelect(... myLimitFrom bigint unsigned, myLimitNumber bigint unsigned ...)
begin
...
 	create temporary table tmpIDResult (RowNumber bigint unsigned not null auto_increment, TableID bigint unsigned not null, index (RowNumber), primary key (TableID)) ;
        insert into tmpIDResult (TableID)
 	select CityID
 	from tCity
 	where ...
 	order by ...        

        select t.CityID, t.City, t.StateID, t.Deleted
 	from tmpIDResult r
 		join tCity t on t.CityID = r.TableID
 	where r.TableID between myLimitFrom and (myLimitFrom + (myLimitNumber - 1))
 	order by RowNumber;
...
 end $$

Horror story in osCommerce: customer details showing in other customers address book

I spoke to a friend recently who had a nightmare story in osCommerce, where when a new customer signs up, another customers details appeared in their address book.  What had happened was the store was copied from another live store, and had the database erased, however entries in the address book table were left.  As new customers signed up, the auto number incremented the customer id and matched up to old entries in the address book table.

This example highlights several problems, of which to be aware.

First of all it shows the importance of not copying stores, but installing them from scratch. It’s not worth the risk of missing any data.

Secondly, there is a very large danger of this sort of thing happening with any non-relational database.   MySQL has the option of using the InnoDB database engine, which supports foreign key constraints, but nearly all open source projects use the MyISAM database engine.  If osCommerce was built using InnoDB with foreign keys, the delete command would have failed for the customers table citing foreign key dependancy to the address book table.

Lastly, it is poor design in MySQL to reuse any auto_increment number in a table.

Why do people continue to use MyISAM? MyISAM allows foreign key statements, and rather than giving an error, ignores them.  Many people may think their database enforces foreign keys, when the truth is they have a ticking time bomb.

National Broadband Woes

Nick Minchin – Look, up in the sky! There’s an ugly downside to Labor’s broadband project 

http://www.brisbanetimes.com.au/technology/technology-news/look-up-in-the-sky-theres-an-ugly-downside-to-labors-broadband-project-20090705-d93w.html

Senator Nick Minchin, Opposition Minister for communications and the digital economy, writes a report for the SMH  R.E. the national broadband plan and some already apparent problems.

Despite planning to spend $43 billion on its half-baked “Ruddnet” plan, federal Labor is looking at ways to minimise time and to cut costs.

Optus estimates that if 100 per cent of the network’s cables are deployed underground, as I am sure most taxpayers will quite reasonably expect, the network would cost $60 billion.

The number one problem that will be experienced with any sort of Government project, is that rather than being pushed from a commercial demand, it is pushed from a political demand.

When a regular item has a commercial demand, the consumer pushes the manufacturer for more of a product, or a better model.  This demand allowed two things: cheaper prices and better quality.  Both are brought around since it is financially viable for the company to provide the product or service, and the demand can be met by another party should either of the previously mentioned not be delivered.

Ignoring the effects that a certain company starting with “T” had on hindering the industry, the main reason a high speed broadband network hasn’t been built already is that there is no viable commercial demand.  People aren’t buying our current speed of broadband at a high enough rate to warrant building a faster one.  This means that any government attempt to built a politically driven network (what a vote winner – fast Internet for all!) will be met with high build time and cost due to low existing infrastructure and low consumer demand due to the high cost of subscription.  The latter is being partially offset by funding from tax dollars and bonds, but the buyers of any bond will want a good return.  Should there be a low return, the money will be need to be recouped from tax dollars when the bonds expire.

Who’s looking forward to a low cost, ontime, underground, lightning fast, broadband network?  Judging by the already massive change in project plan and cost woes, I don’t think it will be happening.

Serious IE 8 exploit

A serious Internet Explorer 8 exploit has been revealed without a patch yet, described in this article: http://www.microsoft.com/technet/security/advisory/972890.mspx.  Anyone who use IE should follow the steps in the article, or better yet take it as one more reason that IE has been and will continue to be the worst choice in web browser.

Google Wave

I haven’t blogged for so long, I’ve been slacker than Scott!

To break the drought, I should blog about something worthwhile: Google Wave.

http://wave.google.com/

I applied for it today and wrote them a heiku.

Google wave sounds good
Maybe I can try it out
I would be thankful!

IT and the greater depression

The hard economic times that we are coming into, that may be called “The Greater Depression” by some, will affect many industries, but I thought I would comment on my thoughts regarding IT in such an environment.

Already the steel industry world wide has cut production by 1/3, and a secondary / tertiary industry such as IT will feel the brunt of global slow downs more.  We can only service that which there is business for!

I would see that some of the following could take place:

  • Job losses as demand lowers, and borrowing slows
  • Price drops in general services, as jobs fall, and deflation takes place
  • Falling wages because of said deflation
  • More people will produce lower quality, cheap work for desperate money
  • Higher demands on employees

Thankfully with no IT union there should be no strikes or price fixing which will only make matters worse.  The rewards will be with those who can hold down IT work during the next five years, since they will have a much better wages in the following boom for the experience for the good looking resume.

The sectors that will continue work are most likely to be:

  • Government work, since it will be least likely to cut with socialists in federally and in the states
  • High quality work that is in demand and has the least skills in, such as rapid deployment and specialist such as medical / mining, and true n-tier, OO programming
  • Low quality, cheap work

Finding quality IT providers may become more difficult.  The things to look out for will be years in the industry, and good testimonials from happy customers.  Good businesses may go under as they are undercut, making it harder again.

Keeping a job in IT will be very hard.  Jobs will drop with no industry to support, so several things will be needed.  For the cheap work, it will be like the last depression, where the first in will get the job, so promptness will be the key.  For higher skilled work, experience, quality references and then qualifications will be what scores the work.

    Website Buyers Guide

    There are many caveats and pitfalls with websites that people need to be aware of.  Having been in IT for over eight years, here are a five main things to watch out for that I have found.

    Used Terms 

    Domain: is the name for the site you type into the address bar, such as http://thewebsiteguy.com.au.  These are leased for between one and five years, and the .au domains are regulated so that only elegable people can register one.

    Website:  can refer to the completed product as a whole, or the files for the site that can be hosted on a server.

    Hosting:  the website needs to be put on a server somewhere so that people can access it.  The domain is configured with some hidden information in it to tell your computer which server to talk to, so you can see the site.

    1. Ownership

    This is probably the most important. When you buy a website off a company you would expect that since you bought it, you own it, but think again.  You probably got no written agreement regarding this, and by law a contractor who does any work, automatically owns the IP for it.

    I know of a Queensland company “A” who was recently caught out with this (not a direct business contact).  This certain company purchased a website off web company “B”, and changed over to a new host.  When they did some changes, the old web host “B” threatened legal action for removing the old company’s details and cited that they owned the IP for the site since they made it.  Company “A” promptly got a redesign of the site done, just so they could make certain changes to their own website.

    Always make sure you own the design and can have very clearly what you can and can’t change on it. e.g. You may have an agreement to link to the web company etc.

     2. Technology

    There are many languages and methods of making a website, and even though the end result looks the same, if you ever need to change hosting companies (there are a large variety of reasons this may happen), can you do it?  Open source languages such as PHP, and MySQL can run on any server, but commercial languages such ASP and .Net only run on Windows servers, and hosting tends to be more expensive.

    Further to this, some websites are completely proprietary and will not work outside of their hosting, and if you change, you will need to buy a completely new website.

    3.  Goodwill when moving on

    If you need to change web hosts, will your company help you in the process?  A particular client changed over to hosting with The Website Guy, and their old host refused to transfer the files for the old site, and refused to help point the domain (which they registered and controlled) to the new server.

    It is very important to find out from your web company what happens if for what ever reason you want to change companies.

    4. Site Design

    Do you like the look of other sites the company has made?  You shouldn’t feel afraid to ask for a mock up picture of what the site will look like before they start work, so that you will be happy with how it looks.  Note also that the company may not want to do this without any money changing hands or a work order being signed, since it is a large enough amount of work to do without a guarantee of income.

    Also don’t reject the idea that one company can design the site, and another can host it.  Either of the two, especially the last, should be able to help with setting it up.

    5. On Going Costs 

    This isn’t just the hosting, this is other things that come up too.  If you want work done to your site, what is the hourly rate, and how accessable and friendly is the service?  A normal rate should be around $80-$125 / hr.  Under that you should question their skill, and over is a rip off.  You should be able to contact them by phone and E-mail, and they should be willing to help with these things.

    Slackness in posting!

    I may as well post today so it is not more than a month since the last.  We moved very recently, so that has taken up a large body of time, but I promise that a few cool posts are to come.  I will restart the PHP series and also comment on my thoughts of the financial crisis and the IT industry.