1GB Slice's are go!

Posted by John
on Friday, 28 December 2007

Christopher Walken

Decided to push the envelope a bit more and give my experimental web apps a little bit more power under the hood, 512mb can be a strain.

So today we're running under a 1GB Slice from SliceHost + nightly backups.

Big difference.

P.S.

This is for my mum, she like Mr Walken. cool cat.

Convert InnoDB > MyISAM and Back Again...

Posted by John
on Friday, 28 December 2007

Convert Typo InnoDB > MyISAM

Simple script to convert your Typo database tables from InnoDB to MyISAM format.

use mytypo_production;
ALTER TABLE articles_tags ENGINE = MyISAM;
ALTER TABLE blacklist_patterns ENGINE = MyISAM;
ALTER TABLE blogs ENGINE = MyISAM;
ALTER TABLE categories ENGINE = MyISAM;
ALTER TABLE categorizations ENGINE = MyISAM;
ALTER TABLE contents ENGINE = MyISAM;
ALTER TABLE feedback ENGINE = MyISAM;
ALTER TABLE notifications ENGINE = MyISAM;
ALTER TABLE page_caches ENGINE = MyISAM;
ALTER TABLE pings ENGINE = MyISAM;
ALTER TABLE redirects ENGINE = MyISAM;
ALTER TABLE resources ENGINE = MyISAM;
ALTER TABLE schema_info ENGINE = MyISAM;
ALTER TABLE sessions ENGINE = MyISAM;
ALTER TABLE sidebars ENGINE = MyISAM;
ALTER TABLE sitealizer ENGINE = MyISAM;
ALTER TABLE tags ENGINE = MyISAM;
ALTER TABLE text_filters ENGINE = MyISAM;
ALTER TABLE triggers ENGINE = MyISAM;
ALTER TABLE users ENGINE = MyISAM;

Now What?

Change mytypo_production to your Typo database's name.

Save it as convert.sql

Run it via,

mysql -u root
source convert.sql

You will get a load of check messages and hopefully no errors or warnings. If all goes ok you should now be over to MyISAM.

Convert Typo MyISAM > InnoDB

use mytypo_production;
ALTER TABLE articles_tags ENGINE = INNODB;
ALTER TABLE blacklist_patterns ENGINE = INNODB;
ALTER TABLE blogs ENGINE = INNODB;
ALTER TABLE categories ENGINE = INNODB;
ALTER TABLE categorizations ENGINE = INNODB;
ALTER TABLE contents ENGINE = INNODB;
ALTER TABLE feedback ENGINE = INNODB;
ALTER TABLE notifications ENGINE = INNODB;
ALTER TABLE page_caches ENGINE = INNODB;
ALTER TABLE pings ENGINE = INNODB;
ALTER TABLE redirects ENGINE = INNODB;
ALTER TABLE resources ENGINE = INNODB;
ALTER TABLE schema_info ENGINE = INNODB;
ALTER TABLE sessions ENGINE = INNODB;
ALTER TABLE sidebars ENGINE = INNODB;
ALTER TABLE sitealizer ENGINE = INNODB;
ALTER TABLE tags ENGINE = INNODB;
ALTER TABLE text_filters ENGINE = INNODB;
ALTER TABLE triggers ENGINE = INNODB;
ALTER TABLE users ENGINE = INNODB;

Also...

Also make sure you Tune your MySQL Install...

And optimize the Tables,

Optimize Typo Tables

Posted by John
on Thursday, 27 December 2007

Quick article on Optimizing your Typo MySQL database, does take a bit and only works on MyISAM and BDB Tables.

mysql -u root
use mytypo_db;
show tables;

Now the beef;

optimize table articles_tags, blacklist_patterns, blogs, categories, categorizations, contents, feedback, notifications, page_caches, pings, redirects, resources, schema_info, sessions, sidebars, sitealizer, tags, text_filters, triggers, users;

Does take a while but should clean up your Typo 4.1.1 Database Tables.

