Oct 262014
 

I love BackupPC it’s a truly awesome piece of software and a shining light in the open source world, but it can be cryptic and when it goes wrong the potential fallout is pretty major. The other day on one of my primary systems the backups began to fail with Fatal error during xfer (Child exited prematurely) no more detail simply that.  This is precisely the sort of backup fail I dread, they always seem to become apparent just before bed time!

Anyway I needed to see the behind the scenes output of what Rsync was doing so instep the handy debug tool BackupPC_dump this is precisely the tool you need to debug “Fatal error during xfer” errors.

You can see the full instruction here but the key bit is:

The BackupPC_dump command has a -v option, so the easiest way to debug backup problems on a specific host is to run BackupPC_dump manually as the BackupPC user:

su __BACKUPPCUSER__
__INSTALLDIR__/bin/BackupPC_dump -v -f hostName

which for me translated to:

cd /
su backuppc
./usr/share/backuppc/bin/BackupPC_dump -v -f mydomain.com
This quickly helped me identify problems with transferring of a particular sub folder, that as it happened wasn’t required anyway.  It also gave me a really handy look into the inner workings of backup pc rsync and how it works.
Good luck, hope it helps you resolve your issues with Fatal error during xfer (Child exited prematurely).

 

 

 

Nov 182013
 

As much as a note to self as anything else, for some reason it proved hard to find out how I could use html in the auto validation messages generated by models in CakePHP.  Now it’s totally arguable that the use of html is not best practice in this case, the right or wrong of that on a technical level is entirely up to you however assuming you do need/want to use html in the validation messages just make sure that on forms that are applicable you either use a custom form error trap:

e.g.

$this->Form->input(‘yourfield’,array(‘error’=>false);

$this->Form->error(‘yourfield’,array(‘escape’=>false);

OR the simpler mechanism is:

$this->Form->input(‘yourfield’,array(‘error’=>array(‘escape’=false);

As an added benefit assuming you’re wanting to wrap your html validation message in a custom div simply add a class attribute:

$this->Form->input(‘yourfield’,array(‘error’=>array(‘escape’=false,’class’=>’alert alert-error’);

So this is how you put html in CakePhp validation messages!

 

 

May 092013
 

Following on from a post I wrote a long time ago entitled “What does “__n()” do in cakephp?” I thought I’d follow up with an example of how to actually use the __n() with i18n in cakephp as it’s not obvious and also hard to find examples of use and or documentation.

If you’re using __(n) in version 2.0 or above Cake the documentation is here.  After a brief look around I couldn’t find the 1.3 version please comment if you have the link!  The documentation says this:

 __n(string $singularstring $pluralinteger $countmixed $args = null)
Returns correct plural form of message identified by $singular and $plural for count $count. Some languages have more than one form for plural messages dependent on the count.

This is fine but it doesn’t result in a translation that includes the actual numbers in translated context so here as a note to self more than anything is an example of how to actually use the __n() with i18n in cakephp:

echo sprintf(__n('%s Singularname', '%s Pluralname',$number,true),$number);

e.g. how to show “x dog/s”

echo sprintf(__n('%s dog', '%s dogs',$number,true),$number);

 

Hope that’s useful!

 

Jan 212013
 

For some reason wp_redirect/wp_safe_redirect in WordPress can be a total pain, whether it be when writing custom front end code, plugins or widgets I seem to come across an issue with redirects periodically, with the utterly frustrating “Cannot modify header information – headers already sent” error.  As a heads up, this is caused as the name suggests by  content in a header being pushed down before the redirect is called, this is a generic issue not one that is specific to WordPress.  More often than not it is simple to identify, if any of the involved PHP files have leading or trailing white space, and or there’s some hidden debug output you have forgotten.  Occasionally the issue is WordPress however, in my case the issue of wp_redirect not working on a custom admin page, was caused by a function in

/wp-admin/includes/template.php:1636 or so, whereby headers/html, quite a lot of them are indeed sent as part of the page load process.

Having ensured all of my files were trimmed and there was nothing wrong with my plugin code, I discovered here that there’s a little workaround for forms being called in custom admin pages, that is simply to append:

&noheader=true

To your action, e.g.

<form method=”POST” action=”?page=your-plugin-page&noheader=true”>

This resolved my problem instantly – understandably given it suppressed the content being produced in template.php!

Hope it helps anyone having problems with wp_redirect and wp_safe_redirect on custom admin pages in WordPress.

 

 

Mar 092012
 

Aptana for Eclipse is brilliant, an amazing plugin, that for the most part really gives a productivity boost.   Something that I’ve never quite understood however is why they keep messing with their FTP integration.  I’ll  be honest this was one of the main reasons I started using it instead of the older eclipse PHP tools.  For some reason though whenever I do an update it seems to work slightly differently – either location in the context menu, or what can be uploaded from where or whatever.  So in the latest version it’s known as “deployment” – ok that makes sense, but it’s also broken.    For ages I was living with “Opening file for write failed” errors, just switching to Filezilla when I needed to do FTP, this however is such a pain and really slows you down when you’re making small regular changes to test or whatever.   After yet another “Opening file for write failed”, I decided to sort it out, I found a few references to it, none of which really helped, so I resorted to the age old process of just trying different settings until I found one that worked.  Form me, the resolution of the Eclipse Aptana Studio 3 – FTP “Opening file for write failed” error was just to change to SFTP rather than non SFTP.  Nothing exciting in this, but worth noting simply because a number of references I found suggested the opposite also worked.  So the tip, if you’re getting “Opening file for write failed” in Aptana FTP, is just experiment with variations in your SFTP settings, one of them should work!

Jan 092012
 

I’ve just spent tow frustrating hours going around the houses, trying to work out how to link my brand new Facebook I-frame app to my fan page.  I’ve done this successfully before, but it was a while ago so this is a note to self.  I’m constantly amazed at how despite such comprehensive documentation it can be so difficult to find things that are so fundamental to how a Facebook app works.  So, in case it helps, to link a  Facebook app to a fan page (other than the page you create for the app) you need to use this url:

https://www.facebook.com/dialog/pagetab?app_id=YOUR_APP_ID&next=YOUR_URL

Obviously replacing the capitalised details.  The app ID is easy – found here in your app settings, the url as far as I can tell can be anything, just cut and paste your app url here and it will redirect you to it afterwards.  When linking your Facebook app to the fan page, the link above will allow you to select which page you want to link to, submit this.

From here, go to your fan page > edit page > apps (in the left nav) and the new app should be listed, from which point you can choose to “link to this tab” and it will appear in your menu on the left.

The information for this was sourced from https://developers.facebook.com/docs/appsonfacebook/pagetabs/ hopefully it will help you with how to link a Facebook app to a fan page.

 

 

 

Nov 122010
 

Just one of the various niggles in the SQL Server Management Studio 2008, if by mistake you set up a user and fail to uncheck the “enforce password policy” box (you may have good reason for this, but if you’re on a dev machine as I was it’s a bit of overkill I think), you may encounter access problems when accessing the system from for example a scripting language like Coldfusion or PHP.  In the case of Coldfusion the error looks like:

[Macromedia][SQLServer JDBC Driver][SQLServer]Login failed for user ‘cf_user’. Reason: The password of the account must be changed.

At this point it’s reasonably obvious that you must go in and change the user properties under Security > Users in SSMS.  However, havign created the user when one tries to remove this check box you will encounter (always I think)

The CHECK_POLICY and CHECK_EXPIRATION options cannot be turned OFF when MUST_CHANGE is ON.

This is a bug in the software, and while it is possible to actually change the password programatically thus:

USE Master
GO
ALTER LOGIN [somelogin] WITH PASSWORD = ‘samepassword’
GO
ALTER LOGIN [somelogin] WITH
CHECK_POLICY = OFF,
CHECK_EXPIRATION = OFF;

If you want to just reset this policy the easiest way is to just delete the user and then create it again making sure to leave the enforce password policy unchecked first time around.  There will be no problem saving it initially thus.

Mar 282010
 

In all the years I have used excel I have never once encountered this problem so hopefully this helps anyone else in the situation.  I have been used to Excel automatically updating its values (say in a sum() column) whenever I change values above, but somehow today it stopped working.  fortunately my better half happens to be an Excel nerd, so with her help I worked out what it was.

If you find that the values in Excel are not updating automatically it is probably because you have not got the (succinctly named) “calculation options” switched to automatic.  Apparently back in the day you were required to press F9 to do calculations at any stage, and indeed this still works, but if you want a more permanent solution in Excel 2007 at least goto:

Formulas > Calculation > Calculation options

Then check the “Automatic” selection.  This should rectify the problem immediately.

Jan 252010
 

I’ve been using Excel a lot more recently to crunch numbers, and something that I’ve found particularly handy has been the conditional formatting function, which will surprise surprise, format a cell or cells based on a condition. For me I was using the spreadsheet to highlight cells based on the length of their contents, I was using the spreadsheet for managing Google Adwords and needed to be sure that the titles, and descriptions didn’t exceed their maximum length like this:

excel-conditional-formatting-highight

I found it surprisingly confusing initially, mainly I think because I was thinking the conditional formatting was going to be managed inline like a traditional formula, it isn’t, it has it’s own management interface where you specify to what the formatting is supposed to be applied and for what reasons.

Ok, so I won’t go gthrough the whole process, I’ll assume you have seen (in Outlook 2007) the “Conditional formatting” button under the “home” tab:

excel-conditional-formatting-select

And have also seen the “Highlight Cells rules” link underneath, here is the place where you can specify the conditions you want to highlight, and have set it up so that at least one cell does what you want (this was pretty straight forward I think, if you’re not sure what to do please leave a comment/question).

From here though I was stuck, I didn’t get how to update the range to which it was applied, and have it rolled out across multiple cells.  In step the  “Manage rules” link that is in the image above.  This is a separate screen where you get a summary of all the conditional formatting rules on your spreadsheet. Open it up and you will see something like this:

excel-conditional-formatting-manage

As you can see I have used a formula based on a relative cell value (i.e. one that updates relative to the cell you’re working with rather than referring to a single static location), this is what those $ symbols mean, the rule I have is that any cell that exceeds 25 characters in length should be coloured red.  The mistake I had originally made was to firstly not use a relative cell value (my original formula was len($S$1) > 25    ) and then to not have specified the range correctly in the “applies to” box.

Experimenting with the “Rules Manager” for conditional formatting reveals this to be just as powerful as you were probably expecting when you started.  Good luck!

Jan 202010
 

.htaccess problems and can be a real pain, especially if like me you only do things with the .htaccess file every now and then so aren’t completely comfortable with the syntax.  Last night when helping a friend and author of the excellent ExchangeWire (about tracking the nascent ad exchange and ad trading networks) switch a domain, I configured the .htaccess file using a standard format:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www. oldomain.com$
RewriteRule ^(.*)$ “http\:\/\/www\.newdomain\.com\/$1″ [R=301,L]

I say “a” standard format because as anyone who has used .htaccess before knows, there are a few variations on this syntax that do the same thing.  Not thinking about it much I put this in the root .htaccess of the WordPress install, I tested the top domain, worked fine, but the pages themselves just kept redirecting to the the root, not the actual page.  My complete .htaccess file that was not redirecting properly:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www. oldomain.com$
RewriteRule ^(.*)$ “http\:\/\/www\.newdomain\.com\/$1″ [R=301,L]

Ok so the clued up amongst you will realise the problem was caused because of the ordering of the commands I had put in the file, this is important. In terms of importance, the domain redirection had to happen first, so I needed to put it above the WordPress command otherwise the WordPress command hijacked the process and confused the primary redirect.  So, the lesson is be careful of the order you put things in and the potential conflicts that can occur as a result.  Keep the major redirects/rules at the top of the page (e.g. when you want to change domains) and the more detailed one(s) below for more consistency (such as WordPress redirects).