<?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>SoftLayer Blog &#187; snippits</title>
	<atom:link href="http://blog.softlayer.com/tag/snippits/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.softlayer.com</link>
	<description>A Behind the Scenes Look at the Best Hosting Provider in the World</description>
	<lastBuildDate>Wed, 22 May 2013 17:40:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>Meet Memcached: A Developer&#8217;s Best Friend</title>
		<link>http://blog.softlayer.com/2012/meet-memcached-a-developers-best-friend/</link>
		<comments>http://blog.softlayer.com/2012/meet-memcached-a-developers-best-friend/#comments</comments>
		<pubDate>Thu, 02 Aug 2012 17:10:31 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[experience]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[opportunity]]></category>
		<category><![CDATA[potential]]></category>
		<category><![CDATA[rich media]]></category>
		<category><![CDATA[snippits]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=8765</guid>
		<description><![CDATA[Whether you&#8217;re new to software development or you&#8217;ve been a coder since the punchcard days, at some point, you&#8217;ve probably come across horrendous performance problems with your website or scripts. From the most advanced users &#8212; creating scripts so complex that their databases flooded with complex JOINs &#8212; to the novice users &#8212; putting SQL [...]]]></description>
			<content:encoded><![CDATA[<p>Whether you&#8217;re new to software development or you&#8217;ve been a coder since the punchcard days, at some point, you&#8217;ve probably come across horrendous performance problems with your website or scripts. From the most advanced users &mdash; creating scripts so complex that their databases flooded with complex JOINs &mdash; to the novice users &mdash; putting SQL calls in loops &mdash; database queries <em>can</em> be your worst nightmare as a developer. I hate to admit it, but I&#8217;ve experienced some these nightmares first-hand as a result of some less-than-optimal coding practices when writing some of my own scripts. Luckily, I&#8217;ve learned how to use <a href="http://memcached.org/">memcached</a> to make life a little easier. </p>
<h3>What is Memcached?</h3>
<p>Memcached is a free and open source distributed memory object caching system that allows the developer to store any sort of data in a temporary cache for later use, so they don&#8217;t have to re-query it. By using memcached, a tremendous performance load can be decreased to almost nil. One of the most noteworthy features of the system is that it doesn&#8217;t cache EVERYTHING on your site/script; it only caches data that is sure to be queried often. Originally developed in 2003 by Brad Fitzpatrick to improve the site performance of LiveJournal.com, memcached has grown tremendously in popularity, with some of the worlds biggest sites &mdash; Wikipedia, Flickr, Twitter, YouTube and Craigslist &mdash; taking advantage of the functionality.</p>
<h3>How Do I Use Memcache?</h3>
<p>After installing the memcached library on your server (available at <a href="http://memcached.org/">http://memcached.org/</a>), it&#8217;s relatively simple to get started:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// Set up connection to Memcached</span>
  <span style="color: #000088;">$memcache</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Memcached<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$memcache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'host'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">11211</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not connect&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Connect to database here</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Check the cache for your query</span>
  <span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM memcached_test WHERE id=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$memcache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// if the data exists in the cache, get it!</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Got it from the cache!'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// data didn't exist in the cache</span>
    <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM memcached_test WHERE id=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// though we didn't find the data this time, cache it for next time!</span>
  <span style="color: #000088;">$memcache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #666666; font-style: italic;">// Stores the result of the query for 30 seconds</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'In the cache now!'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Querying the cache is very similar to querying any table in your database, and if that data isn&#8217;t cached, you&#8217;ll run a database query to get the information you&#8217;re looking for, and you can add that information to the cache for the next query. If another query for the data doesn&#8217;t come within 30 seconds (or whatever window you specify), memcached will clear it from the cache, and the data will be pulled from the database.</p>
<p>So come on <a href="http://sldn.softlayer.com">developers</a>! Support memcached and faster load times! What other tools and tricks do you use to make your applications run more efficiently?</p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/meet-memcached-a-developers-best-friend/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HTML5 &#8211; Compatibility for All?</title>
		<link>http://blog.softlayer.com/2012/html5-compatibility-for-all/</link>
		<comments>http://blog.softlayer.com/2012/html5-compatibility-for-all/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 18:10:05 +0000</pubDate>
		<dc:creator>Cassandra Wolff</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[experience]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[opportunity]]></category>
		<category><![CDATA[potential]]></category>
		<category><![CDATA[rich media]]></category>
		<category><![CDATA[snippits]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=7712</guid>
		<description><![CDATA[Many of us remember when Flash was the &#8220;only&#8221; way to enhance user experience and create rich media interactivity. It was a bittersweet integration, though &#8230; Many users didn&#8217;t have the browser compatibility to use it, so some portion of your visitors were left in the dark. Until recently, that user base was relatively small [...]]]></description>
			<content:encoded><![CDATA[<p>Many of us remember when <a href="http://get.adobe.com/flashplayer/">Flash</a> was the &#8220;only&#8221; way to enhance user experience and create rich media interactivity. It was a bittersweet integration, though &#8230; Many users didn&#8217;t have the browser compatibility to use it, so some portion of your visitors were left in the dark. Until recently, that user base was relatively small &mdash; the purists who didn&#8217;t want Flash or the people whose hardware/software couldn&#8217;t support it. When Apple decided it wouldn&#8217;t enable Flash on the iPhone/iPad, web developers around the world groaned. A HUGE user base (that&#8217;s growing exponentially) couldn&#8217;t access the rich media and interactive content.</p>
<p>In the last year or so, Adobe released <a href="http://www.bgr.com/2011/09/09/adobe-finally-brings-flash-to-iphone-and-ipad/">Flash Media Server</a> to circumvent the Apple-imposed restrictions, but the larger web community has responded with a platform that will be both compatible and phenomenally functional: HTML5. </p>
<p>HTML5 allows us to do things we&#8217;ve never been able to do before (at least without the hassle of plugins, installations and frustration). Gone are the limitations that resigned HTML to serving as a simple framework for webpages &#8230; Now developers can push the limits of what they thought possible. As the platform has matured, some developers have even taken it upon themselves to prototype exactly where this generation of scripting is heading by creating Flash-free browser games. </p>
<p>Yes, you read that right: Games you can actually play on your browser, WITHOUT plugins. </p>
<p>From simple <a href="http://stewd.io/pong/">Pong</a> clones that use browser windows as the paddles and ball to adventure-based Zelda-like massively multiplayer online role playing games (MMORPGs) like <a href="http://browserquest.mozilla.org/">BrowserQuest</a>, it&#8217;s pretty unbelievable to see the tip of the iceberg of possibilities enabled by HTML5 &#8230; Though it does seem a bit ironic to say that a Pong clone is such a great example of the potential of the HTML5 platform. Click on the screenshot below to check out BrowserQuest and tell me it doesn&#8217;t amaze you:</p>
<p><a href="http://browserquest.mozilla.org/" target="blank"><img class="centered" src="http://cdn.softlayer.com/innerlayer/browserquest.jpg" alt="Browser Quest"/></a></p>
<p>With an ingenious combination of CSS, JavaScript and HTML5, developers of BrowserQuest have been able to accomplish something that no one has ever seen (nor would ever even have thought possible). Developers are now able to generate dynamic content by injecting JavaScript into their HTML5 canvasses:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">function</span> handleKeyDown<span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	keys<span style="color: #009900;">&#91;</span>evt<span style="color: #339933;">.</span>keyCode<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> handleKeyUp<span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	keys<span style="color: #009900;">&#91;</span>evt<span style="color: #339933;">.</span>keyCode<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// disable vertical scrolling from arrows :)</span>
document<span style="color: #339933;">.</span>onkeydown<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">return</span> event<span style="color: #339933;">.</span>keyCode<span style="color: #339933;">!=</span><span style="color: #cc66cc;">38</span> <span style="color: #339933;">&amp;&amp;</span> event<span style="color: #339933;">.</span>keyCode<span style="color: #339933;">!=</span><span style="color: #cc66cc;">40</span><span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>code<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Look familiar? The game-making process (not syntax!) appears eerily similar to that of any other popular language. The only difference: You don&#8217;t need to install this game &#8230; You just open your browser and enjoy.</p>
<p>Using a popular port of Box2D, a physics simulator, making pure browser-based games is as simple as &#8220;Make. Include. Create.&#8221; Here&#8217;s a snippit:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;</span>
<span style="color: #666666; font-style: italic;">//Make your canvas</span>
<span style="color: #339933;">&lt;</span>canvas id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;game&quot;</span> width<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;600&quot;</span> height<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;400&quot;</span><span style="color: #339933;">&gt;&lt;/</span>canvas<span style="color: #339933;">&gt;</span>  
&nbsp;
<span style="color: #666666; font-style: italic;">//include your js physics files</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create your world</span>
<span style="color: #000000; font-weight: bold;">function</span> createWorld<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// here we create our world settings for collisions</span>
	<span style="color: #000000; font-weight: bold;">var</span> worldAABB <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> b2AABB<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	worldAABB<span style="color: #339933;">.</span>minVertex<span style="color: #339933;">.</span>Set<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	worldAABB<span style="color: #339933;">.</span>maxVertex<span style="color: #339933;">.</span>Set<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// set gravity vector</span>
	<span style="color: #000000; font-weight: bold;">var</span> gravity <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> b2Vec2<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> doSleep <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// init our world and return its value</span>
	<span style="color: #000000; font-weight: bold;">var</span> world <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> b2World<span style="color: #009900;">&#40;</span>worldAABB<span style="color: #339933;">,</span> gravity<span style="color: #339933;">,</span> doSleep<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> world<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>code<span style="color: #339933;">&gt;</span></pre></div></div>

<p>We may be a few years away from building full-scale WoW-level MMORPGs with HTML5, but I think seeing this functionality in native HTML will be a sigh of relief to those that&#8217;ve missed out on so much Flash goodness. While developers are building out the next generation of games and apps that will use HTML5, you can keep yourself entertained (and waste hours of time) with the HTML5 port of <a href="http://chrome.angrybirds.com">Angry Birds</a>! </p>
<p><a href="http://chrome.angrybirds.com"><img class="centered" src="http://cdn.softlayer.com/innerlayer/angrybirdsbrowser.jpg" alt="Angry Birds"/></a></p>
<p>HTML5 is not immune to some browser compatibility issues with older versions, but as it matures and becomes the standard platform for web development, we&#8217;re going to see what&#8217;s to come in our technology&#8217;s immediate future: Pure and simple compatibility for all.</p>
<p>-Cassandra</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2012/html5-compatibility-for-all/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
