<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:refactormycode.com,2007:users186</id>
  <link type="application/atom+xml" href="http://refactormycode.com/users/186" rel="self"/>
  <title>richardhealy</title>
  <updated>Sat Oct 27 13:31:23 +0000 2007</updated>
  <entry>
    <id>tag:refactormycode.com,2007:Code113</id>
    <published>2007-10-27T13:31:23+00:00</published>
    <updated>2007-11-05T02:55:09+00:00</updated>
    <title>[JavaScript] Stop Watch</title>
    <content type="html">&lt;p&gt;I use this to test speed of javascript code. Any ideas on how to make it better?&lt;/p&gt;

&lt;pre&gt;#Functions [javscript]
var ms = 0;
var state = 0;

function startstop() 
{
	if (state == 0)
	{
		state = 1;
		then = new Date();
		then.setTime(then.getTime() - ms);
	}
	else
	{
		state = 0;
		now = new Date();
		ms = now.getTime() - then.getTime();
	}
}

function swreset() 
{
	state = 0;
	ms = 0;
}

function display() 
{
	now = new Date();
	ms = now.getTime() - then.getTime();
	document.write('Time:'+ ms);
}

//Array Join
startstop();
str1 = '';
arr = [];
for (var i = 0; i &amp;lt; 100000; i++)
{
	arr[i] = ' AND A ' + i;
}
str1 = arr.join(' ');
startstop();
display();
swreset();&lt;/pre&gt;</content>
    <author>
      <name>richardhealy</name>
      <email>richard.healy@progressiveinternet.co.uk</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/113-stop-watch" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor478</id>
    <published>2007-10-19T08:45:20+00:00</published>
    <title>[JavaScript] On Curry</title>
    <content type="html">&lt;p&gt;Let me show you how I am using it. It might help to show you how I am implementing this. This is my rating widget that I use my Currying function in (lines 43 and 44). You can see the example working here: &lt;a href="http://code.richardhealy.co.uk/yui/rating/index.htm" target="_blank"&gt;http://code.richardhealy.co.uk/yui/rating/index.htm&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;## Javascript [javascript]
function curry(fn, scope)
{
	var scope = scope || window;
	var args = Array.prototype.slice.call(arguments, 2) || [];

	return function()
	{
		fn.apply(scope, args);
	};
};

var rating = function(id, value)
{
	this.construct.apply(this, arguments);
};

rating.prototype =
{
	construct: function(id, stars, value)
	{
		this.__timeout = -1;
		this.__listeners = {};
		this.__timeouts = {};
		this.id = id;
		this.imageOff = 'assets/blank.gif';
		this.imageOn = 'assets/gSelected.gif';
		this.imageOut = 'assets/bSelected.gif';
		this.timeout = 500;
		this.value = value;
		this.stars = stars;
		
		var outsideEl = document.getElementById(id);
		
		for(i=1; i&amp;lt;=this.stars; i++){
			var imgID = 'img'+i;
			var newimg = document.createElement('img');
			newimg.id = imgID;
			newimg.src = this.imageOff;
			
			//Appends Image within the external container
			outsideEl.appendChild(newimg);
			
			YAHOO.util.Event.addListener(document.getElementById(imgID), &amp;quot;mouseover&amp;quot;, curry(this.mouseOver, this, i)); //&amp;lt;--- Currying Used Here
			YAHOO.util.Event.addListener(document.getElementById(imgID), &amp;quot;click&amp;quot;, curry(this.clickMethod, this, i));   //&amp;lt;--- Currying Used Here
		}
		
		this.addMethodListener(&amp;quot;mouseOut&amp;quot;, this.id, &amp;quot;mouseout&amp;quot;);
		
		this.renderStars(this.value, false);
	},
	
	addMethodListener: function(method, el, event)
	{
		var that = this;
	
		this.__listeners[&amp;quot;method:&amp;quot; + name + &amp;quot;:&amp;quot; + el.id + &amp;quot;:&amp;quot; + event] = function()
		{
			that[method].apply(that, arguments);
		};
	
		YAHOO.util.Event.addListener(el, event, this.__listeners[&amp;quot;method:&amp;quot; + name + &amp;quot;:&amp;quot; + el.id + &amp;quot;:&amp;quot; + event]);
	},

	mouseOver: function(rating)
	{
		this.clearTimeout(this.__timeout);
		this.__timeout = -1;

		this.renderStars(rating, true);
	},
	
	clickMethod: function(rating)
	{
		this.value = rating;
		this.onClick(rating);
	},

	mouseOut: function()
	{
		if(this.__timeout != -1)
		{
			this.clearTimeout(this.__timeout);
		}

		this.__timeout = this.setTimeout('onTimeOut',this.timeout);
	},
	
	onTimeOut: function()
	{
		this.renderStars(this.value, false);
	},

	renderStars: function(units, startColor)
	{
		for (var i = 1; i &amp;lt;= units; i++)
		{
			if(startColor == true)
			{
				document.getElementById(&amp;quot;img&amp;quot; + i).src = this.imageOn;
			}
			else
			{
				document.getElementById(&amp;quot;img&amp;quot; + i).src = this.imageOut;
			}
		}

		for (i = units + 1; i &amp;lt;= this.stars; i++)
		{
			document.getElementById(&amp;quot;img&amp;quot; + i).src = this.imageOff;
		}
	},

	setTimeout: function(method, period)
	{
		this.clearTimeout(method);

		var that = this;
		var args = Array.prototype.slice.call(arguments, 2) || [];

		this.__timeouts[method] = setTimeout(function()
		{
			that[method].apply(that, args);
		}, period);
	},

	clearTimeout: function(method)
	{
		if (this.__timeouts[method] &amp;gt; 0)
		{
			clearTimeout(this.__timeouts[method]);
			this.__timeouts[method] = 0;
		}
	},

	onClick: function(value)
	{
		this.value = value;
	}
}

