March 30, 2012
No Comments
Having issues with javascript dependencies or awkwardly structured html defining objects you need before run?
This is a little trick I used combined with csnover’s roundrect.js to provide IE versions < 9 with border-radius rounded corners.
Create a separate source file e.g. mylateloader.js and in it include the following code :-
function myInArray(needle, haystack) {
var length = haystack.length;
for(var i = 0; i < length; i++) {
var str = jQuery(haystack[i]).attr(‘src’);
if(typeof(str) != ‘undefined’ && str.search(‘.*’+needle+’.*’) > -1) return str;
}
return false;
}
jQuery(document).ready(function(){
var script = document.createElement(‘script’);
url = myInArray(‘mylateloader.js’, document.getElementsByTagName(‘script’));
script.src = url.replace(‘mylateloader.js’,'mycoolminifiedfile.min.js’);
document.getElementsByTagName(‘head’)[0].appendChild(script);
setTimeout("mycoolobject.run()",2000);
})
That way, at document.ready(), mycoolminifiedfile.min.js is loaded from the same directory on the server as the late loader js and 2 seconds later, the mycoolobject.run() is called.
Okay, this is hacky but it really works, and saves a lot of time!
To copy the css selector of an element in chrome, you need your developer tools open popped-out of chrome, not docked but here is the trick :-
Inspect the element that you want, be sure it’s selected in developer tools, then press F12. This will open a second developer tools window inspecting the first developer tools.
Then, insert the following two lines of javascript magic, one at a time – the first pulls jQuery into the developer tools and the second runs a function to build the css path and output it into the console!
First jQuery :
var script = document.createElement('script');script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js";document.getElementsByTagName('head')[0].appendChild(script);
Then the path :
path=""; function addtopath(str) { if(typeof(str) != 'undefined') {path = str+' '+path} } jQuery('.crumbs span').each(function(){addtopath(jQuery(this).attr('title'))}); path;
You can try stringing them together into one command, but sometimes jQuery doesn’t seem to load fast enough.
March 28, 2012
No Comments
If you use PHP’s list function to quickly extract array values out into dollar variables then you might have an issue where it just doesn’t work for some reason.
The problem is that list only works with numeric arrays. If you are using an associative array (with strings for keys instead of numbers) then list will not work.
There is any easy solution though, simply change:
$array = array('a'=>1, 'b'=>2, 'c'=>3);
list($a, $b, $c) = $array;
To:
$array = array('a'=>1, 'b'=>2, 'c'=>3);
list($a, $b, $c) = array_values($array);
And it will work as you expect.
php, By:
admin
No Comments
Tags:
array,
associate,
bug,
indexed,
key,
list,
numeric,
php,
solution,
string,
values
Useful tip – if you’ve ever been ssh’d into a remote machine and don’t want to break the connection or open a new session just to add a new tunnel, there is a way
Press [return] then ~ then C to get to an ssh prompt, then you can add tunnels as you would at the command line e.g.
-L 80:localhost:8080
Then press [return] to return to the session you were running. Cool trick.
March 27, 2012
No Comments
If you have a staging copy of your site anywhere then you might not bother copying over your entire catalogue of product images etc.
You might decide to drop in absolute URLs for those images so that they are pulled from live. However you really don’t want absolute URLs in your code and you certainly don’t want that to go live because it just adds unnecessary bloat.
A nice trick you can do here is make a change to your staging site as follows. Of course ensure this change doesn’t go live, but it should be just one file so that’s easy to handle.
(Note this assumes you already have jQuery available on your page)
<script type="text/javascript">
$().ready(function(){
$('img').each(function(){
var src = $(this).attr('src')+'';
if(-1 == src.indexOf('http')){
var new_src = 'http://www.LIVEDOMAIN.co.uk/'+src;
$(this).attr('src', new_src);
}
});
});
</script>
Don’t forget to change LIVEDOMAIN to be your real live domain
javascript, By:
admin
No Comments
Tags:
abolute,
debugging,
development,
hosting,
image,
images,
img,
javascript,
jquery,
staging,
tip,
urls
March 21, 2012
No Comments
Easily deploy PHP applications to the Amazon Web Services infrastructure allowing you to take advantage of an easily scaled flexible cloud based system.
Furthermore there is Git based deployment so your version control workflow can hook directly into deployment for speed and convenience.
This does really look attractive. The Angry birds store recently launched on Magento using Varnish and Amazon Web Services and it runs very fast indeed. Perhaps the days of expensive dedicated hardware are really numbered. If its this easy to set something up that can perform as well as a complex server cluster at a fraction of the cost.
http://aws.typepad.com/aws/2012/03/aws-elastic-beanstalk-build-php-apps-using-git-based-deployment.html
hosting, By:
admin
No Comments
Tags:
amazon,
availability,
cloud,
deployment,
ec2,
hit,
php,
scalability,
services,
web
March 20, 2012
No Comments
Static analysis is the process of parsing and searching through code without actually running it. It is the equivalent of someone opening your code base in their IDE and reading through it in detail.
RIPS is a tool I have just come across for doing PHP static analysis. You just need a working Apache stack etc for it to work which any PHP dev is going to have.
http://rips-scanner.sourceforge.net/
March 12, 2012
No Comments
We have recently launched a clean, clear and simple web site for local architects SDM architecture who are based in Baildon near Shipley, Bradford and Leeds.
The brief was a clean web site that Stephen the owner can easily manage with his own content showcasing his work and attracting new clients.
All in all the project was a big success with a very rapid turnaround.
Stephen said
“you have been very helpful and I have appreciated everything you have done for me”.
here is a screenshot:

March 8, 2012
No Comments
One of the features that I was previously unaware of in Netbeans is its ability to automatically generate common class methods. This post is a quick guide of how this works for future reference.
To get the system to work, first load up a php class. For this example I’m going to be extending the Magento Product Model. This basic class can be seen here, with a couple of extra properties added.

To start generating the methods you need to press [Alt] & [Insert] and you will be presented with a menu similar to the one below

This lists all of the common methods that do not currently exist within the class. The first thing that we’ll do is to generate a constructor, which gives us the following options

Here you can select which of the class properties you want to be set using the constructor. Pick the ones you want and click OK, and the following code is generated

The Getters and Setters work in the same way, and the Override & Implement provides you with a list of all of the methods that the class can override from its parents. Using these together can help you to quickly all of the methods you need in minutes, as shown below.

If you are developing a Magento store and you would like a method you can call to completely clear everything out that might be cached or indexed etc then you will like this little snippet:
public function flushEverything() {
Mage::app()->getCacheInstance()->flush();
Mage::getModel('core/design_package')->cleanMergedJsCss();
Mage::getModel('catalog/product_image')->clearCache();
$indexer = Mage::getSingleton('index/indexer');
/* @var $indexer Mage_Index_Model_Indexer */
foreach($indexer->getProcessesCollection() as $process){
$process->reindexEverything();
}
}
This flushes the cache storage, removes merged JS/CSS files, flushes the product image cache then loops through each index and reindexes.
Perhaps overkill but sometimes there’s nothing like the use of excessive force!
magento, By:
admin
1 Comment
Tags:
cache,
code,
css,
flush,
image,
index,
js,
magento,
snippet,
storage