Loading JavaScript Better :) July 20th, 2010

Michael Hartmayer

After watching some very stimulating google tech talks on YouTube, I walked away with some new insight on how browsers load content. The following is a technique I picked up that allows for all included javascripts to load in parallel (instead of sequentially), and to prioritize the loading of your visible page content first.

The following code is placed before the closing body tag (and not in the head, as is traditionally done).

<script type="text/javascript"> 
	var DocumentHead = document.getElementsByTagName('head')[0];
 
	function jsOptimizedLoader(src) {
		var Script = document.createElement('script');
			Script.src = src;
			Script.type = 'text/javascript';
			DocumentHead.appendChild(Script);
	}
 
	jsOptimizedLoader('js/app/foo.js');
	jsOptimizedLoader('js/app/bar.js');
	jsOptimizedLoader('js/app/boo.js');
	jsOptimizedLoader('js/app/far.js');
</script>

Once your DOM has finished loading, all the scripts tags are added to the head via javascript. Allowing your page to display PRIOR to spending the time loading all of those scripts will win you usability points and ease of access points with your audience.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon

Continue reading...


 

AS3 Parallax Class June 18th, 2010

Michael Hartmayer

Just something I’ve been toying with. I’ve always wanted to write a class to generate a nice Parallax Effect. Good practice.

Class can be downloaded from: http://pastebin.com/86HYEJqA

Implementation would look something like this:

import Machinespark.SimpleParallax.SimpleParallax;
var ParallaxHolder:MovieClip = new MovieClip();
	addChild(ParallaxHolder);
 
var NewParallax:SimpleParallax = new SimpleParallax(stage.width, stage.height);
	NewParallax.AddPane(new mcPane3, 3);
	NewParallax.AddPane(new mcPane2, 6);
	NewParallax.AddPane(new mcPane1, 9);
	NewParallax.AttachParallax(ParallaxHolder);
	NewParallax.StartParallax();
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon

Continue reading...


 

CSV Export Class for PHP May 2nd, 2010

Michael Hartmayer

Since I’ve been working with a lot of different data sources lately, I’ve found myself needing an easy to use CSV Export class. So, here it is, CSVMaker.php

This class makes it very easy to create CSV files on the fly, from any type of data. Here’s a usage example:

$CSV = new CSVMaker();
 
// Optionally Change the Format
$CSV->csvDelimeter    = ","; // (What seperates each value in a set Foo,Bar,Etc)
$CSV->csvLine         = "\n"; // (What ends one set of data - usually a new line)
$CSV->csvCapsule      = '"'; // (What comes before and after each piece of data "Foo","Bar","Etc")
 
$CSVHeader = array();
$CSVHeader['first_name'] = "First Name";
$CSVHeader['last_name'] = "Last Name";
 
$CSV->createTemplate($CSVHeader);
 
$CSVLine = array();
$CSVLine['first_name'] = "Michael";
$CSVLine['last_name'] = "Hartmayer";
 
$CSV->addEntry($CSVLine);
 
file_put_contents("MyCSVFile.csv",$CSV->buildDoc);
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon

Continue reading...


 

Fetch Google Pages Indexed Using PHP and AJAX April 1st, 2010

Michael Hartmayer

Here’s a quick and dirty solution I threw together to fetch how many pages of a site google has index. I needed this for one of my control panels, so my work group could track this and other metrics on the fly.

gpindex.php

<?php
	// Some arbitrary access code so not everyone can access it. Not "real" security :)
	if($_GET['accessCode']!="some_password") { echo "Access Denied"; exit; }
 
	$site = $_GET['site'];
	$gurl = "http://www.google.com/search?q=site:";
 
	$curl_handle=curl_init();
	curl_setopt($curl_handle,CURLOPT_URL,$gurl.$site);
	curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
	curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
	$buffer = curl_exec($curl_handle);
	curl_close($curl_handle);
 
	preg_match_all("#Results(.*)of about <b>(.*)</b> from <b>$site</b>#",$buffer,$matches,0);
	echo $matches[2][0];