## HTML [html]
&amp;lt;div id=&amp;quot;rater&amp;quot; class=&amp;quot;bk-form-rating rater&amp;quot;&amp;gt;
	&amp;lt;div class=&amp;quot;bk-form-inner&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div id=&amp;quot;actions&amp;quot;&amp;gt;&amp;lt;button id=&amp;quot;getVal&amp;quot; onclick=&amp;quot;alert(r.value);&amp;quot;&amp;gt;Alert Value&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;script&amp;gt;
var r = new rating('rater', 5, 0);
&amp;lt;/script&amp;gt;
&lt;/pre&gt;</content>
    <author>
      <name>richardhealy</name>
      <email>richard.healy@progressiveinternet.co.uk</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/94-curry/refactors/478" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Code94</id>
    <published>2007-10-18T09:34:59+00:00</published>
    <updated>2007-10-30T15:48:25+00:00</updated>
    <title>[JavaScript] Curry</title>
    <content type="html">&lt;p&gt;I use this little function everywhere in my javascript to deal with scope issues. Can anyone make it better?&lt;/p&gt;

&lt;pre&gt;function curry(fn, scope)
{
    var scope = scope || window;
    var args = Array.prototype.slice.call(arguments, 2) || [];

    return function()
    {
        fn.apply(scope, args);
    };
};&lt;/pre&gt;</content>
    <author>
      <name>richardhealy</name>
      <email>richard.healy@progressiveinternet.co.uk</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/94-curry" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor457</id>
    <published>2007-10-17T18:18:38+00:00</published>
    <title>[PHP] On Random password</title>
    <content type="html">&lt;p&gt;I suppose that answers that question then! lol! Interesting to know, I'm going to change my random code generator in my apps now on the back of this. Cheers Meir! :)&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>richardhealy</name>
      <email>richard.healy@progressiveinternet.co.uk</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/90-random-password/refactors/457" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor454</id>
    <published>2007-10-17T16:15:01+00:00</published>
    <title>[PHP] On Random password</title>
    <content type="html">&lt;p&gt;Not sure what the speed differences are between using Arrays vs While statements but here's something a little different. This only uses lowercase letters though.&lt;/p&gt;

&lt;pre&gt;[php]
&amp;lt;?php
function random_password($length = 6)
{
	while (strlen($key) &amp;lt; $length) $key .= rand(0,1) ? chr(rand(48, 57)) : chr(rand(97, 122));
	return $key;
}
echo random_password();
?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>richardhealy</name>
      <email>richard.healy@progressiveinternet.co.uk</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/90-random-password/refactors/454" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor431</id>
    <published>2007-10-15T14:15:03+00:00</published>
    <title>[PHP] On Copyright Year</title>
    <content type="html">&lt;p&gt;Ah! I didn't know that! Cheers for the tip!&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>richardhealy</name>
      <email>richard.healy@progressiveinternet.co.uk</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/68-copyright-year/refactors/431" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor394</id>
    <published>2007-10-12T09:15:55+00:00</published>
    <title>[JavaScript] On Beautify JS Date to how recently the event occured.</title>
    <content type="html">&lt;p&gt;Tomasz! Nice little bit of javascript there. Trying to search for some tuts on the &amp;quot;~~&amp;quot; and I'm not finding anything... Does anyone know where I can find out more about it? What does it do?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>richardhealy</name>
      <email>richard.healy@progressiveinternet.co.uk</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/37-beautify-js-date-to-how-recently-the-event-occured/refactors/394" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor386</id>
    <published>2007-10-11T23:02:03+00:00</published>
    <title>[PHP] On Copyright Year</title>
    <content type="html">&lt;p&gt;Scrap the &amp;quot;bracket&amp;quot; comment... but I still stick to &amp;quot;&amp;lt;?=&amp;quot; :)-&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>richardhealy</name>
      <email>richard.healy@progressiveinternet.co.uk</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/68-copyright-year/refactors/386" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor385</id>
    <published>2007-10-11T22:56:31+00:00</published>
    <title>[PHP] On Copyright Year</title>
    <content type="html">&lt;p&gt;I'm personally not a big fan of &amp;quot;echo&amp;quot;... &amp;quot;&amp;lt;?=&amp;quot; does the job with less brackets&lt;/p&gt;

&lt;pre&gt;## View [php]
Copyright &amp;amp;copy; 2007&amp;lt;?= intval(date('Y')) &amp;gt; 2007 ? date(' - Y') : ''; ?&amp;gt; - All Rights Reserved - Design by scott2010_h&lt;/pre&gt;</content>
    <author>
      <name>richardhealy</name>
      <email>richard.healy@progressiveinternet.co.uk</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/68-copyright-year/refactors/385" rel="alternate"/>
  </entry>
</feed>
