<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CloudSync Developer's Blog</title>
	<atom:link href="http://devblog.cloudsync.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.cloudsync.com</link>
	<description>Developing for the mobile device world</description>
	<lastBuildDate>Wed, 09 Dec 2009 16:45:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP, Dates and Daylight Savings Time</title>
		<link>http://devblog.cloudsync.com/2009/12/09/php-dates-and-daylight-savings-time/</link>
		<comments>http://devblog.cloudsync.com/2009/12/09/php-dates-and-daylight-savings-time/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 16:45:36 +0000</pubDate>
		<dc:creator>Matt Bernier</dc:creator>
				<category><![CDATA[Dates]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[amp]]></category>
		<category><![CDATA[anguish]]></category>
		<category><![CDATA[daylight savings time]]></category>
		<category><![CDATA[dst]]></category>
		<category><![CDATA[gmt]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[increment]]></category>
		<category><![CDATA[january 1]]></category>
		<category><![CDATA[loop through]]></category>
		<category><![CDATA[lt]]></category>
		<category><![CDATA[march 11]]></category>
		<category><![CDATA[minutes and seconds]]></category>
		<category><![CDATA[missing data]]></category>
		<category><![CDATA[oct 30]]></category>
		<category><![CDATA[programmer]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[programming career]]></category>
		<category><![CDATA[relative term]]></category>
		<category><![CDATA[timestamp]]></category>
		<category><![CDATA[timezones]]></category>

		<guid isPermaLink="false">http://devblog.cloudsync.com/?p=287</guid>
		<description><![CDATA[I am pretty sure that at some point in your programming career you will have to mess with dates.  This is normally not a big deal, as a date is a date is a date.  But then, you will get into more complicated date structures and algorithms involving timezones and daylight savings time.  This is [...]]]></description>
			<content:encoded><![CDATA[<p>I am pretty sure that at some point in your programming career you will have to mess with dates.  This is normally not a big deal, as a date is a date is a date.  But then, you will get into more complicated date structures and algorithms involving timezones and daylight savings time.  This is about when your hair will start to fall out and you start running around like an idiot screaming at the walls.  I know, because I was doing almost this exact thing yesterday.</p>
<h2>What happened:</h2>
<p style="padding-left: 30px;">I started with a date, made a timestamp, and then wanted to loop through all dates less than today.  I was doing some data scrubbing based on these dates.  The issue was that when I went to graph the data based on these dates, I was missing data for Oct 30 and March 11.  The more observant programmer, the person who read the title, or someone not blinded by their own code would have noticed that those are the days when we Americans celebrate Daylight savings (celebrate being a relative term).  Much like Y2K, DST causes many programmers much anguish.</p>
<p style="padding-left: 30px;">For example, if I start looping from January 1, 2006 to today, my code looked something like this:</p>
<p style="padding-left: 30px;">
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$timestamp</span> <span class="sy0">=</span> <span class="nu0">1136132724</span><span class="sy0">;</span> <span class="co1">//gmt for jan 01, 2006 + some hours</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//scrub the date to just the Year, month and day &#8211; scrub the hours, minutes and seconds off</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$date</span> <span class="sy0">=</span> <span class="kw3">date</span><span class="br0">&#40;</span><span class="st0">&#39;Y-m-d&#39;</span><span class="sy0">,</span> <span class="re1">$timestamp</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$minDate</span> <span class="sy0">=</span> <span class="kw3">strtotime</span><span class="br0">&#40;</span><span class="re1">$date</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">while</span> <span class="br0">&#40;</span><span class="re1">$minDate</span> <span class="sy0">&amp;</span>lt<span class="sy0">;</span> <span class="kw3">time</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//do some code</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//increment the date by 24hrs worth of seconds</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$minDate</span> <span class="sy0">+=</span> <span class="nu0">86400</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p style="padding-left: 30px;">By all accounts, whether this code is ugly or not, this loop will allow you to run some code for every day between the initial date and today. Except one thing, DST.</p>
<p style="padding-left: 30px;">What happens is that on the code where we do this:</p>
<p style="padding-left: 30px;">
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$date</span> <span class="sy0">=</span> <span class="kw3">date</span><span class="br0">&#40;</span><span class="st0">&#39;Y-m-d&#39;</span><span class="sy0">,</span> <span class="re1">$timestamp</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p style="padding-left: 30px;">We are essentially asking for the same thing as:</p>
<p style="padding-left: 30px;">
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$date</span> <span class="sy0">=</span> <span class="kw3">date</span><span class="br0">&#40;</span><span class="st0">&#39;Y-m-d 00:00:00&#39;</span><span class="sy0">,</span> <span class="re1">$timestamp</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p style="padding-left: 30px;">or</p>
<p style="padding-left: 30px;">
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$date</span> <span class="sy0">=</span> <span class="kw3">date</span><span class="br0">&#40;</span><span class="st0">&#39;Y-m-d&#39;</span><span class="sy0">,</span> <span class="re1">$timestamp</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&#39; 00:00:00&#39;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p style="padding-left: 30px;">Which is midnight of the day we are starting on.  Still, we should be fine, right?</p>
<p style="padding-left: 30px;">Nope.</p>
<p style="padding-left: 30px;">What happens here is that on October 29, 2006 when we add 86400 seconds, we do not get the timestamp of:</p>
<p style="padding-left: 30px;">
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="nu0">2006</span><span class="nu0">-10</span><span class="nu0">-30</span> <span class="nu0">00</span><span class="sy0">:</span><span class="nu0">00</span><span class="sy0">:</span><span class="nu0">00</span></div>
</li>
</ol>
</div>
<p style="padding-left: 30px;">we in fact get:</p>
<p style="padding-left: 30px;">
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="nu0">2006</span><span class="nu0">-10</span><span class="nu0">-29</span> <span class="nu0">23</span><span class="sy0">:</span><span class="nu0">00</span><span class="sy0">:</span><span class="nu0">00</span></div>
</li>
</ol>
</div>
<p style="padding-left: 30px;">because of DST. Fun, right!?</p>
<h2>The Solution:</h2>
<p style="padding-left: 30px;">What we can do is actually initialize the original date variable to be at noon on the initial date.  This means that whether the time goes forward in the spring to 1pm, backwards to 11am, or stays at noon we are ALWAYS talking about the same day. Whereas, 11pm, 12am and 1am are not on the same days.</p>
<p style="padding-left: 30px;">The code looks like this:</p>
<p style="padding-left: 30px;">
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$timestamp</span> <span class="sy0">=</span> <span class="nu0">1136132724</span><span class="sy0">;</span> <span class="co1">//gmt for jan 01, 2006 + some hours</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//scrub the date to just the Year, month and day &#8211; scrub the hours, minutes and seconds off</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$date</span> <span class="sy0">=</span> <span class="kw3">date</span><span class="br0">&#40;</span><span class="st0">&#39;Y-m-d&#39;</span><span class="sy0">,</span> <span class="re1">$timestamp</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$minDate</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="kw3">strtotime</span><span class="br0">&#40;</span><span class="re1">$date</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="nu0">43200</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">while</span> <span class="br0">&#40;</span><span class="re1">$minDate</span> <span class="sy0">&amp;</span>lt<span class="sy0">;</span> <span class="kw3">time</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//do some code</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//increment the date by 24hrs worth of seconds</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$minDate</span> <span class="sy0">+=</span> <span class="nu0">86400</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p style="padding-left: 30px;">Where we essentially just added 12 hours to the scrubbed date. This gives us exactly 12pm.</p>
<h2>Caveats:</h2>
<p style="padding-left: 30px;">This code sort of assumes that all of your timestamps were recorded in the same time zone. Between PHP and MySQL you can get some squirley date issues.  The best solution here is to record all timestamps in GMT and then adjust them in one place only, either as you pull them from MySQL or in the PHP. DO NOT try to adjust sometimes in one place and other times in the other, it is too easy to get confused.</p>
<p style="padding-left: 30px;">The other thing to realize is that your users may be pulling data from across the globe, which means that the timezones are way different. This also means that 12pm your time may be 12am their time, which can put you in the same predicament.  I believe it is better to run date-based system critical data in a single timezone and do not run it from random or different timezones, just in case.</p>
<p>Questions, Comments, Suggestions? Please leave them as a comment below this post!</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.cloudsync.com/2009/12/09/php-dates-and-daylight-savings-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL: Convert UNIX_TIMESTAMP to UTC DATETIME</title>
		<link>http://devblog.cloudsync.com/2009/11/17/mysql-convert-unix_timestamp-to-utc-datetime/</link>
		<comments>http://devblog.cloudsync.com/2009/11/17/mysql-convert-unix_timestamp-to-utc-datetime/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 18:07:34 +0000</pubDate>
		<dc:creator>Matt Bernier</dc:creator>
				<category><![CDATA[db]]></category>
		<category><![CDATA[CONVERT_TZ]]></category>
		<category><![CDATA[FROM_UNIXTIME]]></category>
		<category><![CDATA[global.time_zone]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL timezone]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Timezone]]></category>
		<category><![CDATA[TZ]]></category>
		<category><![CDATA[UNIX_TIMESTAMP]]></category>
		<category><![CDATA[UTC]]></category>

		<guid isPermaLink="false">http://devblog.cloudsync.com/?p=283</guid>
		<description><![CDATA[We just learned that when you insert a UNIX_TIMESTAMP into MySQL that it will keep the UTC version of the timestamp, which is good.  However, when you use FROM_UNIXTIME() to convert your Unix timestamp into a datetime string, it will localize the datetime to mysql&#8217;s timezone.
So, a couple things here:

System time and MySQL time are [...]]]></description>
			<content:encoded><![CDATA[<p>We just learned that when you insert a UNIX_TIMESTAMP into MySQL that it will keep the UTC version of the timestamp, which is good.  However, when you use FROM_UNIXTIME() to convert your Unix timestamp into a datetime string, it will localize the datetime to mysql&#8217;s timezone.</p>
<p>So, a couple things here:</p>
<ol>
<li>System time and MySQL time are not always the same</li>
<li>UTC and MySQL time are not the same</li>
<li>UNIX_TIMESTAMP() is not the same actual time as FROM_UNIXTIME(UNIX_TIMESTAMP())</li>
</ol>
<p>So, there is actually a somewhat easy solution (once you know it) to fix this issue.</p>
<p>MySQL provides a CONVERT_TZ(datetime, from, to) function.</p>
<p>Our first solution was to just get the timezone of the server and drop that into the code:</p>
<div class="geshi no mysql">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">CONVERT_TZ</span><span class="br0">&#40;</span><span class="kw2">DATETIME</span>, <span class="st0">&#39;MST&#39;</span>, <span class="st0">&#39;+00:00&#39;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>This does not work if we do and install on a server not running on MST.  So, the better solution is:</p>
<div class="geshi no mysql">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">CONVERT_TZ</span><span class="br0">&#40;</span><span class="kw2">DATETIME</span>, @@global.time_zone, <span class="st0">&#39;+00:00&#39;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>The variable &#8220;@@global.time_zone&#8221; is a MySQL system variable which will return the timezone MySQL is running on.  With this, we have now just converted ALL of our datetimes to UTC time, and then we can adjust them to our users as we wish.</p>
<p>If you wanted to pass the user&#8217;s timezone into the function, you would just need to know the UTC offset and replace &#8216;+00:00&#8242; with that offset.</p>
<p>I.E. MST would be &#8220;-07:00&#8243;</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.cloudsync.com/2009/11/17/mysql-convert-unix_timestamp-to-utc-datetime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Public/Private Keys for SSH Authentication</title>
		<link>http://devblog.cloudsync.com/2009/10/26/publicprivate-keys-for-ssh-authentication/</link>
		<comments>http://devblog.cloudsync.com/2009/10/26/publicprivate-keys-for-ssh-authentication/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 21:00:41 +0000</pubDate>
		<dc:creator>Matt Bernier</dc:creator>
				<category><![CDATA[Server Stuff]]></category>
		<category><![CDATA[devices]]></category>
		<category><![CDATA[alias]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash shell]]></category>
		<category><![CDATA[computer server]]></category>
		<category><![CDATA[current version]]></category>
		<category><![CDATA[definitions]]></category>
		<category><![CDATA[directory cd]]></category>
		<category><![CDATA[keygen]]></category>
		<category><![CDATA[little bit]]></category>
		<category><![CDATA[profile server]]></category>
		<category><![CDATA[root directory]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[server server]]></category>
		<category><![CDATA[server type]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[ssh client]]></category>

		<guid isPermaLink="false">http://devblog.cloudsync.com/?p=277</guid>
		<description><![CDATA[Most of this information comes from here: HowTos/Network/Securing SSH I have taken the liberty to cut out the extra stuff, and reorganize the information a little bit.
Definitions:
Client &#8211; The computer you use to connect to the server
Server &#8211; The computer/server you are connecting to via SSH
Client Steps:
Get to your user directory by typing:



$ cd ~/



Once [...]]]></description>
			<content:encoded><![CDATA[<p>Most of this information comes from here: <a href="http://wiki.centos.org/HowTos/Network/SecuringSSH">HowTos/Network/Securing SSH</a> I have taken the liberty to cut out the extra stuff, and reorganize the information a little bit.</p>
<h2>Definitions:</h2>
<p style="padding-left: 30px;">Client &#8211; The computer you use to connect to the server</p>
<p style="padding-left: 30px;">Server &#8211; The computer/server you are connecting to via SSH</p>
<h2>Client Steps:</h2>
<p>Get to your user directory by typing:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">$ <span class="kw3">cd</span> ~<span class="sy0">/</span></div>
</li>
</ol>
</div>
<p>Once you are there, verify that you do not already have an &#8220;.ssh&#8221; directory, if you do not create it by typing:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">$ <span class="kw2">mkdir</span> .<span class="kw2">ssh</span></div>
</li>
</ol>
</div>
<p>Now you want to set up the key you will use to authenticate yourself to the server, type:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">$ <span class="kw2">ssh-keygen</span> -t rsa</div>
</li>
</ol>
</div>
<p>When this is running, it will ask you for a passphrase, and other settings.  You should be able to just hit the enter key through the prompts.  This way you do not have to enter a password at all when you run the alias you will set up (this will be explained in a minute).<br />
Once finished running, this last command will create two files, id_rsa and id_rsa.pub in your .ssh directory.  These files identify you to the server.<br />
At this point, you need to tell the server who you are by adding yourself to the servers &#8216;Authenticated users&#8217; list.  You do this by copying your id_rsa.pub file to the server.</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">$ <span class="kw2">scp</span> .<span class="kw2">ssh</span><span class="sy0">/</span>id_rsa.pub user<span class="sy0">@</span>server.com:<span class="sy0">/</span>user<span class="sy0">/</span></div>
</li>
</ol>
</div>
<p>Note: Be sure to replace the words &#8220;user&#8221; and &#8220;server&#8221; appropriately in the command above.</p>
<p>Open your .profile (or .bash_profile) file for editing:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">$ <span class="kw2">nano</span> .profile</div>
</li>
</ol>
</div>
<p>Add the following to your .profile file or .bash_profile file to have an alias for your server:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">alias</span> <span class="re2">servername=</span><span class="st0">&quot;ssh user@server.com&quot;</span></div>
</li>
</ol>
</div>
<p>Note: replace the words to match your server/user</p>
<p>Make sure your current bash shell has the current version of your profile file (replace with correct file):</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">$ <span class="kw3">source</span> .profile</div>
</li>
</ol>
</div>
<h2>Server Steps:</h2>
<p>Once you have SSHed into your server the old fashioned way, you will need to add yourself to the authenticated users list.<br />
Make sure you are in the user&#8217;s root directory:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">$ <span class="kw2">cat</span> id_rsa.pub <span class="sy0">&gt;&gt;</span> .<span class="kw2">ssh</span><span class="sy0">/</span>authorized_keys</div>
</li>
</ol>
</div>
<p>Make sure you have a .ssh folder, if not create it (see above).<br />
Now, add the content of the id_rsa.pub file to the authenticated_keys file in .ssh.  If the file exists, this command will concatenate the content of id_rsa.pub to the file.  If the file does not exist yet, it will after you run this command:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">$ <span class="kw2">chmod</span> <span class="nu0">700</span> .<span class="kw2">ssh</span></div>
</li>
<li class="li1">
<div class="de1">$ <span class="kw2">chmod</span> <span class="nu0">600</span> .<span class="kw2">ssh</span><span class="sy0">/</span>authenticated_keys</div>
</li>
</ol>
</div>
<p>Once you have concatenated the data, you are almost ready to go.  Just make sure the files have the correct permissions:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">$ <span class="kw3">exit</span></div>
</li>
</ol>
</div>
<p>Now, exit out of your ssh session:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">$ servername</div>
</li>
</ol>
</div>
<h2>Test your Authentication:</h2>
<p> To test, just type the name of the alias you set up, should be where you replaced the word &#8220;servername&#8221; in the alias definition you created earlier:</p>
<div class="geshi no ">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>This should send you straight through to the server. Voila!</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.cloudsync.com/2009/10/26/publicprivate-keys-for-ssh-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Does PHP pass objects by reference?</title>
		<link>http://devblog.cloudsync.com/2009/09/17/does-php-pass-objects-by-reference/</link>
		<comments>http://devblog.cloudsync.com/2009/09/17/does-php-pass-objects-by-reference/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 16:49:43 +0000</pubDate>
		<dc:creator>Matt Bernier</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[c string]]></category>
		<category><![CDATA[data index]]></category>
		<category><![CDATA[data return]]></category>
		<category><![CDATA[gt 5]]></category>
		<category><![CDATA[pass by reference]]></category>
		<category><![CDATA[PHP5]]></category>
		<category><![CDATA[reciprocal code]]></category>
		<category><![CDATA[reference]]></category>

		<guid isPermaLink="false">http://devblog.cloudsync.com/?p=271</guid>
		<description><![CDATA[I needed to know if PHP passes objects by reference, because I wanted to create some reciprocal code that would be REALLY messy if it did not.
The steps:

Instantiate both objects
Add the second ($two) object to the first ($one)
Modify the second object outside of $one after adding it
Add data to $two from inside $one
Render the objects [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to know if PHP passes objects by reference, because I wanted to create some reciprocal code that would be REALLY messy if it did not.</p>
<p>The steps:</p>
<ol>
<li>Instantiate both objects</li>
<li>Add the second ($two) object to the first ($one)</li>
<li>Modify the second object outside of $one after adding it</li>
<li>Add data to $two from inside $one</li>
<li>Render the objects and see if the data that was added to $two outside of $onw was added to the $two stored in $one (confused?)</li>
<li>Also, check that the data added to $two from inside of $one was set on $two</li>
</ol>
<p>If objects are being passed by reference, then any change you make on $two whether inside the $one object or on the original $two object will be refleced when you output the individual objects separately. (i.e. they will output exactly the same)</p>
<p>If the objects are copied and therefore not passed by reference, then you will see that the output of the individual objects is completely different.</p>
<p>Here is the code:</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> one</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;protected <span class="re1">$dataObj</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">public</span> <span class="kw2">function</span> addData<span class="br0">&#40;</span><span class="re1">$data</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="re1">$this</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>dataObj <span class="sy0">=</span> <span class="re1">$data</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">public</span> <span class="kw2">function</span> __toString<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="re1">$this</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>dataObj<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>addData<span class="br0">&#40;</span><span class="st0">&#39;c&#39;</span><span class="sy0">,</span> <span class="st0">&#39;what!?&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw3">ob_start</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw3">echo</span> <span class="re1">$this</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>dataObj<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw3">ob_get_clean</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> two</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;protected <span class="re1">$data</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st0">&#39;a&#39;</span> <span class="sy0">=&amp;</span>gt<span class="sy0">;</span> <span class="nu0">5</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">public</span> <span class="kw2">function</span> addData<span class="br0">&#40;</span><span class="re1">$index</span><span class="sy0">,</span> <span class="re1">$val</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="re1">$this</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>data<span class="br0">&#91;</span><span class="re1">$index</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re1">$val</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">public</span> <span class="kw2">function</span> __toString<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw3">ob_start</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw3">var_dump</span><span class="br0">&#40;</span><span class="re1">$this</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>data<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw3">ob_get_clean</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$one</span> <span class="sy0">=</span> <span class="kw2">new</span> one<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$two</span> <span class="sy0">=</span> <span class="kw2">new</span> two<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$one</span><span class="sy0">-&gt;</span><span class="me1">addData</span><span class="br0">&#40;</span><span class="re1">$two</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$two</span><span class="sy0">-&gt;</span><span class="me1">addData</span><span class="br0">&#40;</span><span class="st0">&#39;b&#39;</span><span class="sy0">,</span> <span class="st0">&#39;howdy&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="re1">$one</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="re1">$two</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>So&#8230;what was the result?  </p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">array
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#39;a&#39; =&gt; int 5
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#39;b&#39; =&gt; string &#39;howdy&#39; (length=5)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#39;c&#39; =&gt; string &#39;what!?&#39; (length=6)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">array
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#39;a&#39; =&gt; int 5
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#39;b&#39; =&gt; string &#39;howdy&#39; (length=5)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#39;c&#39; =&gt; string &#39;what!?&#39; (length=6)</div>
</li>
</ol>
</div>
<p>They were exactly the same, which means that PHP passed the $two object by reference to $one. This is a cool feature because it means you can do some really cool things with objects and allows you to be defensive with your programming if someone does something out of order.  There are some potential issues if your developers think that they are NOT passed by reference and that they are modifying a different $two than the one in the object.  Good comments should fix that.</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.cloudsync.com/2009/09/17/does-php-pass-objects-by-reference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net Compact Framework &#8211; Sets the locale for you</title>
		<link>http://devblog.cloudsync.com/2009/08/10/net-compact-framework-sets-the-locale-for-you/</link>
		<comments>http://devblog.cloudsync.com/2009/08/10/net-compact-framework-sets-the-locale-for-you/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 16:40:10 +0000</pubDate>
		<dc:creator>Matt Bernier</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[date time]]></category>
		<category><![CDATA[dd hh]]></category>
		<category><![CDATA[decimals]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[hh mm ss]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[string output]]></category>
		<category><![CDATA[yyyy]]></category>

		<guid isPermaLink="false">http://devblog.cloudsync.com/?p=265</guid>
		<description><![CDATA[When you are developing in the .Net Compact Framework and try to output things like date, time, or any numbers you should take care to pay attention to the device&#8217;s locale.  The reason is that in some countries they use &#8220;.&#8221; for decimals and in others they use &#8220;,&#8221;.  There are other differences too, like [...]]]></description>
			<content:encoded><![CDATA[<p>When you are developing in the .Net Compact Framework and try to output things like date, time, or any numbers you should take care to pay attention to the device&#8217;s locale.  The reason is that in some countries they use &#8220;.&#8221; for decimals and in others they use &#8220;,&#8221;.  There are other differences too, like <a href="http://en.wikipedia.org/wiki/Calendar_date">how dates are formatted</a> internationally.</p>
<p>The solution here, if you need to ALWAYS output data in your specific format, is to pass in an &#8220;Invariant Culture&#8221; to the string output like so:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="sy0">*</span>Time.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="st0">&quot;yyyy-MM-dd HH:mm:ss&quot;</span>, CultureInfo.<span class="me1">InvariantCulture</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>(where *Time is your time variable)</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.cloudsync.com/2009/08/10/net-compact-framework-sets-the-locale-for-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slashes issues</title>
		<link>http://devblog.cloudsync.com/2009/08/05/slashes-issues/</link>
		<comments>http://devblog.cloudsync.com/2009/08/05/slashes-issues/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 17:14:31 +0000</pubDate>
		<dc:creator>Matt Bernier</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[better solution]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[false path]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[ftp file]]></category>
		<category><![CDATA[functionality]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[path]]></category>
		<category><![CDATA[path check]]></category>
		<category><![CDATA[php developer]]></category>
		<category><![CDATA[prefix]]></category>
		<category><![CDATA[return path]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[slashes]]></category>
		<category><![CDATA[stripdouble backslash]]></category>
		<category><![CDATA[time magic]]></category>

		<guid isPermaLink="false">http://devblog.cloudsync.com/?p=260</guid>
		<description><![CDATA[I think that at some point, every PHP developer comes head to head with 2 issues, and probably at the same time.

magic_quotes_gpc
different servers having different setups

My solution for this was to use stripslashes() on a file path, example:



//with magic_quotes_gpc on $path looks like: &#34;mydomain.com//path//to//file&#34;


$path = stripslashes&#40;$path&#41;;


//now it looks like: &#34;mydomain.com/path/to/file&#34;



This is great, if your file [...]]]></description>
			<content:encoded><![CDATA[<p>I think that at some point, every PHP developer comes head to head with 2 issues, and probably at the same time.</p>
<ol>
<li>magic_quotes_gpc</li>
<li>different servers having different setups</li>
</ol>
<p>My solution for this was to use stripslashes() on a file path, example:</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="co1">//with magic_quotes_gpc on $path looks like: &quot;mydomain.com//path//to//file&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$path</span> <span class="sy0">=</span> <span class="kw3">stripslashes</span><span class="br0">&#40;</span><span class="re1">$path</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//now it looks like: &quot;mydomain.com/path/to/file&quot;</span></div>
</li>
</ol>
</div>
<p>This is great, <strong>if</strong> your file paths look like that, and you know that magic quotes is on.  BUT, if you move your code to a server where it is not on, or you run stripslashes on a path that is already clean, you end up with this:</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="co1">//clean $path looks like: &quot;mydomain.com/path/to/file&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$path</span> <span class="sy0">=</span> <span class="kw3">stripslashes</span><span class="br0">&#40;</span><span class="re1">$path</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//now it looks like: &quot;mydomain.compathtofile&quot; &lt;- that does not look right!</span></div>
</li>
</ol>
</div>
<p>So, the better solution to stripslashes() is something like this:</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> cleanFilePath<span class="br0">&#40;</span><span class="re1">$path</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span> </div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//check if magic_quotes_gpc is on or 1</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw3">ini_get</span><span class="br0">&#40;</span><span class="st0">&#39;magic_quotes_gpc&#39;</span><span class="br0">&#41;</span> <span class="sy0">==</span> <span class="st0">&#39;1&#39;</span> <span class="sy0">||</span> <span class="kw3">strtolower</span><span class="br0">&#40;</span><span class="kw3">ini_get</span><span class="br0">&#40;</span><span class="st0">&#39;magic_quotes_gpc&#39;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">==</span> <span class="st0">&#39;on&#39;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="co1">//if you see a double backslash, replace it with a single</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$file</span><span class="sy0">,</span> <span class="st0">&#39;<span class="es0">\\</span><span class="es0">\\</span>&#39;</span><span class="br0">&#41;</span> <span class="sy0">!==</span> <span class="kw2">false</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$path</span> <span class="sy0">=</span> <span class="kw3">str_replace</span><span class="br0">&#40;</span><span class="st0">&#39;<span class="es0">\\</span><span class="es0">\\</span>&#39;</span><span class="sy0">,</span> <span class="st0">&#39;<span class="es0">\\</span>&#39;</span><span class="sy0">,</span> <span class="re1">$path</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">//if you see a double forward slash, replace it with a single</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$file</span><span class="sy0">,</span> <span class="st0">&#39;//&#39;</span><span class="br0">&#41;</span> <span class="sy0">!==</span> <span class="kw2">false</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re1">$path</span> <span class="sy0">=</span> <span class="kw3">str_replace</span><span class="br0">&#40;</span><span class="st0">&#39;//&#39;</span><span class="sy0">,</span> <span class="st0">&#39;/&#39;</span><span class="sy0">,</span> <span class="re1">$path</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="re1">$path</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Now, there is one more thing. If your paths have &#8220;http://&#8221;, &#8220;ftp://&#8221;, &#8220;file://&#8221; or any other prefix, you will need to take these off of the string and make a note of what it was, then clean the path and put the prefix back on.  Otherwise, the &#8220;//&#8221; on the prefix will be removed by the script and your path won&#8217;t work.</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.cloudsync.com/2009/08/05/slashes-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Steal an inline onclick event from one element to another</title>
		<link>http://devblog.cloudsync.com/2009/03/26/steal-an-inline-onclick-event-from-one-element-to-another/</link>
		<comments>http://devblog.cloudsync.com/2009/03/26/steal-an-inline-onclick-event-from-one-element-to-another/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 19:52:21 +0000</pubDate>
		<dc:creator>Matt Bernier</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[copy paste]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[functionality]]></category>
		<category><![CDATA[getelementsbytagname]]></category>
		<category><![CDATA[h1]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[onclick event]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[s]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[suggestion]]></category>

		<guid isPermaLink="false">http://devblog.cloudsync.com/?p=252</guid>
		<description><![CDATA[Sometimes, someone writes a piece of HTML with inline JS (naughty naughty).  And sometimes, you need to use that same functionality elsewhere in your document, but it is named dynamically so you can&#8217;t just copy/paste.
Here comes Prototype to the rescue.
You can do this:



var oldItem = &#39;oldItem&#39;;


var itemToGetEvent = &#39;newItem&#39;;


var temp = $&#40;itemToGetEvent&#41;.observe&#40;&#39;click&#39;, function&#40;&#41;&#123;


&#160; &#160;eval&#40;$&#40;&#39;oldItem&#39;&#41;.readAttribute&#40;&#39;onclick&#39;&#41;&#41;;


&#125;&#41;;



olditem [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, someone writes a piece of HTML with inline JS (naughty naughty).  And sometimes, you need to use that same functionality elsewhere in your document, but it is named dynamically so you can&#8217;t just copy/paste.</p>
<p>Here comes Prototype to the rescue.</p>
<p>You can do this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> oldItem = <span class="st0">&#39;oldItem&#39;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> itemToGetEvent = <span class="st0">&#39;newItem&#39;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> temp = $<span class="br0">&#40;</span>itemToGetEvent<span class="br0">&#41;</span>.<span class="me1">observe</span><span class="br0">&#40;</span><span class="st0">&#39;click&#39;</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">eval</span><span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="st0">&#39;oldItem&#39;</span><span class="br0">&#41;</span>.<span class="me1">readAttribute</span><span class="br0">&#40;</span><span class="st0">&#39;onclick&#39;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>olditem is the item that has the onclick attribute inline<br />
newitem is the item that needs to get this onclick attribute</p>
<p>I am just copying the code and then setting a listener on the new item so that it mimics the onclick attribute of the other item.  </p>
<p>Another Suggestion:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;h1 onclick=&quot;this.innerHTML=&#39;foobar&#39;;&quot;&gt;clickme&lt;/h1&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;h1&gt;clickme2&lt;/h1&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;script&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;var h = document.getElementsByTagName(&#39;h1&#39;);
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;h[1].onclick = function(ev) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;h[0].onclick.call(this, ev);
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;}
</div>
</li>
<li class="li1">
<div class="de1">&lt;/script&gt;</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://devblog.cloudsync.com/2009/03/26/steal-an-inline-onclick-event-from-one-element-to-another/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Keep Prototype&#8217;s periodical executor from running forever</title>
		<link>http://devblog.cloudsync.com/2009/03/12/keep-prototypes-periodical-executor-from-running-forever/</link>
		<comments>http://devblog.cloudsync.com/2009/03/12/keep-prototypes-periodical-executor-from-running-forever/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 18:32:57 +0000</pubDate>
		<dc:creator>Matt Bernier</dc:creator>
				<category><![CDATA[js]]></category>
		<category><![CDATA[bonus]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[executor]]></category>
		<category><![CDATA[firstname]]></category>
		<category><![CDATA[increment]]></category>
		<category><![CDATA[iterations]]></category>
		<category><![CDATA[periodical]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[s]]></category>

		<guid isPermaLink="false">http://devblog.cloudsync.com/?p=247</guid>
		<description><![CDATA[Every once in a while, it is nice to use PeriodicalExecutor from Prototype.js, becuase you just don&#8217;t know when something will happen, or when something will be in the DOM.  Maybe you are the master at JS timing, but I&#8217;m not so here is what I do.
When I know that there is a possibility that [...]]]></description>
			<content:encoded><![CDATA[<p>Every once in a while, it is nice to use PeriodicalExecutor from Prototype.js, becuase you just don&#8217;t know when something will happen, or when something will be in the DOM.  Maybe you are the master at JS timing, but I&#8217;m not so here is what I do.</p>
<p>When I know that there is a possibility that a DOM element, say id=&#8221;firstName&#8221;, will be in the DOM soon or might never be in the DOM.  I will call PeriodicalExecutor and then put in a counter.  Like so:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> tempPeCounter = <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">new</span> PeriodicalExecuter<span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>pe<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>tempPeCounter == <span class="nu0">50</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; pe.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="st0">&#39;firstName&#39;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; pe.<span class="kw3">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;$<span class="br0">&#40;</span><span class="st0">&#39;firstName&#39;</span><span class="br0">&#41;</span>.<span class="kw3">focus</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; tempPeCounter++;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>, .<span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>What will happen is, if the element shows up in the first 50 iterations (here it would be in the first 5 seconds), it will get focus. Otherwise, the counter will increment away until it stops the PeriodicalExecutor.  This is a nice way to make sure that your JS doesn&#8217;t eat up too many resources and to guarantee that your PeriodicalExecutor stops at some point.</p>
<p>Note/Bonus: I have no idea why a field or Element called &#8220;firstName&#8221; would not be in the DOM.  I guess, if I was going to use &#8220;firstName&#8221; it would probably always be there, but this is hypothetical, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.cloudsync.com/2009/03/12/keep-prototypes-periodical-executor-from-running-forever/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Government Time Servers down, a sign of bad times?</title>
		<link>http://devblog.cloudsync.com/2009/03/09/government-time-servers-down-a-sign-of-bad-times/</link>
		<comments>http://devblog.cloudsync.com/2009/03/09/government-time-servers-down-a-sign-of-bad-times/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 22:12:06 +0000</pubDate>
		<dc:creator>Matt Bernier</dc:creator>
				<category><![CDATA[Server Stuff]]></category>
		<category><![CDATA[devices]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[web traffic]]></category>
		<category><![CDATA[choose one]]></category>
		<category><![CDATA[government time]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[time servers]]></category>

		<guid isPermaLink="false">http://devblog.cloudsync.com/?p=243</guid>
		<description><![CDATA[If you have an electronics device whose time is all jacked and it normally updates all on its own, then you are probably using one of the government time servers.  Now, the fun part!
A bunch of them are completely overloaded. (see picture)

If you choose one of the other lesser known servers your time will update [...]]]></description>
			<content:encoded><![CDATA[<p>If you have an electronics device whose time is all jacked and it normally updates all on its own, then you are probably using one of the government time servers.  Now, the fun part!</p>
<p>A bunch of them are completely overloaded. (see picture)</p>
<p><a href="http://devblog.cloudsync.com/wp-content/uploads/2009/03/nist-internet-time-service-clock.jpg"><img class="alignnone size-medium wp-image-244" title="nist-internet-time-service-clock" src="http://devblog.cloudsync.com/wp-content/uploads/2009/03/nist-internet-time-service-clock-300x149.jpg" alt="nist-internet-time-service-clock" width="300" height="149" /></a></p>
<p>If you choose one of the other lesser known servers your time will update automagically and you won&#8217;t be missing all of your meetings.</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.cloudsync.com/2009/03/09/government-time-servers-down-a-sign-of-bad-times/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows mobile not updating time after daylight savings DST update</title>
		<link>http://devblog.cloudsync.com/2009/03/09/windows-mobile-not-updating-time-after-daylight-savings-dst-update/</link>
		<comments>http://devblog.cloudsync.com/2009/03/09/windows-mobile-not-updating-time-after-daylight-savings-dst-update/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 19:35:10 +0000</pubDate>
		<dc:creator>Dustin Swint</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://devblog.cloudsync.com/?p=240</guid>
		<description><![CDATA[Updating Windows Mobile phones for Daylight Saving Time
If you are having issues with you windows mobile device and Pocket PC and the daylight savings(DST) change then you probably need to follow the Micorsoft update procedure here:
http://www.microsoft.com/windowsmobile/en-us/downloads/microsoft/daylight-savings-update.mspx
or you can download the CAB file here:
Update for Windows Mobile (KB949168)
]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color: #3366ff;">Updating Windows Mobile phones for Daylight Saving Time</span></strong></p>
<p><span style="color: #000000;">If you are having issues with you windows mobile device and Pocket PC and the daylight savings(DST) change then you probably need to follow the </span>Micorsoft update procedure here:</p>
<p><strong><span style="color: #3366ff;"><a href="http://www.microsoft.com/windowsmobile/en-us/downloads/microsoft/daylight-savings-update.mspx" target="_blank">http://www.microsoft.com/windowsmobile/en-us/downloads/microsoft/daylight-savings-update.mspx</a></span></strong></p>
<p>or you can download the CAB file here:</p>
<p><a href="Update for Windows Mobile (KB949168)" target="_blank"><span style="color: #3366ff;"><strong>Update for Windows Mobile (KB949168)</strong></span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.cloudsync.com/2009/03/09/windows-mobile-not-updating-time-after-daylight-savings-dst-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