?>

And here’s the Ajax via jQuery that is used to fetch the information:

<script type="text/javascript" src="js/patch/jquery.min.js"></script>
<script type="text/javascript">
   $(document).ready(function(){
      $.ajax({
         url:"http://www.example.com/path/to/gpindex.php?accessCode=some_password&site=example.com",
         success:function(d){$("#googleIndexed").html(d+" Pages");}
      });
   });
</script>
<p style="font-size:11px;">Indexed on Google</p>
<p style="font-size:11px; font-weight:bold;" id="googleIndexed">( Fetching Data )</p>
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon

Continue reading...


 

OfficeDuck.com – My New eCommerce Site March 16th, 2010

Michael Hartmayer

Check out my new eCommerce site. Running off of Magento, and features over 35,000 products.

http://www.officeduck.com/

<Quack Quack>

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon

Continue reading...


 

The 125k Challenge January 19th, 2010

Michael Hartmayer

This is a new thing I’m working on. My goal is to make $125,000 in one year, using only my own projects. Check it out!

Official Website: http://www.125kchallenge.com/
YouTube: http://www.youtube.com/125kchallenge/
Twitter: http://www.twitter.com/125kchallenge/

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon

Continue reading...


 

Working on New Portfolio Theme! December 4th, 2009

Michael Hartmayer

Working on a new theme for my Portfolio! The theme I’m currently using is just something I grabbed off some site, to get my portfolio up and running. Now that I have time to rework it, I’m putting a little extra time and effort into it. So far my process has been to create a wire frame of the elements, and markup some basic functionality (I created an asset list document to work from, before creating the wires). This will make designing a whole lot easier and permit me to only have to worry about the “pretty factor”, since I’ve already mapped out my functionality and flow.

Check out my progress:

Wireframes (Layout):

Wireframe: Layout

Wireframe (Layout + Navigation Example):

Wireframe: New Layout with Navigation

Designing the Background:

Design: Background

( I’ve already got grid lines in place to make sure everything will work with 960px. width )

More Background Work + Some Layout:

Design and Layout: New Portfolio

Trying to find a good way to present the navigation:

UI - Designing Navigation

Started Filling in the Content UI:

New Portfolio Theme: Content and UI

Continued:

New Portfolio Theme: UI and Design Continued

Continued:

New Portfolio Theme - UI and Design Continued

Continued:

New Portfolio Theme: UI and Design Continued

Continued:

New Portfolio Theme: Created Custom Icons

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon

Continue reading...


 

IE6 / IE7 jQuery Fix: Anchor Image Clickable Area September 25th, 2009

Michael Hartmayer

IE6 and IE7 both experience a problem in which images inside of block elements inside of anchors lose their click ability. Here’s an example:

<a href="rss-icon.png">
	<span style="display:block; width:100px; height:100px;">
		<img src="someImage.png" />
	</span>
</a>

Every area of the link remains click-able except for the surface consumed by someImage.png. (Note, this problem will not show in IE8, or FF)

Here’s a very small jQuery plugin I wrote to fix this particular issue.

(function($){
	$.fn.fixClick = function() {
		return this.each(function(){
			$(this)
				.css({cursor:'pointer'})
				.click(function(){
					window.location.href = $(this).attr('href'); 
				});
		});
	}
})(jQuery);

Simply select your target element(s) and use this plugin to make the entire anchor click-able again. Here’s an example:

$(document).ready(function(){
   $('a').fixClick();
});
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon

Continue reading...


 

Scripting for Smarties : Application Portability 101 September 23rd, 2009

Michael Hartmayer



Here’s the first ‘tutorial’-esque video that I’ve published in my new Channel Scripting for Smarties.

Enjoy~

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon

Continue reading...


 

PHP Database Class September 10th, 2009

