<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><!-- generator="wordpress/2.3.1" --><rss 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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" version="2.0">

<channel>
	<title>The Montoya Herald</title>
	<link>http://www.christianmontoya.com</link>
	<description>Web Design, Technology, and New Media</description>
	<pubDate>Thu, 26 Jun 2008 10:32:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
	<language>en</language>
			<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by-nc-nd/2.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/christianmontoya" type="application/rss+xml" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">386584</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://www.feedburner.com</feedburner:feedburnerHostname><item>
		<title>Principles</title>
		<link>http://www.christianmontoya.com/2008/06/26/principles/</link>
		<comments>http://www.christianmontoya.com/2008/06/26/principles/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 10:32:17 +0000</pubDate>
		<dc:creator>Christian Montoya</dc:creator>
		
		<category><![CDATA[Asides]]></category>

		<guid isPermaLink="false">http://www.christianmontoya.com/2008/06/26/principles/</guid>
		<description><![CDATA[I&#8217;m not going to F8 unless my boss decides to pay for me.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not going to <a href="http://www.facebook.com/developers/f8_register.php">F8</a> unless my boss decides to pay for me.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/christianmontoya?a=11jlPi"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=11jlPi" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=MALjui"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=MALjui" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=EGoliI"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=EGoliI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/christianmontoya/~4/320421821" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.christianmontoya.com/2008/06/26/principles/feed/</wfw:commentRss>
		<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetItemData?uri=christianmontoya&amp;itemurl=http%3A%2F%2Fwww.christianmontoya.com%2F2008%2F06%2F26%2Fprinciples%2F</feedburner:awareness></item>
		<item>
		<title>Scraping Wikipedia for whatever I need</title>
		<link>http://www.christianmontoya.com/2008/06/25/scraping-wikipedia-for-whatever-i-need/</link>
		<comments>http://www.christianmontoya.com/2008/06/25/scraping-wikipedia-for-whatever-i-need/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 07:43:49 +0000</pubDate>
		<dc:creator>Christian Montoya</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.christianmontoya.com/2008/06/25/scraping-wikipedia-for-whatever-i-need/</guid>
		<description><![CDATA[If there's something on Wikipedia, I can get it into my database, easily :)]]></description>
			<content:encoded><![CDATA[<p>Sunday I was working on a project for which I need a complete list of games for the Nintendo Wii. The best way I know how to do this is as follows:</p>

<ul>
<li>Find a web page that has a complete list of games: <a href="http://en.wikipedia.org/wiki/List_of_wii_games">http://en.wikipedia.org/wiki/List_of_wii_games</a> (Wikipedia has a lot of pages like this).</li>
<li>Use Perl regular expression matching in PHP to scrape this list from the page and insert into my database. </li>
<li>Done. </li>
</ul>

<p>Let me dive a bit deeper. All the names on this web page are marked with the same HTML pattern:</p>

<div class='photo'><a href="http://www.flickr.com/photos/thephotoherald/2609335209/" title="wiki_wii_scrape by montoya.christian, on Flickr"><img src="http://farm4.static.flickr.com/3109/2609335209_2d99105954_o.jpg" width="546" height="200" alt="wiki_wii_scrape" /></a></div>

<p>It&#8217;s <code>&amp;lt;i&amp;gt;&amp;lt;a href=&quot;[some link]&quot; title=&quot;[THE NAME]&quot;</code>. With a bit of knowledge about regular expressions, and after I have used <code>htmlentities()</code> to encode the markup, the expression I need is:</p>

<p><code>preg_match_all("/&amp;lt;i&amp;gt;&amp;lt;a href=(.+?)title=(\")(.+?)(\"| \()/", $r, $matches);</code></p>

<p>What this does is capture all occurrences of the regular expression I&#8217;ve used in the string <code>$r</code>, and place those in the array <code>$matches</code>. Furthermore, each <code>(...)</code> has its own set of matches, so that the <code>$matches</code> variable is actually an array of arrays. So, the names of these Wii games that I am looking for are all in <code>$matches[3]</code>. All I have to do is iterate through that array and put each name in my database.</p>

<p><em>But wait, there&#8217;s more&#8230;</em></p>

<p>Something I should explain further: The most important part of my regular expression match is this: <code>title=(\")(.+?)(\"| \()</code>. I&#8217;m grabbing the content of the title attribute because the actual text sometimes contains more than just the game&#8217;s name, but sometimes the title also contains something in parentheses, which is a Wikipedia disambiguation. So, there are two things that might come after the title attribute: a quotation mark, or a space &amp; open-paren. With the pipe, I capture both, and I always get nothing more than the name of each game, without even having to <code>trim()</code>.</p>

<p>Scraping is fun, eh?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/christianmontoya?a=y6p49i"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=y6p49i" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=2wwKni"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=2wwKni" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=mou3jI"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=mou3jI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/christianmontoya/~4/319509827" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.christianmontoya.com/2008/06/25/scraping-wikipedia-for-whatever-i-need/feed/</wfw:commentRss>
		<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetItemData?uri=christianmontoya&amp;itemurl=http%3A%2F%2Fwww.christianmontoya.com%2F2008%2F06%2F25%2Fscraping-wikipedia-for-whatever-i-need%2F</feedburner:awareness></item>
		<item>
		<title>The Ebay Problem</title>
		<link>http://www.christianmontoya.com/2008/06/19/the-ebay-problem/</link>
		<comments>http://www.christianmontoya.com/2008/06/19/the-ebay-problem/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 06:10:20 +0000</pubDate>
		<dc:creator>Christian Montoya</dc:creator>
		
		<category><![CDATA[Business]]></category>

		<guid isPermaLink="false">http://www.christianmontoya.com/2008/06/19/the-ebay-problem/</guid>
		<description><![CDATA[Scalpers are making it impossible for the average person to get popular products at retail price, and Ebay is where it all happens.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to buy a Wii Fit for the past month. I&#8217;m on a very serious weight loss plan that involves heavy dieting and exercise, and I would like to incorporate Wii Fit into my workout routine. I already have a Wii, and lately I&#8217;ve been using Wii Sports, aside from doing my usual combination of crunches, push-ups, and jogging. Unfortunately, Wii Fit is always sold out. I know because I&#8217;ve been watching the <a href="http://wiitracker.com/wiifit/">Wii Fit tracker</a>. Each day, for about 10 minutes, some online store will suddenly have the Wii Fit in stock, and then it will be gone again. It happens so fast because there are tons of scalpers out there watching those sites more fervently than me, and as soon as any stock becomes available, they snatch them up to resell them on Ebay. Here&#8217;s a screenshot from the latest auctions there, all due to end in 7 or 8 hours:</p>

<div class='photo'><a href="http://www.flickr.com/photos/thephotoherald/2591483007/" title="wii-fit-on-ebay-june-2008 by montoya.christian, on Flickr"><img src="http://farm4.static.flickr.com/3264/2591483007_e9cbc58531_o.jpg" width="545" height="400" alt="wii-fit-on-ebay-june-2008" /></a></div>

<p>Wii Fit, which goes for a retail price of $90, is reaching prices of $132 hours before the auctions even close. To make things worse, these prices indicate that <strong>people are actually offering to pay this much more</strong> for something that retailed at $90. Clearly, the Ebay problem is a scalping problem. Ebay was always meant as a way for people to resell things rather than just throwing them away. For the buyer, Ebay ought to be a place where you can find <em>deals</em> as well as products that aren&#8217;t sold in stores. I really wish it wasn&#8217;t the prime place for scalping.</p>

<p>Unfortunately, you can&#8217;t blame Ebay for allowing this practice. They are simply providing a service, and allowing users the freedom to take advantage of that service as they please. The real responsibility is on the buyers; people should refuse to pay any more than $90 for Wii Fit, ever. If people did that, no one would try buying them just to resell them, and it would be much easier for a guy like me to buy a Wii Fit at retail price direct from a store.</p>

<p>Maybe I&#8217;m just dreaming. It&#8217;s hard to get everyone to think in the interest of others. I&#8217;m just writing this to make the statement that I refuse to pay more than $90 for the Wii Fit I&#8217;ll eventually have. In the meantime, I&#8217;ll stick to jogging and whatever else I can do to lose weight.</p>

<p><small>Note: I have no qualms with paying <em>less</em> than $90 for Wii Fit, ha ha</small></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/christianmontoya?a=Riixzi"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=Riixzi" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=SrRtoi"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=SrRtoi" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=n9NV7I"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=n9NV7I" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/christianmontoya/~4/315193618" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.christianmontoya.com/2008/06/19/the-ebay-problem/feed/</wfw:commentRss>
		<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetItemData?uri=christianmontoya&amp;itemurl=http%3A%2F%2Fwww.christianmontoya.com%2F2008%2F06%2F19%2Fthe-ebay-problem%2F</feedburner:awareness></item>
		<item>
		<title>Crowdherding</title>
		<link>http://www.christianmontoya.com/2008/06/09/crowdherding/</link>
		<comments>http://www.christianmontoya.com/2008/06/09/crowdherding/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 02:46:16 +0000</pubDate>
		<dc:creator>Christian Montoya</dc:creator>
		
		<category><![CDATA[Business]]></category>

		<guid isPermaLink="false">http://www.christianmontoya.com/2008/06/09/crowdherding/</guid>
		<description><![CDATA[It's like Crowdsourcing, but much more common]]></description>
			<content:encoded><![CDATA[<p>I hold the following to be an absolute truth:</p>

<p>If I gave you a bucket and told you to sit on a beach and count grains of sand, one by one, all day long, you would do it. You would do it because it&#8217;s fun. You might insist that I&#8217;m wrong, but I know I&#8217;m right because millions of people do this every day. Not only are people willing to do this, but many businesses and entrepreneurs are driving their revenue models on making people count sand. It&#8217;s happening so much that I needed to coin a term to describe it, especially since I would like an easy way to describe to people what I do for a living. I came up with &#8220;Crowdherding.&#8221;</p>

<div class='photo'><img src='http://www.christianmontoya.com/wp-content/uploads/2008/06/dumb_kid_sand.jpg' alt='I needed a picture of a dumb kid with a bucket and sand. Thanks FunExpress.com!' title='I needed a picture of a dumb kid with a bucket and sand. Thanks FunExpress.com!' /></div>

<p>Crowdherding is a lot like Crowdsourcing, which Wikipedia, in its infinite wisdom, describes as:</p>

<blockquote>&#8220;a neologism for the act of taking a task traditionally performed by an employee or contractor, and outsourcing it to an undefined, generally large group of people, in the form of an open call. For example, the public may be invited to develop a new technology, carry out a design task, refine an algorithm or help capture, systematize or analyze large amounts of data&#8221;</blockquote>

<p>Wikipedia&#8217;s wisdom doesn&#8217;t stop there. It also says:</p>

<blockquote>&#8220;The term has become popular with business authors and journalists as shorthand for the trend of leveraging the mass collaboration enabled by Web 2.0 technologies to achieve business goals. However, both the term and its underlying business models have attracted controversy and criticism.&#8221;</blockquote>

<p>I think this is simple enough. Crowdsourcing is cool when you think about all the ways in which it takes place:</p>

<ul>
<li><a href="http://en.wikipedia.org/">Wikipedia</a> never has to buy any content. All the information within is generated by users, and the system works in such a way so as to ensure a manageable level of accuracy. </li>
<li><a href="http://www.kongregate.com/">Kongregate</a>&#8217;s library of games is made up of Flash games that have been submitted by outside developers, running on a platform that allows those games to tie into the site. Kongregate splits revenue with these developers, and in return Kongregate gets one of the most engaging and feature-packed online gaming sites.</li>
<li><a href="http://www.amazon.com">Amazon</a> doesn&#8217;t pay people to write reviews. It encourages users to submit reviews and aggregates them, and then encourages users to rate those reviews to ensure a reasonable level of quality. That&#8217;s crowdsourcing <em>twice</em>.</li>
</ul>

<p>The way I see it, all forms of Crowdsourcing have one thing in common: the members of the crowd are building something valuable. Crowdherding, which I believe happens much more often, does not have this quality. I would describe Crowdherding to be:</p>

<blockquote>&#8220;the act of convincing a group of people to perform a rote task, akin to sitting on a beach all day and counting sand, usually through various incentives, whether real or virtual&#8221;</blockquote>

<p>Some examples:</p>

<ul>
<li>In RPGs, players often refer to &#8220;grinding,&#8221; which is the task of continuously fighting monsters to raise their avatar&#8217;s level, or continuously searching for items to complete quests. They call it grinding because it&#8217;s a lot like grinding an axe on a wheel; one simple task has to be done continuously to make the axe sharp, and until it has been done for long enough, the person grinding the axe is really bored. A <a href="http://iro.ragnarokonline.com/">Ragnarok</a> player once told me that it would take him ~250 hours to get his character from level 98 to 99, where the process involves fighting tons of monsters and nothing else. He did it.</li>
<li><a href='http://freerice.com/'>FreeRice</a> has users play a vocabulary game; for each word a user gets correct, 20 grains of rice are donated to the UN World Food Program. In the month of May, over 4 billion grains of rice were donated. The rice is paid for by the ads that appear on the bottom of the screen. The website operator claims to not take any profit.</li>
<li>The Facebook game <a href='http://www.facebook.com/applications/Friends_For_Sale!/7019261521'>Friends For Sale!</a> awards you $10,000 of in-game currency for visiting the application at least once in a 4 hour period. This is essential to the developers because it keeps the daily numbers up and it is enticing to the users because money is necessary to buy friends in the game. In the past month, Friends For Sale! was the <a href="http://www.bretterrill.com/2008/06/playfish-dominates-social-gaming-top.html">#2 most popular game on Facebook</a>, after OWNED!, another game that follows the exact same principles.</li>
</ul>

<p>As mentioned before, in all examples of Crowdherding, the members of the crowd are not building anything. They are not generating content. They are simply gaining incentives, whether that be points for their avatar, virtual currency, or a sense of well-doing for helping the needy. In all cases, the actual mechanics of what the user is doing can be described as nothing more than clicking (on a link, or a button, or an on-screen enemy). If you think about it, Crowdherding has been around for a long time. Think of any case where users are being driven like sheep to do a simple task that generates revenue for someone else, and you have an example of Crowdherding. While it sounds bad, I wouldn&#8217;t think of it as good or bad. It&#8217;s using psychology to generate revenue from user activity. It&#8217;s getting people to look at your webpage instead of someone else&#8217;s. It&#8217;s a concept you have to understand if you want to be successful in this ad-driven industry. <small>And in the case of Free Rice, that herding leads to purely humanitarian goals.</small></p>

<p>So let me describe what makes successful Crowdherding:</p>

<ul>
<li><strong>Offering valuable incentives.</strong> This value can be virtual, in which case the actual cost might be much lower. A virtual incentive might be a cartoon depiction of a hat which your avatar can wear inside a game. This hat only costs as much as a one-time fee charged by the artist who made it, so once it has convinced a few certain number of people to generate a certain amount of ad revenue through their activity, it has paid itself off. A service that uses both real and virtual incentives is <a href="http://club.live.com/">Live Search Club</a>.</li>
<li><strong>Making the process of counting sand engaging.</strong> Even though the user maybe be performing some rote task, they are more likely to do it if it feels fun. This may involve watching a funny video or playing an engaging game. </li>
<li><strong>Making the process of counting sand &amp; gaining incentives somewhat difficult.</strong> People who play RPGs may complain about grind when they encounter it, but the fact is that the best online RPGs all have it. This is because grind is hard, demanding a serious time commitment from the user, and when users make it through that grind and gain their reward, they feel a sense of accomplishment that they wouldn&#8217;t have if they had received the reward quickly. This, in turn, inflates the value of the incentives, making them even more desirable to users (and building a vicious cycle). Also, the more a user invests in a game, the more they feel attached to that game and are reluctant to give up playing it. </li>
</ul>

<p>That&#8217;s Crowdherding as best as I can explain it. Hopefully now you have some insight into my line of work. <small>Food for thought: is Crowdsourcing a subset of Crowdherding, or are they distinct practices, or what?</small></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/christianmontoya?a=jqHxNi"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=jqHxNi" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=k28NJi"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=k28NJi" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=wouN3I"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=wouN3I" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/christianmontoya/~4/308492624" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.christianmontoya.com/2008/06/09/crowdherding/feed/</wfw:commentRss>
		<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetItemData?uri=christianmontoya&amp;itemurl=http%3A%2F%2Fwww.christianmontoya.com%2F2008%2F06%2F09%2Fcrowdherding%2F</feedburner:awareness></item>
		<item>
		<title>Constructive Contribution</title>
		<link>http://www.christianmontoya.com/2008/06/02/constructive-contribution/</link>
		<comments>http://www.christianmontoya.com/2008/06/02/constructive-contribution/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 07:21:17 +0000</pubDate>
		<dc:creator>Christian Montoya</dc:creator>
		
		<category><![CDATA[Business]]></category>

		<guid isPermaLink="false">http://www.christianmontoya.com/2008/06/02/constructive-contribution/</guid>
		<description><![CDATA[On problems and solutions in startup environments.]]></description>
			<content:encoded><![CDATA[<p><small>Since I can&#8217;t give away all the details about my day-to-day work on this site, I&#8217;m going to focus more on insight and advice from the startup scene in my writing. Hopefully this means more consistent updates than the last few months.</small></p>

<p>In a startup, it&#8217;s typical for ideas to be plentiful and resources to be limited. It&#8217;s also typical to have a lot of problems, as a company moves from scratch to (hopeful) success. This means that there will always be reasons to argue, and there will always be a need for solutions.</p>

<p>I have often seen someone in the middle of a discussion do nothing more than state existing problems, as if saying them out loud will somehow fix them. Stating problems doesn&#8217;t make them go away, nor does it encourage others to fix it. An example of doing so would be, &#8220;Our projects take too long to complete because we don&#8217;t have any task monitoring or follow-up in place.&#8221; It&#8217;s way more useful to propose solutions to existing problems. While people may be annoyed when they are reminded about the same problems they already deal with everyday, the same people are excited to hear about solutions that might put those problems to rest; after all, solutions are what people get paid for. An example would be, &#8220;Our projects take too long to complete because we don&#8217;t have any task monitoring or follow-up in place, but we can fix this by using project management software A and assigning someone to be product manager.&#8221;</p>

<p>Now this is already a huge improvement, but in the limited teams that are typical of startups, if you want to see problems actually get eliminated, you have to be willing to take this one step further and actually implement your own solutions, or at least find the right people to do so. Another example: &#8220;Our projects take too long to complete because we don&#8217;t have any task monitoring or follow-up in place, but we can fix this by using project management software A and assigning someone to be product manager. I&#8217;ll purchase an X-user license for this software and have CD&#8217;s for us by tomorrow so everyone can install it, and I propose that we start hiring for a new position of product manager; in the meantime, I can fill the position to get things rolling.&#8221; This is what separates constructive contribution from complaints, and I can say for certain that this attitude is what every startup needs.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/christianmontoya?a=qjILJi"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=qjILJi" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=2ejebi"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=2ejebi" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=eIuDlI"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=eIuDlI" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/christianmontoya/~4/302796680" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.christianmontoya.com/2008/06/02/constructive-contribution/feed/</wfw:commentRss>
		<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetItemData?uri=christianmontoya&amp;itemurl=http%3A%2F%2Fwww.christianmontoya.com%2F2008%2F06%2F02%2Fconstructive-contribution%2F</feedburner:awareness></item>
		<item>
		<title>On the big screen (with link)</title>
		<link>http://www.christianmontoya.com/2008/05/29/on-the-big-screen/</link>
		<comments>http://www.christianmontoya.com/2008/05/29/on-the-big-screen/#comments</comments>
		<pubDate>Fri, 30 May 2008 00:22:59 +0000</pubDate>
		<dc:creator>Christian Montoya</dc:creator>
		
		<category><![CDATA[Asides]]></category>

		<guid isPermaLink="false">http://www.christianmontoya.com/2008/05/29/on-the-big-screen/</guid>
		<description><![CDATA[I&#8217;m sitting at the latest Facebook Developer Garage in Palo Alto and they just showed a video recap of the first year of Facebook platform. Included in that was a short video featuring 3 employees from SGN, including myself. Talk about embarrassing. Link here: Facebook video for the Platform birthday.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sitting at the latest Facebook Developer Garage in Palo Alto and they just showed a video recap of the first year of Facebook platform. Included in that was a short video featuring 3 employees from <a href='http://www.sgn.com'>SGN</a>, including myself. Talk about embarrassing. Link here: <a href='http://www.facebook.com/video/video.php?v=15172363703&amp;oid=14400738508'>Facebook video for the Platform birthday</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/christianmontoya?a=OJLxjh"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=OJLxjh" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=zMwEph"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=zMwEph" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=tUulZH"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=tUulZH" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/christianmontoya/~4/300887064" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.christianmontoya.com/2008/05/29/on-the-big-screen/feed/</wfw:commentRss>
		<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetItemData?uri=christianmontoya&amp;itemurl=http%3A%2F%2Fwww.christianmontoya.com%2F2008%2F05%2F29%2Fon-the-big-screen%2F</feedburner:awareness></item>
		<item>
		<title>Share the gift of better browsing</title>
		<link>http://www.christianmontoya.com/2008/05/10/share-the-gift-of-better-browsing/</link>
		<comments>http://www.christianmontoya.com/2008/05/10/share-the-gift-of-better-browsing/#comments</comments>
		<pubDate>Sat, 10 May 2008 21:21:35 +0000</pubDate>
		<dc:creator>Christian Montoya</dc:creator>
		
		<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.christianmontoya.com/2008/05/10/share-the-gift-of-better-browsing/</guid>
		<description><![CDATA[by sending your Facebook friends Firefox gifts with Free Gifts.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s some fresh news from the <a href="http://sgn.com/">SGN</a> front: <a href="http://apps.facebook.com/freegifts">Free Gifts</a>, the premier virtual gifting application on Facebook, now has an official collection for <a href="http://www.mozilla.com/firefox/">Mozilla Firefox</a>.</p>

<p><a href="http://www.flickr.com/photos/thephotoherald/2481587620/" title="Facebook - Free Gifts Mozilla Firefox collection by montoya.christian, on Flickr"><img src="http://farm4.static.flickr.com/3094/2481587620_b09da6eb0b.jpg" width="500" height="322" alt="Facebook - Free Gifts Mozilla Firefox collection" /></a></p>

<p>When you send a gift from the Mozilla Firefox collection to a friend, they will see this link encouraging them to try Firefox:</p>

<p><a href="http://www.flickr.com/photos/thephotoherald/2480779465/" title="Facebook - Free Gifts Mozilla Firefox link by montoya.christian, on Flickr"><img src="http://farm4.static.flickr.com/3268/2480779465_54b6b67ae3_o.png" width="416" height="149" alt="Facebook - Free Gifts Mozilla Firefox link" /></a></p>

<p>So how about showing your support for Firefox and <a href="http://apps.facebook.com/freegifts/">sending these gifts to all your friends</a>? They&#8217;ll thank you later.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/christianmontoya?a=xkFFUh"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=xkFFUh" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=THiSWh"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=THiSWh" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=s1lNDH"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=s1lNDH" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/christianmontoya/~4/287702115" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.christianmontoya.com/2008/05/10/share-the-gift-of-better-browsing/feed/</wfw:commentRss>
		<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetItemData?uri=christianmontoya&amp;itemurl=http%3A%2F%2Fwww.christianmontoya.com%2F2008%2F05%2F10%2Fshare-the-gift-of-better-browsing%2F</feedburner:awareness></item>
		<item>
		<title>Construct 0.5: small changes that equal big improvements</title>
		<link>http://www.christianmontoya.com/2008/04/30/construct-05-small-changes-that-equal-big-improvements/</link>
		<comments>http://www.christianmontoya.com/2008/04/30/construct-05-small-changes-that-equal-big-improvements/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 06:40:19 +0000</pubDate>
		<dc:creator>Christian Montoya</dc:creator>
		
		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://www.christianmontoya.com/2008/04/30/construct-05-small-changes-that-equal-big-improvements/</guid>
		<description><![CDATA[Now with features like one-click preview, horizontal rules, Lorem Ipsum text, and improved generated output.]]></description>
			<content:encoded><![CDATA[<p>Last Sunday I decided to finally take <a href="http://constructyourcss.com/">Construct</a> to version 0.5 with some long-awaited features. It now supports:</p>

<ul>
<li>Preview mode: click &#8220;Preview&#8221; in the header to see how the layout will actually look, then click &#8220;Edit&#8221; to return to editing mode.</li>
<li>&lt;HR&gt; tag: Press Z to toggle having an &lt;HR&gt; after the currently selected container.</li>
<li>Lorem Ipsum: Press C to fill the current column with Lorem Ipsum text. Press V to empty it. </li>
</ul>

<p>It also has some small fixes and improvements, most importantly:</p>

<ul>
<li>The bug where old styles or IDs would continue to show up in the generated CSS is gone.</li>
<li>The HTML and CSS output are nicely boxed and separated.</li>
<li>The &#8220;Hide this&#8221; link for slide-down dialogs is more standardized and sits in the top right.</li>
</ul>

<p>These changes required some major updates to the Construct code. For example:</p>

<ul>
<li>Floated columns only take up space if they have content in them, so they all have a non-breaking space (&amp;nbsp;) even when they are empty. </li>
<li>Having &lt;HR&gt; tags between containers means there are siblings that are not containers, but the up/down arrows are still supposed to scroll through containers. What used to be:</li>
</ul>


<div class="wp_syntax"><div class="code"><pre class="javascript">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#construct .container.selected'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">prev</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #009900; font-style: italic;">// ... </span>
$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#construct .container.selected'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">next</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<p>Had to become:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript">$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#construct .container.selected'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">prevAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'.container'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">slice</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">length</span> - <span style="color: #CC0000;">1</span>, <span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #009900; font-style: italic;">// ... </span>
$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#construct .container.selected'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">nextAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'.container'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">slice</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<p>And I&#8217;m not sure if that&#8217;s because there&#8217;s a bug in jQuery or that&#8217;s just the intended way.</p>

<ul>
<li>Adding &lt;HR&gt;&#8217;s and paragraphs to the mix meant my parser had to account for them, since they are both different from DIVs. For now I have these two checks thrown into the recursive function that parses each element:</li>
</ul>


<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #003366; font-weight: bold;">var</span> tagName = el.<span style="color: #006600;">nodeName</span>.<span style="color: #006600;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #009900; font-style: italic;">// tag name!</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span> tagName == <span style="color: #3366CC;">'hr'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> 
  markup += tabToDepth<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #3366CC;">&quot;&amp;lt;&quot;</span> + tagName + <span style="color: #3366CC;">&quot;&amp;gt; &lt;br&gt;&quot;</span>;
  <span style="color: #000066; font-weight: bold;">return</span> markup;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span> tagName == <span style="color: #3366CC;">'p'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> 
  parseDepth += <span style="color: #CC0000;">2</span>;
  markup += tabToDepth<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #3366CC;">&quot;&amp;lt;&quot;</span> + tagName + <span style="color: #3366CC;">&quot;&amp;gt;Lorem Ipsum...&amp;lt;/&quot;</span> + tagName + <span style="color: #3366CC;">&quot;&amp;gt; &lt;br&gt;&quot;</span>;
  parseDepth -= <span style="color: #CC0000;">2</span>;
  <span style="color: #000066; font-weight: bold;">return</span> markup;
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<p>I&#8217;ll have some screenshots and maybe a fresh tutorial up soon, but make sure to <a href="http://constructyourcss.com/">check version 0.5 out</a>. Also, I think it&#8217;s worth mentioning that with what I did on Sunday, it&#8217;s apparent that I can achieve a lot more in terms of allowing users to add their own sample content to the layout as well as allowing them to customize more things, such as colors and background images, as well as content styles. More than ever before, I can see the potential for a completely semantic, clean, standards-based layout editor built on top of Blueprint and jQuery, with a very minimal amount of code. It&#8217;s cool stuff.</p>

<p>If anyone has any ideas for what I can do to reach more people with this project and make it better as well, do share.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/christianmontoya?a=ml3FOg"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=ml3FOg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=scOVug"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=scOVug" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=tTihIG"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=tTihIG" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/christianmontoya/~4/280595107" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.christianmontoya.com/2008/04/30/construct-05-small-changes-that-equal-big-improvements/feed/</wfw:commentRss>
		<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetItemData?uri=christianmontoya&amp;itemurl=http%3A%2F%2Fwww.christianmontoya.com%2F2008%2F04%2F30%2Fconstruct-05-small-changes-that-equal-big-improvements%2F</feedburner:awareness></item>
		<item>
		<title>NEWSFLASH: Video comments on Techcrunch reveal that the blogosphere really is full of lame nerds</title>
		<link>http://www.christianmontoya.com/2008/04/23/newsflash-video-comments-on-techcrunch-reveal-that-the-blogosphere-really-is-full-of-lame-nerds/</link>
		<comments>http://www.christianmontoya.com/2008/04/23/newsflash-video-comments-on-techcrunch-reveal-that-the-blogosphere-really-is-full-of-lame-nerds/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 19:02:05 +0000</pubDate>
		<dc:creator>Christian Montoya</dc:creator>
		
		<category><![CDATA[Asides]]></category>

		<guid isPermaLink="false">http://www.christianmontoya.com/2008/04/23/newsflash-video-comments-on-techcrunch-reveal-that-the-blogosphere-really-is-full-of-lame-nerds/</guid>
		<description><![CDATA[Title says it all.
]]></description>
			<content:encoded><![CDATA[<p>Title says it all.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/christianmontoya?a=iZbc4ug"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=iZbc4ug" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=NFiPQEg"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=NFiPQEg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=INVHdvG"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=INVHdvG" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/christianmontoya/~4/276361774" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.christianmontoya.com/2008/04/23/newsflash-video-comments-on-techcrunch-reveal-that-the-blogosphere-really-is-full-of-lame-nerds/feed/</wfw:commentRss>
		<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetItemData?uri=christianmontoya&amp;itemurl=http%3A%2F%2Fwww.christianmontoya.com%2F2008%2F04%2F23%2Fnewsflash-video-comments-on-techcrunch-reveal-that-the-blogosphere-really-is-full-of-lame-nerds%2F</feedburner:awareness></item>
		<item>
		<title>Better object handling with PHP singletons</title>
		<link>http://www.christianmontoya.com/2008/04/15/better-object-handling-with-php-singletons/</link>
		<comments>http://www.christianmontoya.com/2008/04/15/better-object-handling-with-php-singletons/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 11:19:28 +0000</pubDate>
		<dc:creator>Christian Montoya</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.christianmontoya.com/2008/04/15/better-object-handling-with-php-singletons/</guid>
		<description><![CDATA[As opposed to the typical use of global variables for connection objects.]]></description>
			<content:encoded><![CDATA[<p>Recently I was researching local caching options for PHP when I came across the XCache var cache &mdash; a file-based caching interface that comes with the XCache opcode cacher (and only requires a small change in the PHP config). While looking for example code to use in my project, I came across an OOP API wrapper that used a design pattern I hadn&#8217;t seen before in PHP: <a href="http://en.wikipedia.org/wiki/Singleton_pattern">the singleton</a>. I&#8217;m going to repost the code that sparked my interest in using singletons consistently, which even includes examples for usage:</p>


<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #808080; font-style: italic;">/**
 * XCache
 *
 * @package XCache
 * @version $Id$
 * @copyright 2007
 * @author Cristian Rodriguez &lt;judas.iscariote@flyspray.org&gt;
 * @license BSD {@link http://www.opensource.org/licenses/bsd-license.php}
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> XCache <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066;">static</span> <span style="color: #0000ff;">$xcobj</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> final <span style="color: #000000; font-weight: bold;">function</span> __clone<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        throw <span style="color: #000000; font-weight: bold;">new</span> BadMethodCallException<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Clone is not allowed&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span> 
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * getInstance 
     * 
     * @static
     * @access public
     * @return object XCache instance
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> 
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> !<span style="color: #66cc66;">&#40;</span>self::<span style="color: #0000ff;">$xcobj</span> instanceof XCache<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          self::<span style="color: #0000ff;">$xcobj</span> = <span style="color: #000000; font-weight: bold;">new</span> XCache<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #b1b100;">return</span> self::<span style="color: #0000ff;">$xcobj</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * __set 
     * 
     * @param mixed $name 
     * @param mixed $value 
     * @access public
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span>, <span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        xcache_set<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span>, <span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * __get 
     * 
     * @param mixed $name 
     * @access public
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __get<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">return</span> xcache_get<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * __isset 
     * 
     * @param mixed $name 
     * @access public
     * @return bool
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __isset<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">return</span> xcache_isset<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * __unset 
     * 
     * @param mixed $name 
     * @access public
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __unset<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        xcache_unset<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//example use...</span>
&nbsp;
<span style="color: #0000ff;">$cache</span> = XCache::<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$cache</span>-&gt;<span style="color: #006600;">foo</span> = PHP_INT_MAX;
<span style="color: #0000ff;">$cache</span>-&gt;<span style="color: #006600;">bar</span> = <span style="color: #000066;">range</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'a'</span>, <span style="color: #ff0000;">'z'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000066;">var_dump</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cache</span>-&gt;<span style="color: #006600;">foo</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000066;">var_dump</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cache</span>-&gt;<span style="color: #006600;">bar</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000066;">unset</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cache</span>-&gt;<span style="color: #006600;">bar</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000066;">var_dump</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">isset</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cache</span>-&gt;<span style="color: #006600;">bar</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<p>If all this looks daunting to you, let&#8217;s consider what developers usually use: global variables. One might do:</p>


<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #0000ff;">$cache</span> = <span style="color: #000000; font-weight: bold;">new</span> XCache;</pre></div></div>


<p>in a file like cache.setup.php and include that in the rest of their files. Then, in a function, one might do:</p>


<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">function</span> get_from_cache<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$key</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000066;">global</span> <span style="color: #0000ff;">$cache</span>;
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$cache</span>-&gt;<span style="color: #0000ff;">$key</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<p>This might seem simple enough, but there are a couple problems with this approach:</p>

<ul>
<li>Even in scripts that don&#8217;t need to connect to the cache / create an instance of the connection, the connection still occurs. In a high level application with a lot of scripts being run, it&#8217;s important to avoid unused connection overhead. </li>
<li>Every function or method has to call the global variable with &#8220;global $var,&#8221; though one could argue this isn&#8217;t much different from calling a singleton object. </li>
</ul>

<p>The important point is the first one; I&#8217;m always developing for speed in my day-to-day work, and I&#8217;d like to put all my PHP scripts together into a coherent application without having to think about which pages of an application should be connecting to the database/memcache/xcache and which ones shouldn&#8217;t. I would like to have the connection interfaces available without having to worry about the connection overhead unless I absolutely need to make those connections. And I never, ever, want to connect to any of these services more than once in a page. I want to use the same connection from right when I first need to open it to the end.</p>

<p>Singletons make all of that easy. That&#8217;s why I wrote my own for mysqli and Memcache:</p>


<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #808080; font-style: italic;">/**
 * XDB
 *
 * @package XDB
 * @version $Id$
 * @copyright 2008
 * @author Christian Montoya &lt;montoya.christian@gmail.com&gt;
 * @license BSD {@link http://www.opensource.org/licenses/bsd-license.php}
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> XDB <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066;">static</span> <span style="color: #0000ff;">$xdbobj</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> final <span style="color: #000000; font-weight: bold;">function</span> __clone<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        throw <span style="color: #000000; font-weight: bold;">new</span> BadMethodCallException<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Clone is not allowed&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span> 
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * getInstance 
     * 
     * @static
     * @access public
     * @return object mysqli instance
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> 
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">// this is broken up for easy reading</span>
        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> !<span style="color: #66cc66;">&#40;</span> self::<span style="color: #0000ff;">$xdbobj</span> instanceof mysqli<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          self::<span style="color: #0000ff;">$xdbobj</span> = <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #66cc66;">&#40;</span>DB_IP, DB_USER, DB_PASS, DB_NAME<span style="color: #66cc66;">&#41;</span>;
          <span style="color: #808080; font-style: italic;">// here I am using defined constants for all the DB creds</span>
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #b1b100;">return</span> self::<span style="color: #0000ff;">$xdbobj</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// Examples</span>
<span style="color: #0000ff;">$DB</span> = XDB::<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$select</span> = <span style="color: #0000ff;">$DB</span>-&gt;<span style="color: #006600;">prepare</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SELECT * FROM blog&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// ...</span>
<span style="color: #0000ff;">$DB</span> = XDB::<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; 
<span style="color: #808080; font-style: italic;">// still the same, single mysqli connection</span></pre></div></div>



<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #808080; font-style: italic;">/**
 * XMem
 *
 * @package XMem
 * @version $Id$
 * @copyright 2008
 * @author Christian Montoya &lt;montoya.christian@gmail.com&gt;
 * @license BSD {@link http://www.opensource.org/licenses/bsd-license.php}
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> XMem <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066;">static</span> <span style="color: #0000ff;">$xmemobj</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> final <span style="color: #000000; font-weight: bold;">function</span> __clone<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        throw <span style="color: #000000; font-weight: bold;">new</span> BadMethodCallException<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Clone is not allowed&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span> 
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * getInstance 
     * 
     * @static
     * @access public
     * @return object Memcache instance
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> 
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> !<span style="color: #66cc66;">&#40;</span>self::<span style="color: #0000ff;">$xmemobj</span> instanceof Memcache<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          self::<span style="color: #0000ff;">$xmemobj</span> = <span style="color: #000000; font-weight: bold;">new</span> Memcache<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
          self::<span style="color: #0000ff;">$xmemobj</span>-&gt;<span style="color: #006600;">pconnect</span><span style="color: #66cc66;">&#40;</span>MEMCACHE_IP, MEMCACHE_PORT<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #b1b100;">return</span> self::<span style="color: #0000ff;">$xmemobj</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// Examples</span>
<span style="color: #0000ff;">$Mem</span> = XMem::<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$Mem</span>-&gt;<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'key1234'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$Mem</span>-&gt;<span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'key5678'</span>, <span style="color: #ff0000;">'saved'</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">3600</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>


<p>Remember, these singletons will return a new instance (connection) the first time they are called in a script execution, and everytime thereafter they will return the same instance that was already opened. If they are never called, a connection will never be opened, so there are no wasted connections.</p>

<p>In my opinion, this is way better than depending on global variables. If you are interested in using this, feel free to take the code here. Just remember to remove the examples <img src='http://www.christianmontoya.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<p><ins datetime="2008-04-15T23:26:52+00:00">Updated 4-15-2008</ins> with fixed code, thanks Cristian Rodriguez</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/christianmontoya?a=9v0ahXg"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=9v0ahXg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=TH9j3kg"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=TH9j3kg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/christianmontoya?a=iRUCc8G"><img src="http://feeds.feedburner.com/~f/christianmontoya?i=iRUCc8G" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/christianmontoya/~4/270643799" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.christianmontoya.com/2008/04/15/better-object-handling-with-php-singletons/feed/</wfw:commentRss>
		<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetItemData?uri=christianmontoya&amp;itemurl=http%3A%2F%2Fwww.christianmontoya.com%2F2008%2F04%2F15%2Fbetter-object-handling-with-php-singletons%2F</feedburner:awareness></item>
	<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetFeedData?uri=christianmontoya</feedburner:awareness></channel>
</rss>
