Archive for the ‘Uncategorized’ Category

MySQL Temporary Tables and CakePHP 1.3

July 24th, 2012 2 comments

So, if you create a MySQL temporary table in CakePHP, when you try to create a model for that table, it dies, because mysql “Show Tables” doesn’t show temporary tables.  To get around this, implement the setSource function in your model..  i.e.

class WholesalerLeadsDataTemp extends AppModel{

	var $name = 'WholesalerLeadsDataTemp';
    function setSource($tableName) {
        $db =& ConnectionManager::getDataSource($this->useDbConfig);
        $db->cacheSources = ($this->cacheSources && $db->cacheSources);

        //MySQL Doesn't return temporary tables in the list of tables, so we have to disable this check...  (yay...)...
//        if ($db->isInterfaceSupported('listSources')) {
//            $sources = $db->listSources();
//            if (is_array($sources) && !in_array(strtolower($this->tablePrefix . $tableName), array_map('strtolower', $sources))) {
//                return $this->cakeError('missingTable', array(array(
//                    'className' => $this->alias,
//                    'table' => $this->tablePrefix . $tableName,
//                    'code' => 500
//                )));
//            }
//            $this->_schema = null;
//        }
        $this->table = $this->useTable = $tableName;
        $this->tableToModel[$this->table] = $this->alias;
Categories: Uncategorized Tags:

Update a wordpress site to a new domain…

August 18th, 2011 No comments

I like to do all my work locally, and so I frequently copy a remote site to my local computer, but I also like to NOT mess with my hosts file so that I can always look at the live site, and you never get into one of those “Is this the live site?” situations. Unfortunately wordpress uses serialized php arrays to store much of it’s data.  And those serialized arrays cannot simply be search and replaced.  (Because php has a basic string length checksum built into the serialize unserialize methods), so you need to use this too:



Categories: Uncategorized, wordpress Tags:

SEO Friendly URL’s in Cake PHP

May 4th, 2011 No comments

I love cake php… It’s awesome.

But one thing I want, is more friendly urls…

i.e. I want /myAccount/index to be /my-account/index

I found a few solutions, but settled on this one, by changing your .htaccess file and adding two RewriteRules you can replace all -‘s with _’s, which will then allow the Cake Router to route the url to the right controller.

The finished .htaccess file should look like this:

RewriteEngine on
RewriteRule ^([^\-]*)\-([^\-]*\-.*) $1_$2 [N]
RewriteRule ^([^\-]*)\-([^\-]*)$ /$1_$2 [N]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]

Categories: Uncategorized Tags:

Dynamic Sizing of a cross domain iframe

March 25th, 2011 No comments

There are several ways to communicate via domains in a browser. One of the simplest is using the hash on a url… i.e. The part of the url AFTER the # sign.

The way this works is… The parent window can set the url of the child iframe, and the child iframe can set the url of the parent window. The only hangup, is that both windows need to know the correct location for the other window before they can properly set the hash on the other’s url without navigating the other to a different url…

Recently I explored methods of accomplishing this for a project I was working on. After trying a few solutions I came up with a simple clean solution that works GREAT if both sides already know the url for the other… And acutally, for resizing, only the page in the iframe needs to know the right url for the parent, as the communication is only one way… Below is the code… (jQuery is required, but this could easily be changed just by setting the function as an event handler without jQuery.)

So… On all pages in the child iframe you want to resize make sure jQuery is installed and add this code…