Michael Hartmayer

I just recently wrote a brand new Database class to add to my PHP library. The old one was starting to get stale. This class is capable of taking advantage of the Singleton design pattern.

<?php
 
/**
 * @author Michael Hartmayer (michaelhartmayer[at]gmail.com)
 * @copyright 2009
 */
 
	class Db {
 
		static $ref;				// Database Resource
 
		private $user 	= 'root';		// Username
		private $pass 	= '';			// Password
		private $host 	= 'localhost';		// Host
		private $db 	= 'test';		// Database
 
		private $err 	= array();		// Error Log
		private $errHalt = true;		// Toggle: Halt on DB Error?
 
		static $q;				// Last Query
		static $r;				// Last Results
 
		static $singleton;
 
		public function Db() {
			return true;
		}//endMethod
 
		public function getInstance() {
			if(!self::$singleton)
				self::$singleton = new self;
 
			return self::$singleton;
		}//endMethod
 
		public function setUser($i) {
			$this->user = $i;
			return true;
		}//endMethod 
 
		public function setPass($i) {
			$this->pass = $i;
			return true;
		}//endMethod
 
		public function setHost($i) {
			$this->host = $i;
			return true;
		}//endMethod
 
		public function setDb($i) {
			$this->db = $i;
			return true;
		}//endMethod
 
		public function setAll($h,$u,$p,$d) {
			$this->host = $h;
			$this->user = $u;
			$this->pass = $p;
			$this->db = $d;
			return;
		}//endMethod
 
		public function doConnect(){
			if(!empty($this->ref))
				$this->doDisconnect();
 
			if(!$this->ref = @mysql_connect($this->host,$this->user,$this->pass))
				return $this->dbErr(mysql_error());
 
			if(!@mysql_select_db($this->db,$this->ref))			
				return $this->dbErr(mysql_error($this->ref));
 
			return true;
		}//endMethod
 
		public function doDisconnect() {
			if(empty($this->ref)) return false;
 
			mysql_close($this->ref);
			$this->ref = null;
 
			return true;
		}//endMethod
 
		public function getRef() { 
			return($this->ref);
		}//endMethod
 
		public function dbSet($q) {
			$this->q = $q;
			if($this->r=@mysql_query($this->q,$this->ref)) 
				return true;
 
			return $this->dbErr(mysql_error($this->ref));
		}//endMethod
 
		public function dbGet($q,$type='') {
 
			switch($type) {
				case 'STR':
					$resultType = MYSQL_ASSOC;
					break;
				case 'INT':
					$resultType = MYSQL_NUM;
					break;
				default:
					$resultType = MYSQL_BOTH;
					break;
			}
 
			$this->q = $q;
			if(!$this->r = mysql_query($this->q,$this->ref)) 
				return $this->dbErr(mysql_error($this->ref));
 
			$resultArr = array();
			while($makeDbArr = mysql_fetch_array($this->r,$resultType)) {
				$resultArr[] = $makeDbArr;
			}//endWhile
 
			return $resultArr;
		}//endMethod
 
		public function dbCount($table, $matchPartialQuery='') {
			$this->q = "SELECT COUNT(*) AS 'COUNT' FROM `$table` $matchPartialQuery;";
			if($this->r = $this->dbGet($this->q))
				return $this->r[0]['COUNT'];
 
			return $this->dbErr(mysql_error($this->err));
		}//endMethod
 
		private function dbErr($err) {
			if(empty($err)) return false;
 
			$this->err[] = $err;
 
			if($this->errHalt==true) {
				echo ">> System has halted on Db Error. <br />";
				echo ">> Error Log:<br /><br />";
				print_r($err);
				exit;	
			}
 
			return err;
		}//endMethod
 
		public function strClean($str) {
			return mysql_real_escape_string($str,$this->ref);
		}//endMethod
 
	}//endClass
 
?>
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • StumbleUpon

Continue reading...