Using HostGator as a remote git repository

May 12th, 2011 No comments

I do freelance web development, and I’ve been looking for a way to get a remote repository for my work. I tried svn over ssh, no luck. But! Git works!

The first step is to get Shell Access to your Host Gator account. See: http://support.hostgator.com/articles/getting-started/how-do-i-get-and-use-ssh-access

Now, login, and create a git repository somewhere. (I put the git repository in the webroot of the subdomain of the project I’m working on. Now, from the directory of your git repository, type “pwd” and copy down the absolute path to yoru git repository.

Now, create a clone of that repository with your git client (I use msys git with git-gui). The url would be:

ssh://username@domain:2222/(path copied from pwd command)

Viola! It will ask you for your password 2 or 3 times, but it will create a clone of the remote git repository to your directory of choice. Now, you can commit changes locally and periodically push them to your remote repository.

Categories: git, hostgator 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…

jQuery(document).ready(
	function(){
		iframe_resize_extend_jQuery();
		if (top != self) {
			var parent_url = jQuery.getUrlVar('parent_url');
			if(parent_url){
				parent_url = unescape(parent_url);
				jQuery.cookie('parent_url', parent_url);
			} else {
				parent_url = jQuery.cookie('parent_url');
			}

			if(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 = options.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));
						break;
					}
				}
			}
			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.push(hash[0]);
		  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:

vimeo OEmbed service rejects Apache Commons Http Client User Agent

February 24th, 2011 2 comments

Recently I was working on implementing an OEmbed client for work, and I spent a while trying to figure out why an oembed lookup worked in firefox, but not in my Java Service…

The url was:  http://www.vimeo.com/api/oembed.xml?url=http://vimeo.com/17853047&maxwidth=320&maxheight=200&format=xml

For whatever reason, everytime I was making the request in my service I was receiving a 404 error.  I used tamper data in Firefox 3.6 to remove ALL headers except the host header, and it worked…  So, I set the user agent for apache commons HttpClient to a mozilla user agent string instead of the default “Jakarta Commons-HttpClient/3.1″  Just to verify this was the problem, I used tamper data again to set the User Agent for a request from firefox to “Jakarta Commons-HttpClient/3.1″ and I received a 404 error…

The User-Agent string I used is: “Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.04 (lucid) Firefox/3.6.13″

Categories: Social Media, workarounds 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…
<Center>
User Story
<br/>

<br/>
Scrum Users Group
<br/>

</center>

Categories: Uncategorized Tags:

Using Selenium to test Ajax

December 1st, 2010 No comments

If you’ve used Selenium before you know it’s power, and the pain of Ajax and Selenium…  I spent about a week on it at work and created several helper methods, but was never quite happy with my Ajax solution (waiting for text to be present, blech!!!).  Then, I found this article about getting selenium and ajax to play nicely…

It turns out the major JavaScript libraries (jQuery, YUI (v3+), Prototype, and Dojo) provide a way to see if requests are still active.  They provided instructions for writing a function, but I wanted a fool proof method, that JUST WORKS regardless of what library you use.

So, I created this function (Currently supports jQuery, Dojo, and Prototype, not Yui 3 yet):

function getActiveRequestCount(){
    var currentActiveRequestCount = 0;
    //Get prototype active requests...
    if(window.Ajax && window.Ajax.activeRequestCount){
        currentActiveRequestCount += window.Ajax.activeRequestCount;
    }

    //jQuery active requests...
    if(window.jQuery){
        currentActiveRequestCount += jQuery.active;
    }

    //Dojo
    if(window.dojo && window.dojo.io.XMLHTTPTransport.inFlight.length){
        currentActiveRequestCount += window.dojo.io.XMLHTTPTransport.inFlight.length;
    }
    return currentActiveRequestCount;
}

Then, use the following selenium command to wait for the request count to be low…

selenium.waitForCondition("selenium.browserbot.getCurrentWindow().getActiveRequestCount() == 0", "30000");

And viola!!!  No more pesky pauses!!!  Or wait for text to be present!!!

Categories: ajax, dojo, html, jquery, selenium, yui Tags:

Why you NEED to become framiliar with Maven.

November 18th, 2010 No comments

If you program in Java, you NEED to become fluent in Maven.

Why?  Because it simplifies working on projects a lot. 

Specifics:

  • Lots of utilities that can be run on any and all maven projects at any time with only one command, and without downloading anything manual.
  • Generate Javadocs instantly.(mvn javadoc:javadoc)
  • Run all tests with one command and receive pretty html reports of your test results.(mvn test)
  • View Test Code coverage with one command and no downloading. (mvn cobertura:cobertra)
  • Almost instantly use the latest Java libraries, like Apache Commons. (IDE detects unknown class and prompts you to add a dependency to your project).
  • Do selenium testing with one command. (mvn selenium:start-server)
  • Generate web projects that include Hibernate, Spring, and more in minutes. (mvn archetype generate)
  • Run your tomcat projects with a single command. (mvn tomcat:run)
  • And more!!!  If you develop in Java,  learning Maven will increase productivity a lot.

So, LEARN IT

Start off with this video:

Categories: java, maven, spring, web Tags:

Never ever ever make a php config file not a php file…

November 8th, 2010 1 comment

I was using a php sdk today where the config file is NOT a php file, but rather a file named .cfg…

The problem?  You have to restrict access to this file with a .htaccess file to prevent someone from reading it.  Whereas, if it were a php file, not only would you not have to prevent access to it, you also don’t have to write your own parser.

Lesson…  Don’t use a cfg file, where a php config file will do.

Categories: http, php, php5, web Tags:

Spring MVC Redirect using “redirect:url” syntax.

October 27th, 2010 2 comments

I searched online for how to do redirects from a controller, and only came up with the RedirectView…

But I KNEW there was an easier way I had seen before…

The key is make your controller function return a string…  And then return “redirect:URL” instead of a view name.  Violaa!

Absolute and relative urls work great.

See: Spring 3.0.x docs for UrlBasedViewResolver

Categories: http, java, spring Tags:

Oracle has wasted no time in Rebranding Sun products.

October 26th, 2010 1 comment

Unless you’ve been out of touch for a long time, you’ve heard that Sun bought MySql, and was subsequently bought by Oracle.  If you use java, you’ve noticed that Oracle hasn’t drug their feet in rebranding sun products as Oracle…  java url’s are now download.oracle.com instead of download.sun.com.

MySQL appears to have escaped the re-branding at the moment.  It will be interesting to see what Oracle does with it in the future…  If they killed it, they would tick off half the development community in the world, making them less-likely to choose Oracle products in the future (let’s face it, there are LOTS of un-objective decision makers in the world).  But they could put some spin on it, and use it to build their market share…  Let’s wait and see…

Categories: community, java, oracle, sun Tags: