Posts

Showing posts from April, 2011

Efficient Age From Date of Birth Calculation - PHP edition

Well thought I would have a look at the same set of methods in PHP as I did in MS SQL.  The order of efficiency did change somewhat, which was certainly interesting to me.  Below is my simple code. $timeformatted = date("Y-m-d",strtotime('20th March 1954')); //Start test 1 $time_start = microtime(true); $datetime1 = new DateTime($timeformatted); $datetime2 = new DateTime("now"); $interval = date_diff($datetime1, $datetime2); echo " Test1 ".$interval->y ; $time_end = microtime(true); $time = ($time_end - $time_start)*100; echo " $time ms "; //start test2 $time_start2 = microtime(true); $japDate1 = str_replace("-","",$timeformatted); $japDate2 = date("Ymd",time()); $answer = floor(($japDate2 - $japDate1)/10000); echo " Test2  $answer "; $time_end2 = microtime(true); $time2 = ($time_end2 - $time_start2)*100; echo " $time2 ms "; //start test 3 $time_start

How to make CSS3 Windows 7 buttons

Just playing around with the lovely CSS3 controls and decided to see if I could generally replicate the Window 7 style buttons without images.  Well I have pretty much achieved the same effect using the CSS below. input[type="button"]  {   cursor:pointer;    border: 1px solid #707070;   background-color: #F0F0F0;   border-radius: 4px;   -moz-border-radius: 4px;   -webkit-border-radius: 4px;   box-shadow: inset 0 1px 2px #fff, inset 0 -0.7em #DDD;   -o-box-shadow: inset 0 1px 2px #fff, inset 0 -0.7em #DDD;   -webkit-box-shadow: inset 0 1px 2px #fff, inset 0 -0.7em #DDD;   -moz-box-shadow: inset 0 1px 2px #fff, inset 0 -0.7em #DDD;   padding: 3px 6px; } input[type="button"]:hover  {   cursor:pointer;   background-color: #EAF6FD;   border: 1px solid #3C7FB1;   box-shadow: inset 0 1px 2px #fff, inset 0 -0.7em #BEE6FD, 0 0 3px #A7D9F5;   -o-box-shadow: inset 0 1px 2px #fff, inset 0 -0.7em #BEE6FD, 0 0 3px #A7D9F5;   -webkit-box-shadow: inset 0 1px 2

If you have nothing to do make work for yourself...

Developer1:  OK so we need to store lots of data, what should we use? Developer2: How about an SQL database? Project manager: Nah, that seems far too easy, lets use a hashed file system with no data typing and write all the engine transaction code ourselves. Developer1:  Well we need the application to be client server based? Developer2:  Shall we use an MVC model and a "dumb" database? Project manager:  Nah, that's just one of those established paradigms that all the boring people use.  How about we put all of the business logic in stored procedures and all of the database validation in the client, yep sounds good. Developer1:  We need this to communicate over long distances? Developer2:  How about we use a web browser and HTTPS? Project manager:  What use established protocols, are you mad, we should create our own communications mechanism. Developer1:  Which language should we work in? Developer2:  Well I guess a modern language would be good to take adv

Efficient Age From Date of Birth Calculation

I have been playing around with MS SQL and I was wondering what would be the most efficient method to gather a users age. Calculations involving dates should always be considered from their most tricky state, if you consider that you might need to take into account UTC time, leap years, time zones it all starts to add up to complexity that you can too easily trip up over.  So my first thought when someone asks me to calculate the age from a DOB field is to "cheat" and use the built in languages tools. Most languages have some form of datediff function that can be used to calculate the time between two dates.  However is this going to be the most efficient method? I thought I would test a couple of methods on MS SQL to see the performance changes.  All tests were performed on a low spec laptop on MS SQL Express on a set of 100 random date of births First method SELECT floor(datediff(day,[dob],current_timestamp) / 365.25) Well this is nice and succinct but does suff

Is the Moodle project dead?

While you may have heard the design mantra "Content is King", perhaps you might not be familiar with the development mantra that "Documentation is King". In June 2010 I developed a Block for Moodle to connect Moodle to another piece of software.  This block was developed for version 1.9, using the documentation based on the instructions provided in http://docs.moodle.org/en/Development:Blocks.  Although the instructions were sparse I managed to create a working Block. A few months later I tested it against the latest release version 1.9.8.  It was all still working.  Shortly after this a customer asked if it worked on version 2.0.  Unfortunately when I tested in version 2 my module did not show up. Assuming that they had not changed too much I started looking through the documentation.  I was stuck for a little while with the version.php section as I initially assumed I should be entering $this->version = 2004111200; This through me for a while because this

E-Commerce UI

Really enjoyed this Smashing magazine article on E-Commerce user interface design .  Of course it is not omnipitient and does not go into all of the reason why users abandon the checkout process. I know from my own experience I have abandoned a checkout because it was not HTTPS.  Some websites only become HTTPS very late on in the process.  As soon as you start sending shopping information you should be on HTTPS pages to emphasise security.  Security experts will be happier and non-experts who have been told about the Green URL bar will also feel a bit better. Additionally I have been unsure about making a purchase I have proceeded through the checkout process only to decide that I dont really want the item.  Now it could be argued that the persuasiveness of the website was insufficient at the checkout stage, but I feel it was not an easy of use issue and it would be difficult for the UI to have lead to conversion at that stage. Of course 60%+ does seem like a high loss level an