11 Oct

Add EC2 to ECS Cluster

I have had a lot of problems with ecs-agent always connecting to the “default” cluster rather than the one I want it to connect to. All the other instructions missed one vital step – removing ecs-agent from docker and reinstalling – that way it re-reads the ECS config file – without this step I could not get ecs-agent to connect to anything other than “default” cluster.

To put an EC2 ecs-agent into a specific cluster do the following:

Edit the ecs configuration file at /etc/ecs/ecs.config: sudo vi /etc/ecs/ecs.config
Add: ECS_CLUSTER=YourCluster
Close the editor “:wq”

Stop ecs-agent: sudo docker stop ecs-agent

Remove ecs-agent from docker: sudo docker rm ecs-agent

Remove the ecs-agent checkpoint file: sudo rm /var/lib/ecs/data/ecs_agent_data.jsonRead the rest

05 Sep

WordPress Transients – Storing False

Storing information in transients is a great way to speed up WordPress, especially if you’re using a memory cache instead of the options table. However, storing false in transients is difficult, because false means there is no transient in the cache. So how do you store false in WordPress transients?

For a great introduction to transients, see https://css-tricks.com/the-deal-with-wordpress-transients/

Why would you want to store false? Generally you would want to store false when it is a legitimate value – for example, when looking for the permalink for a slug, if the slug doesn’t exist then false is a valid return, and you wouldn’t want to query the database every time you looked up the missing slug.… Read the rest

08 Apr

Issues Creating and Downloading File in IE from PHP

Took a while to fix this one. The problem is you create a download button in HTML that leads to a PHP program that creates a file that Internet Explorer should download. The code works fine in Firefox just not IE.

The original code was something like:
{code type=php}
header(“Pragma: no-cache”);
header(“Expires: 0”);

header(“Content-disposition: attachment; filename=\”export.xls\”;”);
header(“Content-Type: application/vnd.ms-excel”);
{/code}
Which works in Firefox but not IE. The new code is:
{code type=php}header(“Pragma: “);
header(“Cache-Control: “);

header(“Content-disposition: attachment; filename=\”export.xls\”;”);
header(“Content-Type: application/vnd.ms-excel”);
{/code}
And that works fine.… Read the rest

22 Jul

PHP UTF-8 and simplexml

Recently the page checking code was breaking when used on a site. The XML returned from the supplier was being read using file_get_contents() and passed straight into simplexml_load_string() which was then kicking out a UTF-8 Encoding Error.

The way around this is to use utf8_encode() to ensure the string is encoded into UTF-8 before passing to simplexml_load_string(). In this instance my code goes like:

{code type=php}
$FileContents = file_get_contents( $URL ) ;
if ( $FileContents !== false )
{
   $xml  = simplexml_load_string( utf8_encode( $FileContents ) ) ;
}
{/code}… Read the rest

29 Dec

jQuery – Add a default button to a page

Normally in HTML you can add a ‘input type=”submit”‘ to a page and it acts as a default button. However this only works if the input tag is within a ‘form’. I was using AJAX and found that adding a form caused the AJAX to fail. Instead I ended up with the following code:

$(‘input’).keyup(function(e) {
//alert(e.keyCode);
if(e.keyCode == 13) {
$(‘#btnSubmit’).click() ;
}
});

This adds to all input fields a keyup function that checks for the enter key and if found calls the click function on the button I want to use as the default button – in this case it’s an input button called ‘btnSubmit’.… Read the rest

07 Nov

Save HTML Table to Excel using jQuery

After a few hours work looking into this, this turned out really easy to implement using jQuery and server side PHP programming as follows:

On the client side the following HTML code needs adding to the page (note this is older code – for newer code follow link at bottom):

Note – variables used above – ReportTable is the id of the table you want to save and datatodisplay is a hidden variable used to post the table to the server.

The jQuery commands were added to the form’s onsubmit event but could easily be in your $(function(){}); fuction

The hard part here was getting all of the <table> HTML code.… Read the rest