		if (top != self) {
			var parent_url = jQuery.getUrlVar('parent_url');
				parent_url = unescape(parent_url);
				jQuery.cookie('parent_url', parent_url);
			} else {
				parent_url = jQuery.cookie('parent_url');
				var url = parent_url + '#'  + document.body.scrollWidth + 'x' + document.body.scrollHeight;			
				parent.location = url;

function iframe_resize_extend_jQuery(){
	if(!jQuery.cookie) jQuery.cookie = function(name, value, options) {
		if (typeof value != 'undefined') { // name and value given, set cookie
			options = options || {};
			if (value === null) {
				value = '';
				options.expires = -1;
			var expires = '';
			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
				var date;
				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
				} else {
					date = options.expires;
				expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
			// CAUTION: Needed to parenthesize options.path and options.domain
			// in the following expressions, otherwise they evaluate to undefined
			// in the packed version for some reason...
			var path = options.path ? '; path=' + (options.path) : '';
			var domain = options.domain ? '; domain=' + (options.domain) : '';
			var secure = ? '; secure' : '';
			document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
		} else { // only name given, get cookie
			var cookieValue = null;
			if (document.cookie && document.cookie != '') {
				var cookies = document.cookie.split(';');
				for (var i = 0; i < cookies.length; i++) {
					var cookie = jQuery.trim(cookies[i]);
					// Does this cookie string begin with the name we want?
					if (cookie.substring(0, name.length + 1) == (name + '=')) {
						cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
			return cookieValue;

	if(!jQuery.getUrlVars) jQuery.getUrlVars = function(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		  hash = hashes[i].split('=');
		  vars[hash[0]] = hash[1];
		return vars;

	if(!jQuery.getUrlVar) jQuery.getUrlVar = function(name){
		return jQuery.getUrlVars()[name];  

And, on the parent window add...

var refreshFrequency = 30;
var extraHeight = 0;
var extraWidth = 0;
var lastHeight = 0;
var lastWidth = 0;
var iframeId = 'resizeIframe';

function checkIFrameSize(){
  if(window.location.hash && document.getElementById(iframeId)){
    var currentHeight = parseInt(document.getElementById(iframeId).style.height.replace(/[^0-9]/g, ''));

    var dimensions = window.location.hash.split('x');

    if(dimensions.length == 2){
        var width = parseInt(dimensions[0].replace(/[^0-9]/g, ''));
        var height = parseInt(dimensions[1].replace(/[^0-9]/g, ''));
    if(!isNaN(width) && !isNaN(height)){
        var newWidth = (width + extraWidth);
        if(lastWidth != newWidth){
            document.getElementById(iframeId).style.width =  (newWidth) + 'px';
            lastWidth = newWidth;

        var newHeight = (height + extraHeight);
        if(newHeight != lastHeight){
            document.getElementById(iframeId).style.height = (newHeight) + 'px';
            lastHeight = newHeight;
  setTimeout(checkIFrameSize, refreshFrequency);

setTimeout(checkIFrameSize, refreshFrequency);

That's it!

Categories: html, Uncategorized Tags:

SCRUM according to my wife…

January 20th, 2011 No comments

My wife is a great listener, and enjoys me talking about work.  She lets me use acronyms, etc…  And I explain them as I go.  Anyways, recently she enlightened me to what she thinks of when she hears a few scrum terms…
User Story

Scrum Users Group


Categories: Uncategorized Tags:

Blocking Webform / Comment Spammers…

October 20th, 2010 No comments

I found out about this site today, that hosts a sample .htaccess file that will block IP Addresses that are known spammer ip’s.  Not email spammers, but webform spammers…  (Very annoying!)

Check it out:

Categories: Uncategorized Tags:

Troubleshooting By Dividing

October 19th, 2010 No comments

Troubleshooting…  When you are troubleshooting something, divide and conquer…  In a large system, choose a point in the middle of the system, and see if the problem exists there.  If it does, move backwards half way to the start of the system, and test again…  Continue….

This process allows you to find problems in large and complicated systems effeciently.

Good instrumentation in a large system makes this process even easier.  A blackbox system, in which you cannot look inside is extremely difficult to troubleshoot.  The same problem exists for systems that cannot be operated with it’s clothes off.  For example, Computer monitors.  I have tried to repair expensive computer monitors in the past with some success.  There are lots of little controls inside the monitor that can be adjusted.  You can also find bad solder joints by wiggling parts inside the monitor and see if it makes it start working.  However, many monitors cannot be operated with the cover off.  The same problem exists for code that cannot be debugged easily. 

So…  Next time you are trying to fix an annoying bug…  Divide and conquer.  If you don’t have good instrumentation, add it in!  In php, and easy way to add instrumentation is by adding your own custom header with debug information.

Categories: Uncategorized Tags:

oEmbed – Easily get the information you need to embed content from viddler, flickr, hooloo, etc… in your pages.

June 9th, 2010 No comments

oEmbed is an open standard that allows you to pass a url to an oEmbed provider and get back information about that resource.

i.e. Pass a hulu url to hulu’s oEmbed service:  and you’ll get back a json object with details of the video (thumbnail size and url, etc..) and on some oembed services the html needed to embed the video.

For more information, check out this page:

Categories: Uncategorized Tags:

HTML 5 Freature Overview Presentation With Sample Code

April 23rd, 2010 No comments

At work Shawn Lonas sent this out to all of us, it’s a really good concise overview of some html5 features.

Categories: html, html5, Uncategorized Tags: , ,

Developing a website offline.

January 9th, 2009 No comments

WAMP gives you everything you need to serve websites (with php and mysql) from your desktop while developing. Just download it, install it, and run it.  Once it is running, click on the system tray icon and select “Start All Services”.  If something isn’t working, stop Skype first and then start the services.  Also note, that windows is not case sensitivie with respect to file names and linux is, so if you script works fine one your desktop but your host says a file is missing, check the case.  Make sure it is exactly the same (Using extensive use of copy and paste eleminates this as a source of trouble.)

Categories: Uncategorized Tags: