Tuesday, August 11, 2009

Generate and check regular expressions, fast and for free

http://www.gskinner.com/RegExr/desktop/

This application and online system is an excellent way of trialing your regular expressions before going live, and making a right mess!

Its also an excellent way of learning how they work.

Enjoy.

Monday, July 27, 2009

IE7 Vs IE8... Compatibility View

Well it's clear that I'm not a fan of Microsoft products but I do think think that they could do some amazing work if they just changed their approach – I just feel that they re-invent the wheel by forcing us to use square ones, they then slowly shave the corners until we have a round one again, by which time we have forgotten that we had round wheels 3 years previous.

I have just been asked to fix a margin or padding issue that only appears in IE8, however with 'Compatibility View' set to 'On' the issue is resolved. There should be no incompatibilities between their own products unless they are going to follow the increasingly accepted standards. Then why not fix the older browsers using the update service and be done with the incompatibilities.

With IE6's Product Lifecycle about to expire and HTML5 on the horizon I personally felt that the web was about to get even bigger, almost a true start the web 2.0 ethos. But there is always something that isn't cross browser, or needs tweaking which just slows down development.

Would it not be better to gather up all the good bits and best practices, then build browser around one set of rules. The browser war can then just be down to the user experience, available extensions and scope for development.

The world can be better if we worked together!

Wednesday, July 22, 2009

Windows 7 is it just a con?



Great, yet another OS from Microsoft where we are all forced to buy machines that are buggy until we point the bugs out ourself. The OS shouldn't be released until Microsoft have found all the issues and corrected them - effectively waited till service pack 2 before even releasing, I don't buy a washing machine and expect it to be just-about-usable until 1 year and a half later.

I've been looking at the "new features" and one of Windows 7s' key selling points is that when you click the programs icon you can just type the program name and the start menu will display it... great... but this same feature is in Vista, so what is better?

WELL. As you can see, you get some new wallpapers! And if you can't understand computers it will spell everything out for you - despite more and more people from the older and next generations learning how to use computers all the time!

Forward thinking please Microsoft! Lets see if Google can do better...

Moving the magento installation up and down folders...

Moving the installation is very posible...

See http://www.magentocommerce.com/boards/viewthread/13826/P15/ for more information but I found that using the following in the SSH terminal allowed the domain to copied up or down the folder tree on the server