Why So Serious ?

Posted by John
on Tuesday, 25 December 2007

JavaScript Dates

Posted by John
on Tuesday, 25 December 2007

One sometimes misunderstood element of JavaScript is how it handles dates, so in this article I'm going to try and conquer that little confusion.

P.S. Happy Christmas!!!

Dates in Depth

Returning the Current Date

Simple,

document.write(Date());

Creating a Date Object

First off you'll need to create a Date object, this is accomplished by...

var d = new Date();

This creates a new variable with the type as a date object, named d, with the default value as the current date & time.

Setting it's Value

var d = new Date("11/23/2007");

This will create a new Data object and set it's initial date to November 23rd 2007 (note it uses the American format mm/dd/yyyy).

You can set it's date afterwards with the .setFullYear();

d.setFullYear(1997,11,3);

Using the format YYYY/MM/DD.

Days

To return the day value of a Date object do,

document.write(d.getDate());  
// returns => 23 from 23rd Nov 2006
// (1..31)

document.write(d.getDay());   
// returns day of week value lands on, e.g. 2 for Monday for 23rd
// (0..6)

Yes this can be confusing, getDay() does not return what you expect (e.g. 23 from 11/23/2007), but the numeric value for the day of the week the 23rd lands on, so if the 23rd lands on a Tuesday it'd be 3. Use getDate() to return 23.

Setting the Day

document.write(d.setDate(11));
// sets the day digit to 11

Months

To return the month value of a Date object do,

document.write(d.getMonth());
// returns values from 0..11 (0=Jan 11=Dec)
// (0..11)

Because Month is an array, you'll need to add 1 to it to return days from 1..12,

document.write(d.getMonth()+1);
// returns values from 1..12 (corrected by adding 1 to the value)

Setting the Month,

d.setMonth(mm,dd);

// e.g.
document.write(d.setMonth(11,1));
// set the month to December the 1st

Years

To return the Year value of an Date object do,

document.write(d.getFullYear());
// returns 2007 for 11/23/2007

Note, there was a function called getYear() but this returns a 2-4 digit number and is not recommended to be used; depreciated.

Setting the year,

document.write(d.setFullYear(1992));
// sets the year to 1992

// also can be used like, 
d.setFullYear(yyyy, mm, dd);

Time

To return the Time value of a Date object do,

d.getTime();
// returns the number of seconds from midnight

Adding seconds to a day, e.g. advance 1 day would be...

d.setTime(86400);
// adds 86400 seconds to the current date value
// 86400 seconds = 1 day

Hours, Minutes, Seconds,

This can be done like,

document.write(d.getHours());
// (0..23), returns the hour of the day, 11 = 11 O'clock

document.write(d.getMinutes());
// (0..59), returns the minutes, 23 = 23 minutes past

document.write(d.getSeconds());
// (0..59), returns the seconds, 12 = 12 seconds past

document.write(d.getMilliseconds());
// (0..999), returns the milliseconds past
// 1000 milliseconds in a second

Setting the values,

d.setHours(hour,min,sec,milli);

// so..
document.write(d.setHours(12));
// set to 12 noon

d.setMinutes(min,sec,milli);
document.write(d.setMinutes(2));

d.setSeconds(sec,milli);

d.setMilliseconds(milli);

To String

To return a Date object as a String value,

document.write(d.toString());
// returns Tue Dec 25 2007 12:44:05 GMT+0000 (GMT)

Calculations

Days in Month

This function returns the max days in the chosen month, so 2, 2008 returns => 29.

function daysInMonth(iMonth, iYear)
{
return 32 - new Date(iYear, iMonth, 32).getDate();
}

Thanks goes to Charlie for that...

Comparing Dates

if (Date.parse("11/11/2007") < Date.parse("11/11/2008")) {
document.write("wooah!");
}

NOTE: remember to use a lowercase if* rather than *If otherwise it'll throw up a missing ; error.