cp -fR /www/vhtdocs/folder1/magento/* /www/vhtdocs/folder1/

This make a copy of everything everything apart from the .htaccess file, in the folder above (use your own logic to flip the folder names to copy into another folder instead of out-from) which takes a few seconds to FTP down then back up, the original post regarding shifting folders doesn't mention that the .htaccess file lists a BASEHREF to the wrong folder after moving so remember to alter that... but all told it went well.

The command is 'cp (copy) -f (overwriting) R (including sub-folders) /www/...(from)/*(everything) /www/...(to)

You can then keep the old installation as a backup if you like.

Monday, July 20, 2009

Putty BASH commands

I found that while trying to install a copy of Magento the files would corrupt and due to the size timeout all the time, so I uploaded the tar.gz file to the server and used the following to extract the files.

Note: Make sure that the tar.gz file is above the level where the store is to be located, i.e. dropping it into the root folder will mean that the store files will be located at /magento until you pull some strings to get the webserver to point at that folder (therefore bringing the store-front to be the root, but I don't even know if this is possible!?) It would be nice if they supplied the tar.gz file with all the files at the top level and not in a "magento" folder but perhaps there is a limitation.

So, log into your SSH program, I use Putty, and get through to the folder that contains the tar.gz file:
cd /www/vhtdocs/folder/folder/

Then you need to decompress the file:
tar -xvzf magento.tar.gz

If it throws a load of errors up try changing the write permissions of the folder you are in with something like:
cd ..
THEN
chmod 777 folder
THEN
cd folder
And try again... in Putty you can just push the up arrow a few times to get the unzip script back.

If it works you can then install Magento by going to your website /magento, but this will be your store URL so change this now if you want something different (unless you installed to ROOT) for this I just used FTP.

There are a few files anf folders that need write permissions so just navigate arround using "cd .." to go up a level and "cd foldername" to go into folders, but remember you chmod the folder from the folder above - don't try and use "cd foldername1" and "chmod foldername1" because you are trying to alter a folder that you are in (imagine painting a box while sitting in it, difficult, but probably possible).

I store these more as notes to myself, but I hope that this helps you achieve things faster.


Sunday, July 19, 2009

Saving last view using the URL anchor

I had a page with 3 links in it, each link changed the className of 3 divs so that 2 were hidden and 1 was visible... the issue was that when a user clicked a link the 'viewstate' was lost. Using a similar methodology as AJAX back button I cobbled together the following code to hide the divs and retreive the state when a user returned to the page using the back buttons.

// HTML Document
<a href="#div1" onclick="reveal('div1');">Button 1</a>
<a href="#div2" onclick="reveal('div2');">Button 2</a>
<a href="#div3" onclick="reveal('div3');">Button 3</a>

<div id="div1">Div 1</div>
<div id="div2">Div 2</div>
<div id="div3">Div 3</div>

<script type="text/javascript">
<!--
reveal('div1');
-->
</script>

// JavaScript Document
function getObject(name){
var ns4 = (document.layers) ? true : false;
var w3c = (document.getElementById) ? true : false;
var ie4 = (document.all) ? true : false;
if (ns4) return eval('document.' + name);
if (w3c) return document.getElementById(name);
if (ie4) return eval('document.all.' + name);
return false;
}

function closeall(){
getObject('div1').className = 'closed';
getObject('div2').className = 'closed';
getObject('div3').className = 'closed';
}

function reveal(which){
closeall();
document.location = '#'+which;
var query = location.href.split('#');
if((query[1].length) > 0){
what = query[1];
}
else {
what = which;
}
getObject(what).className = 'open';
}

Tuesday, May 12, 2009

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<style>

/***** Selector Hacks ******/

/* IE 6 and below */

* html #all { color: red }

/* IE 7 and below */

*:first-child+html #all { color: #F60 } /*ORANGE*/

/* IE 7 and modern browsers */

html>body #all { color: #FC0 } /*YELLOW*/

/* Modern browsers (not IE 7) */

html>/**/body #all { color: #9C0 } /*GREEN*/

/* Opera 9.27 and below */

html:first-child #all { color: #6CC } /*TIFFANY*/

/* Safari */

html[xmlns*=""] body:last-child #all { color: #36F } /*BLUE*/

/*safari 3+, chrome 1+, opera9+, ff 3.5+ */

body:nth-of-type(1) #all { color: #609 } /*PURPLE*/

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */

body:first-of-type #all { color: #600 } /*MAROON*/

/* saf3, chrome1+ */

@media screen and (-webkit-min-device-pixel-ratio:0) {

#all { background: #FFDECE; border: 2px solid #ff0000 } /*??*/

}

/***** Attribute Hacks ******/

/* ie6 and below */

#all { _color: #300 } /*NEARLY BLACK*/

/* ie7 and below */

#all { *color: #666 } /* or #color:#ffffff */ /*GREY*/

/* 'Modern Browsers' includes IE8, whether you agree or not.. :) */

</style>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Test CSS Document</title>

</head>

<body>

<div id="all">This is you browsers color...</div>

</body>

</html>

Monday, March 30, 2009

PHP Alternating row colours using a shorthand if statements

$class = ($i % 2 ? 'low' : 'high');

<table>
<tr>
<td class="<?=$class?>">Row 1</td>
</tr>
<tr>
<td class="<?=$class?>">Row 2</td>
</tr>
<tr>
<td class="<?=$class?>">Row 3</td>
</tr>
</table>

Friday, March 13, 2009

Change the date format using PHP

If $month is currently Mar and your want March use

date("F",strtotime($month))

Simple