<?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>Brit Gardner &#183; Dallas, TX &#183; Web, iOS, Game Developer</title>
	<atom:link href="http://britg.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://britg.com</link>
	<description>The big yellow one&#039;s the sun.</description>
	<lastBuildDate>Sat, 18 Aug 2012 19:00:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Device Domains</title>
		<link>http://britg.com/2012/08/18/device-domains/</link>
		<comments>http://britg.com/2012/08/18/device-domains/#comments</comments>
		<pubDate>Sat, 18 Aug 2012 18:50:04 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[gaming]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://britg.com/?p=28762</guid>
		<description><![CDATA[Up until recently I&#8217;ve tried to keep my 3 main computing devices (Macbook, iPhone, iPad) all capable of doing the same things. I installed twitter, feed reader, and even Kindle apps on the laptop, and attempted to use text editing, server monitoring, and IM apps on the mobile devices. It&#8217;s the future! All of my [...]]]></description>
			<content:encoded><![CDATA[<p>Up until recently I&#8217;ve tried to keep my 3 main computing devices (Macbook, iPhone, iPad) all capable of doing the same things. I installed twitter, feed reader, and even Kindle apps on the laptop, and attempted to use text editing, server monitoring, and IM apps on the mobile devices. It&#8217;s the future! All of my devices should do all of the things, right?!</p>
<p>The unintended result was a mediocre experience on the domains that didn&#8217;t make sense for the device. This is a kind of poison to person who spends most of their time on one or the other. Overall productivity was down when it should have been up, and I found my reading and gaming going down.</p>
<p>So, after upgrading my laptop just a couple weeks ago I decided to try and keep specific domains to my devices.</p>
<ul>
<li><strong>Macbook:</strong> Work, email, IM</li>
<li><strong>iPhone:</strong> Gaming, Twitter, short-form reading</li>
<li><strong>iPad:</strong> Gaming, long-form reading</li>
</ul>
<p>Here are a few changes in behavior I&#8217;ve noticed:</p>
<ul>
<li>Whenever I&#8217;d get to a tough take-a-moment-and-think problem while coding, I&#8217;d context switch to Reeder or Twitter &#8212; no more!</li>
<li>I am finishing a lot more long-form reading</li>
<li>I am experiencing a lot more games (I&#8217;m not finishing them all, but <em>that&#8217;s</em> a whole other blog post)</li>
<li>I&#8217;ve rediscovered the beauty and utility in each of the devices</li>
</ul>
<p>The end result: I&#8217;ve noticed a huge difference in my productivity since adhering to these domains. The lack of context switching when I&#8217;m on a device increases focus tenfold. Also, when I use a device in a way that really makes the most of its form factor and capabilities, I feel like I&#8217;m in my stride. I&#8217;m not swimming upstream anymore, so to speak.</p>
<p>So, I&#8217;m going to try my best to keep Twitter and Reeder off my laptop, and work off my mobile devices. You should too if you don&#8217;t already!</p>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2012/08/18/device-domains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solitude</title>
		<link>http://britg.com/2012/07/13/solitude/</link>
		<comments>http://britg.com/2012/07/13/solitude/#comments</comments>
		<pubDate>Fri, 13 Jul 2012 14:05:20 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[news]]></category>

		<guid isPermaLink="false">http://britg.com/?p=28758</guid>
		<description><![CDATA[I&#8217;ve recently returned from a trip to Alaska (highly recommended!) and there&#8217;s one thing that I keep returning to in my thoughts, and I think it&#8217;s something that&#8217;s going to stick with me. As you know if you visit any National or State Parks, a big part of their mission is to protect nature, and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://britg.com.s3.amazonaws.com/solitude.jpg" rel="facebox"><img src="http://britg.com.s3.amazonaws.com/solitude.jpg" style="width: 250px; float: right; margin-left: 10px; margin-bottom: 10px;" /></a></p>
<p>I&#8217;ve recently returned from a trip to Alaska (highly recommended!) and there&#8217;s one thing that I keep returning to in my thoughts, and I think it&#8217;s something that&#8217;s going to stick with me.</p>
<p>As you know if you visit any National or State Parks, a big part of their mission is to protect nature, and educate visitors about that protection. What they&#8217;re protecting is mostly the same between all the parks, just the setting is different. But, a few of the park rangers in Alaska listed a strange resource they were preserving: <strong>Solitude</strong>.</p>
<p>Interesting, I had never thought of solitude as being something to protect, seek out or cherish. Perhaps it&#8217;s because the term is often mistakenly associated with loneliness. From <a href="http://en.wikipedia.org/wiki/Solitude">Wikipedia</a>:</p>
<blockquote><p>Solitude is a state of seclusion or isolation… A distinction has been made between solitude and loneliness. In this sense solitude is positive.</p></blockquote>
<p>In Alaska there is a pervading sense of enormity and scale. It can make you feel small and trivial, but not in a negative way. Even when around other people, there isn&#8217;t a subconscious <em>press</em> of humans &#8212; the space is just too big. The physical wonder of the place leads to a psychological state that I now recognize as solitude. It&#8217;s a pretty great place for the mind to be.</p>
<p>In our normal lives it&#8217;s hard to attain solitude but very easy to feel the cold grip of loneliness. I think experiencing Alaska and realizing that solitude is something to seek out and preserve has helped me deal with feelings of loneliness that&#8217;s all too commonly found in modern society. For that, I am thankful and I feel compelled to carry the torch: solitude is something we should all protect.</p>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2012/07/13/solitude/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SPDY and Its Relation to WebSockets</title>
		<link>http://britg.com/2012/03/15/spdy-and-its-relation-to-websockets/</link>
		<comments>http://britg.com/2012/03/15/spdy-and-its-relation-to-websockets/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 13:58:50 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[html/css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[spdy]]></category>
		<category><![CDATA[websockets]]></category>

		<guid isPermaLink="false">http://britg.com/?p=28393</guid>
		<description><![CDATA[When SPDY was first announced I didn&#8217;t pay too much attention as history has shown it takes years before these things become widely adopted, if ever. Recently though, Twitter launched support for the protocol and I noticed (via this Chrome plugin) that quite a few of the sites I visit on a regular basis (mostly [...]]]></description>
			<content:encoded><![CDATA[<p>When <a href="http://en.wikipedia.org/wiki/SPDY">SPDY</a> was first announced I didn&#8217;t pay too much attention as history has shown it takes years before these things become widely adopted, if ever. Recently though, <a href="http://www.webmonkey.com/2012/03/twitter-catches-the-spdy-train/">Twitter launched support</a> for the protocol and I noticed (via <a href="https://chrome.google.com/webstore/detail/mpbpobfflnpcgagjijhmgnchggcjblin">this Chrome plugin</a>) that quite a few of the sites I visit on a regular basis (mostly Google properties) are actually using SPDY in production.</p>
<p>Interesting. I guess it&#8217;s time to pay attention.</p>
<h3>But, WebSockets!</h3>
<p>My first question, without knowing too much about SPDY, was what its relation was to <a href="http://en.wikipedia.org/wiki/WebSocket">WebSockets</a> &#8212; are they two competing implementations solving the same problem? The short of it is: <em>No, they are complimentary and will coexist</em>. Here&#8217;s my best attempt to relate the two:</p>
<p><strong>SPDY</strong> is an augmentation to HTTP with the goal of making synchronous HTTP requests faster.</p>
<p><strong>WebSockets</strong> is an alternative to HTTP with the goal of facilitating <em>real time</em> communication.</p>
<p>The big point here being that SPDY shouldn&#8217;t require too much application-level refactoring, whereas supporting WebSockets means building an application specifically for bi-directional communication.</p>
<h3>Push</h3>
<p>A word often bandied about is <strong>push</strong> and it has two different meanings with these technologies.</p>
<p><strong>SPDY Push</strong> is a technique where more than just the requested resource is sent down the pipe to a browser, but within the context of a single request. Example: on a given HTML page there&#8217;s a good assumption that the corresponding .js and .css and a few images will be requested. SPDY can send all of these in a single request, eliminating quite a bit of RTT (round trip time).</p>
<p><strong>WebSockets Push</strong> facilitates asynchronous communication between the server and browser. The server receives new data from another source and rather than waiting for the browser to request the new data, it is simply pushed through an already-open connection.</p>
<h3>Complementary</h3>
<p>The two protocols are actually complimentary. WebSockets makes its initial handshake with servers over HTTP to discover if the <code>ws://</code> protocol is supported, and one of SPDY&#8217;s primary methods of optimization is compressing and caching HTTP request headers.</p>
<p>From the <a href="http://www.chromium.org/spdy/spdy-whitepaper">SPDY Whitepaper</a></p>
<blockquote><p>Header compression resulted in an ~88% reduction in the size of request headers and an ~85% reduction in the size of response headers… We found a reduction of 45 &#8211; 1142 ms in page load time simply due to header compression.</p></blockquote>
<p>So, in an ideal future the RESTful request-based web is driven by SPDY, and all of the real-time communication and &#8220;app-ifying&#8221; is handled via WebSockets. Two peas in a pod!</p>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2012/03/15/spdy-and-its-relation-to-websockets/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Forging Forgecraft: Integrating CSS3 Transitions with Javascript</title>
		<link>http://britg.com/2012/01/15/forging-forgecraft-integrating-css3-transitions-with-javascript/</link>
		<comments>http://britg.com/2012/01/15/forging-forgecraft-integrating-css3-transitions-with-javascript/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 16:01:01 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[gaming]]></category>
		<category><![CDATA[html/css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[forgecraft]]></category>

		<guid isPermaLink="false">http://britg.com/?p=26688</guid>
		<description><![CDATA[Forgecraft is a game currently in development using Ruby on Rails, Backbone.js, and all sorts of HTML5 buzzwords. Read an introduction here, and play the demo here. With Forgecraft, and any game really, there are usually quite a few animations running concurrently. I found these moments to be choppy, unresponsive and frustrating when they were [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://playforgecraft.com"><img src="http://britg.com.s3.amazonaws.com/forgecraft/logo-shadow.jpg" style="float: right; margin-left: 10px; margin-bottom: 10px; height: 45px;" /></a><em><a href="http://playforgecraft.com">Forgecraft</a> is a game currently in development using Ruby on Rails, Backbone.js, and all sorts of HTML5 buzzwords. Read an introduction <a href="http://britg.com/2011/12/29/forging-forgecraft-part-1-introduction/">here</a>, and play the demo <a href="http://playforgecraft.com">here</a>.</em></p>
<p>With Forgecraft, and any game really, there are usually quite a few animations running concurrently. I found these moments to be choppy, unresponsive and frustrating when they were implemented in javascript (especially on lower CPU environments like the iPad) and needed another solution. <a href="http://www.alistapart.com/articles/understanding-css3-transitions/">CSS3 transitions</a> were an obvious choice to check out, as they&#8217;ve been shown to be a great way to add a little pizzazz to a modern web app and can be executed natively (and even <a href="http://www.html5rocks.com/en/tutorials/speed/html5/#transanim">GPU accelerated</a>).</p>
<p><strong>But, can they provide the technical underpinnings for an interactive gamely element?</strong> To be effective in this context, they&#8217;d have to be:</p>
<ul>
<li>responsive, consistent and reliable</li>
<li>noticeably smoother than their javascript counterparts</li>
<li>simple to integrate with scripting</li>
</ul>
<p>Regarding the first 2 points, CSS3 transitions&#8217; effectiveness will really depend on your particular use-case. With Forgecraft they were definitely response, reliable, and smoother than javascript and I decided early on to use them in lieu of javascript wherever I could. But, I won&#8217;t go into the benchmarks and A/B comparisons in this article… perhaps later. Let&#8217;s just skip straight to the useful part:</p>
<h3>Product Intergortion <span style="font-size:12px"><em><a href="http://www.youtube.com/watch?v=CurP0BRHT9Y&#038;feature=endscreen&#038;NR=1" target="_blank">obscure 30 Rock reference &rarr;</a></em></span></h3>
<p>Integrating CSS3 transitions with the game&#8217;s scripting is pretty straight forward:</p>
<ul>
<li>Define transitions in CSS on your master element</li>
<li>Define classes with resulting properties changed</li>
<li>Trigger a class change using javascript</li>
<li>Listen for the transition-end event with javascript</li>
</ul>
<p>Of course, there are a few pitfalls with each of these steps that I&#8217;ll go into here. Let&#8217;s take an example from Forgecraft: the Bonus Strike event. Randomly while forging the player will see a bar pop-up like this:</p>
<p><img src="http://britg.com.s3.amazonaws.com/forgecraft/active-forge.jpg" style="width: 500px;" /></p>
<p>The bar moves from left-to-right and the player&#8217;s goal is to click the icon when the moving bar is directly under the target (large white) bar. The moving bar is animated with CSS3 transitions.</p>
<h4>Defining the CSS:</h4>
<p>We have a bar that needs an initial negative offset (the start position) that transitions to its final position. Simple enough: we define the base CSS on the <code>#bar</code> element and give it two classes (.new and .activated) defining each of its states. We also define the transition between the two states:</p>
<p><script src="https://gist.github.com/1616386.js?file=bar.css"></script><br />
<noscript><br />
#bar {<br />
  width: 600px;<br />
  height: 60px;</p>
<p>  position: relative;</p>
<p>  background-color: rgba(153, 153, 153, 0.3);<br />
  border-right: solid 5px white;</p>
<p>  -moz-transition-property: left;<br />
  -webkit-transition-property: left;<br />
  -o-transition-property: left;<br />
  transition-property: left;<br />
  -moz-transition-duration: 1.5s;<br />
  -webkit-transition-duration: 1.5s;<br />
  -o-transition-duration: 1.5s;<br />
  transition-duration: 1.5s;</p>
<p>}</p>
<p>#bar.new {<br />
  left: 0px;<br />
}</p>
<p>#bar.activated {<br />
  left: 600px;<br />
}<br />
</noscript></p>
<p><strong>One pitfall you may run into:</strong> for the animations to work in Firefox, you have to explicitly define the initial state for whatever property you are transitioning. In this example we are transitioning the <code>left</code> property of the <code>#bar</code> element. You normally wouldn&#8217;t define <code>left: 0;</code> &#8212; that&#8217;s the default! But Firefox requires this to trigger the transition when that property changes.</p>
<h4>Triggering the Animation in Javascript</h4>
<p>Using jQuery, we simply apply the classes that we defined in the CSS when we want to trigger the transition.</p>
<p><script src="https://gist.github.com/1616386.js?file=activate.js"></script><br />
<noscript><br />
$(&#8216;#bar&#8217;).removeClass(&#8216;new&#8217;).addClass(&#8216;activated&#8217;);<br />
</noscript></p>
<h4>Listening for the transition-end event</h4>
<p>CSS3 Transitions would be useless if we couldn&#8217;t get their context from within our scripting. Luckily, a series of events are fired in javascript while the transitions are running, just like you&#8217;d expect in a javascript-based animation. The primary event we care about is when the transition ends as you&#8217;ll most likely want to trigger callbacks.</p>
<p>Unfortunately, each browser vendor has decided to name these events differently… typical huh. <a href="http://www.modernizr.com/">Modernizr</a> to the rescue! (If you&#8217;re not using Modernizr, you should be. But that&#8217;s another blog post altogether).</p>
<p>There&#8217;s a hidden gem in the comments in the source code of Modernizr that explains how to use its <code><a href="http://www.modernizr.com/docs/#prefixed">.prefixed()</a></code> API to make a simple wrapper around the browser-specific transition event names. Here&#8217;s how I implemented it for the transition-end event. Feel free to use this wherever you need it:</p>
<p><script src="https://gist.github.com/1616386.js?file=transitionend.js"></script><br />
<noscript><br />
// Adapted from the Modernizer source comments</p>
<p>var transEndEventNames = {<br />
  &#8216;WebkitTransition&#8217; : &#8216;webkitTransitionEnd&#8217;,<br />
  &#8216;MozTransition&#8217;    : &#8216;transitionend&#8217;,<br />
  &#8216;OTransition&#8217;      : &#8216;oTransitionEnd&#8217;,<br />
  &#8216;msTransition&#8217;     : &#8216;msTransitionEnd&#8217;, // maybe?<br />
  &#8216;transition&#8217;       : &#8216;transitionEnd&#8217;<br />
}, </p>
<p>CSS3_TRANSITION_END = transEndEventNames[ Modernizr.prefixed('transition') ];<br />
</noscript></p>
<p>Bam, now we can use one simple event binding to handle all browsers:</p>
<p><script src="https://gist.github.com/1616386.js?file=listen.js"></script><br />
<noscript><br />
$(&#8216;#bar&#8217;).bind(CSS3_TRANSITION_END, function() {<br />
  //&#8230; do stuff<br />
});<br />
</noscript></p>
<h4>Stopping a Transition Early</h4>
<p>When the player hits the hammer-and-anvil icon during the Bonus Strike event, I needed to stop the animation early. The easiest way I found to do this, was to just set the animating property to its current value. The transition delta becomes 0, so the animation stops:</p>
<p><script src="https://gist.github.com/1616386.js?file=stop.js"></script><br />
<noscript><br />
$(&#8216;#bar&#8217;)css({ left: $(&#8216;#bar&#8217;).css(&#8216;left&#8217;) });<br />
</noscript></p>
<h3>Transition: End</h3>
<p>You may find that integrating CSS3 Transitions into your game makes your interactions smoother and more responsive, and with a simple API for scripting against transition events, developing against them should look and feel a lot like working in pure javascript.</p>
<hr />
<p><em>More Forging Forgecraft:</em></p>
<ul>
<li> <a href="http://britg.com/2011/12/29/forging-forgecraft-part-1-introduction/">Introducing Forgecraft</a></li>
<li> <a href="http://britg.com/2012/01/07/forging-forgecraft-a-hybrid-sql-mongodb-data-solution/">A Hybrid SQL MongoDB Data Solution</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2012/01/15/forging-forgecraft-integrating-css3-transitions-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forging Forgecraft: A Hybrid SQL MongoDB Data Solution</title>
		<link>http://britg.com/2012/01/07/forging-forgecraft-a-hybrid-sql-mongodb-data-solution/</link>
		<comments>http://britg.com/2012/01/07/forging-forgecraft-a-hybrid-sql-mongodb-data-solution/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 14:27:39 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[gaming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[forgecraft]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">http://britg.com/?p=26402</guid>
		<description><![CDATA[Forgecraft is a game currently in development using Ruby on Rails, Backbone.js, and all sorts of HTML5 buzzwords. Read an introduction here, and play the demo here. One of my primary goals while building Forgecraft is to learn as many new technologies as possible. I&#8217;ve learned the hard way that it&#8217;s better to leave this [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://playforgecraft.com"><img src="http://britg.com.s3.amazonaws.com/forgecraft/logo-shadow.jpg" style="float: right; margin-left: 10px; margin-bottom: 10px; height: 45px;" /></a><em><a href="http://playforgecraft.com">Forgecraft</a> is a game currently in development using Ruby on Rails, Backbone.js, and all sorts of HTML5 buzzwords. Read an introduction <a href="http://britg.com/2011/12/29/forging-forgecraft-part-1-introduction/">here</a>, and play the demo <a href="http://playforgecraft.com">here</a>.</em></p>
<p>One of my primary goals while building Forgecraft is to learn as many new technologies as possible. I&#8217;ve learned the hard way that it&#8217;s better to leave this kind of exploration in your hobby projects and out of your production &#8220;for real&#8221; stuff. And, seeing as how there are so many emergent technologies right now in web development there&#8217;s a lot to explore!</p>
<h4>Whole Hog is Too Much Hog</h4>
<p><a href="http://mongodb.org">MongoDB</a> has quite a bit of steam behind it in the Rails/Ruby community (and plenty of other places too), and with projects like <a href="http://mongoid.org">Mongoid</a> and <a href="http://mongomapper.com/">MongoMapper</a> (I went with Mongoid) it&#8217;s an easy drop-in replacement for Active Record that maintains all those ORM conventions you know and love. I decided against the <em>replacement</em> approach for one primary reason: <strong>I wanted to use existing, robust, and actively developed libraries that rely on Active Record</strong>.</p>
<p>Example: There&#8217;s no reason to roll your own authentication/user system when there are insanely popular and feature-full libraries already in place for them like <a href="https://github.com/plataformatec/Devise">Devise</a> and <a href="https://github.com/binarylogic/authlogic">authlogic</a> (I went with Devise).</p>
<p>Fortunately combining Active Record with Mongoid and getting the best of both worlds proved to be easy and painless.</p>
<h4>The Set Up</h4>
<p>The <a href="http://mongoid.org/docs/installation/configuration.html">instructions</a> for Mongoid include a step to remove the Active Record libraries from being loaded and delete your database.yml. Simply skip that step and both systems will run in conjunction.</p>
<p>One small operational change you&#8217;ll have to make during development is explicitly defining when your rails generators should use Active Record. If you want to make an AR-driven model, your generators will look like:</p>
<p><code>rails g active_record:model Player …</code> produces a model the extends from ActiveRecord::Base.</p>
<p>And by default, the data generators will use Mongoid:</p>
<p><code>rails g model Skill …</code> produces a model that includes Mongoid::Document.</p>
<h4>The Implementation</h4>
<p>Here&#8217;s how this combo system really shines in my opinion: get all the great features of gems built on AR with all the schema less features of Mongo. I&#8217;ll walk through an example:</p>
<p>In Forgecraft, the authenticating object is the <code>Player</code> and players have many <code>Skills</code> which, right now, are Accuracy, Craftsmanship, and Perception. But, the skill list will likely grow and change over time as the game evolves. A typical AR/SQL based approach would be to create a skills table and a join table between players and skills resulting in a complex multi-table query to get a player&#8217;s complete skills.</p>
<p>It&#8217;s clear here that the Player and Skills would fit well together as a single document in Mongo, queried all at once in one tidy object. But, since the Player is also our authentication model, using Mongo would prevent us from using Devise to handle all of that boring and complex auth stuff for us.</p>
<p>Enter Hybridization. Forgecraft&#8217;s implementation uses the typical Devise set up around the Player object (again all on top of AR). All of a player&#8217;s skills go into a single document with a reference to the player, like so:</p>
<p><script src="https://gist.github.com/1575059.js?file=skill.rb"></script><br />
<noscript>
<pre>class Skill
  include Mongoid::Document
  field :player_id, :type => Integer

  field :accuracy, :type => Integer, :default => 0
  field :craftsmanship, :type => Integer, :default => 0
  field :perception, :type => Integer, :default => 0

  index :player_id, :unique => true

  def player
    Player.find_by_id(player_id)
  end
end</pre>
<p></noscript></p>
<p>To set up the relationships like one would expect with Active Record is a simple method on your Player object:</p>
<p><script src="https://gist.github.com/1575059.js?file=player.rb"></script><br />
<noscript>
<pre>class Player < ActiveRecord::Base

  # ...

  def skills
    @skills ||= (Skill.where(:player_id => self.id).first || \
                 Skill.create(:player_id => self.id))
  end

end</pre>
<p></noscript></p>
<p>Bam! Now we can retrieve our skills as a single document (fast), and add new skills with ease (easy). Since Mongo is schema less, you could even have a different set of skills per player. Again, all of this is achievable through SQL &#8212; it&#8217;s been done for decades &#8212; but it just makes more conceptual sense to treat these as a single document.</p>
<p>Querying and working with these objects and their relationships looks and feels just like active record:</p>
<pre>player.skills
player.skills.accuracy
player.skills.update_attributes(:accuracy => 5)
player.skills.inc(:accuracy, 1)</pre>
<h4>Benefits Outweight the Consequences</h4>
<p>I know, I know &#8212; any time you introduce an additional system, especially a datastore, you introduce a lot of complexity, failure modes, testing, etc. But, I honestly think the benefits are worth this extra complexity. Speed, ease of development, and the potential for less schema-driven growth make this an ideal environment for me. I highly recommend it, and will be using it in the future!</p>
<hr />
<p><em>More Forging Forgecraft:</em></p>
<ul>
<li> <a href="http://britg.com/2011/12/29/forging-forgecraft-part-1-introduction/">Introducing Forgecraft</a></li>
<li> <a href="http://britg.com/2012/01/15/forging-forgecraft-integrating-css3-transitions-with-javascript/">Integrating CSS3 Transitions with Javascript</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2012/01/07/forging-forgecraft-a-hybrid-sql-mongodb-data-solution/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Forging Forgecraft Part 1: Introduction</title>
		<link>http://britg.com/2011/12/29/forging-forgecraft-part-1-introduction/</link>
		<comments>http://britg.com/2011/12/29/forging-forgecraft-part-1-introduction/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 23:50:58 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[gaming]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[forgecraft]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://britg.com/?p=26154</guid>
		<description><![CDATA[For the past few months I&#8217;ve been hacking away at a game partly, well, to make a game, and partly to play with a bunch of web technologies I&#8217;ve been interested in. That game is Forgecraft! Check it out and tell me what you think. What is Forgecraft? If you&#8217;ve played bejeweled you&#8217;ve got an [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://playforgecraft.com"><img src="http://britg.com.s3.amazonaws.com/forgecraft/intro.jpg" style="float: right; margin-left: 10px; margin-bottom: 10px;" /></a>For the past few months I&#8217;ve been hacking away at a game partly, well, to make a game, and partly to play with a bunch of web technologies I&#8217;ve been interested in. That game is <a href="http://playforgecraft.com">Forgecraft</a>! Check it out and tell me what you think.</p>
<h3>What is Forgecraft?</h3>
<p>If you&#8217;ve played bejeweled you&#8217;ve got an idea of the primary game mechanic: move gems into patterns. If you&#8217;ve played Minecraft you&#8217;ve got an idea of the gameplay twist: patterns. You&#8217;re not just matching 3, but moving ores into patterns that resemble weapons and armor. And finally, if you&#8217;ve played any loot-based game ever you&#8217;ve got an idea of reward structure: loot!</p>
<p>The target player is the casual player, but the game may also appeal to people who just like loot. And the target platforms are any modern web browser. Right now things are working ok in Chrome, Firefox, and Safari. Oh, and the game plays well as an installable web app on the iPad. In fact, all of the design decisions were made with this play mode in mind. Go ahead and save-to-homescreen on your iPad!</p>
<p><strong>Warning:</strong> It&#8217;s rough around the edges. There&#8217;s no tutorial and there may be bugs/features just flat out missing. I consider the game&#8217;s state as &#8216;playable demo.&#8217; But do let me know if you run into any bugs.</p>
<h3>The Tech</h3>
<p>Over the next few months I hope to put together a series of posts on the different technologies I played with while making Forgecraft. You know, go in-depth on each of them and all that jazz. For now, here&#8217;s just a run-down of the fun stuff I used:</p>
<h4>Back End</h4>
<ul>
<li>Hosted on <a href="http://heroku.com">Heroku</a> (Cedar stack)</li>
<li><a href="http://rubyonrails.org">Rails 3.1</a> with the asset pipeline</li>
<li><a href="http://mongodb.org">MongoDB</a></li>
</ul>
<h4>Front End</h4>
<ul>
<li>Haml/Sass through <a href="http://compass-style.org/">Compass</a></li>
<li><a href="http://jashkenas.github.com/coffee-script/">Coffeescript</a></li>
<li><a href="http://jquery.com">jQuery</a></li>
<li><a href="http://documentcloud.github.com/backbone/">Backbone.js</a></li>
<li><a href="http://twitter.github.com/bootstrap/">Bootstrap</a> from Twitter</li>
</ul>
<h4>HTML5 Buzzwords</h4>
<ul>
<li>CSS3 Animations</li>
<li>Web Audio API</li>
<li>History API / Pushstate API</li>
<li>iOS web-app installable</li>
</ul>
<p>My plan is to continue developing Forgecraft, expanding the items, mines, etc. and digging further into these emergent HTML5 technologies. I also would like to continue improving performance across the board. Things can get pretty choppy on the iPad when there are a lot of animations running at the same time.</p>
<p>Please, give <a href="http://playforgecraft.com">Forgecraft</a> a try and let me know how you like it and if you have any suggestions. The number one question I have is, is it fun? A game should be fun, I&#8217;m told.</p>
<hr />
<p><em>More Forging Forgecraft:</em></p>
<ul>
<li> <a href="http://britg.com/2012/01/07/forging-forgecraft-a-hybrid-sql-mongodb-data-solution/">A Hybrid SQL MongoDB Data Solution</a></li>
<li> <a href="http://britg.com/2012/01/15/forging-forgecraft-integrating-css3-transitions-with-javascript/">Integrating CSS3 Transitions with Javascript</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2011/12/29/forging-forgecraft-part-1-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Perfect Logrotate Config</title>
		<link>http://britg.com/2011/12/06/the-perfect-logrotate-script/</link>
		<comments>http://britg.com/2011/12/06/the-perfect-logrotate-script/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 00:18:45 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[sysops]]></category>

		<guid isPermaLink="false">http://britg.com/?p=25847</guid>
		<description><![CDATA[One of the first things I do when setting up a new server somewhere is get all those damn log files rotating. Here&#8217;s the logrotate.conf block I use: in /etc/logrotate.conf /path/to/any/log/file/*.log { daily dateext missingok rotate 365 compress delaycompress notifempty copytruncate } This is a slight modification of this configuration. Check out his explanation for [...]]]></description>
			<content:encoded><![CDATA[<p>One of the first things I do when setting up a new server somewhere is get all those damn log files rotating. Here&#8217;s the logrotate.conf block I use:</p>
<p><code></p>
<p>in /etc/logrotate.conf</p>
<p>/path/to/any/log/file/*.log {<br />
  daily<br />
  dateext<br />
  missingok<br />
  rotate 365<br />
  compress<br />
  delaycompress<br />
  notifempty<br />
  copytruncate<br />
}</p>
<p></code></p>
<p>This is a slight modification of <a href="http://www.nullislove.com/2007/09/10/rotating-rails-log-files/">this configuration</a>. Check out his explanation for all of the params.</p>
<p>The one I added that I think is essential is <code>dateext</code>, which appends dates instead of incrementing digits to the end of the log files, like so: </p>
<p><code><br />
-rw-r--r-- 1 britg britg  64M 2011-10-24 06:49 production.log-20111024.gz<br />
-rw-r--r-- 1 britg britg  62M 2011-10-25 06:52 production.log-20111025.gz<br />
-rw-r--r-- 1 britg britg  56M 2011-10-26 06:29 production.log-20111026.gz<br />
-rw-r--r-- 1 britg britg  56M 2011-10-27 06:51 production.log-20111027.gz<br />
-rw-r--r-- 1 britg britg  57M 2011-10-28 06:51 production.log-20111028.gz<br />
</code></p>
<p>Which, in my opinion, is much more parseable by our puny human brains.</p>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2011/12/06/the-perfect-logrotate-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ShapeEditor &#8211; Create and Export Shapes for MultistrokeGestureRecognizer</title>
		<link>http://britg.com/2011/11/30/shapeeditor-create-and-export-shapes-for-multistrokegesturerecognizer/</link>
		<comments>http://britg.com/2011/11/30/shapeeditor-create-and-export-shapes-for-multistrokegesturerecognizer/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 13:07:01 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[ios]]></category>
		<category><![CDATA[dev]]></category>

		<guid isPermaLink="false">http://britg.com/?p=25704</guid>
		<description><![CDATA[Nicolò Zereik and Luca Roverelli put together a neat tool for creating the JSON template files for the MultistrokeGestureRecognizer library: ShapeEditor It&#8217;s a small JAVA app &#8212; check it out if you&#8217;re looking for a simple way to create basic JSON template files for the gesture recognizer. Thanks, Nicolò and Luca!]]></description>
			<content:encoded><![CDATA[<p>Nicolò Zereik and Luca Roverelli put together a neat tool for creating the JSON template files for the <a href="https://github.com/britg/MultistrokeGestureRecognizer-iOS">MultistrokeGestureRecognizer</a> library:</p>
<p><a href="http://lucalaiho.altervista.org/joomla/shape-editor">ShapeEditor</a></p>
<p>It&#8217;s a small JAVA app &#8212; check it out if you&#8217;re looking for a simple way to create basic JSON template files for the gesture recognizer.</p>
<p>Thanks, Nicolò and Luca!</p>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2011/11/30/shapeeditor-create-and-export-shapes-for-multistrokegesturerecognizer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IGF Pirate Kart Pack 1</title>
		<link>http://britg.com/2011/10/29/igf-pirate-kart-pack-1/</link>
		<comments>http://britg.com/2011/10/29/igf-pirate-kart-pack-1/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 14:39:20 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[gaming]]></category>

		<guid isPermaLink="false">http://britg.com/?p=24850</guid>
		<description><![CDATA[If you&#8217;re unfamiliar with the IGF Pirate kart, it&#8217;s a neat collection of over 300 indie video games: a FREE and LEGAL compilation of over 300 games by over 100 developers! It was put together at the last minute for entry into the 2012 Independent Games Festival Main Competition. I&#8217;ll be honest, it&#8217;s pretty dense [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re unfamiliar with the <a href="http://www.piratekart.com/">IGF Pirate kart</a>, it&#8217;s a neat collection of over 300 indie video games:</p>
<blockquote><p>a FREE and LEGAL compilation of over 300 games by over 100 developers! It was put together at the last minute for entry into the 2012 Independent Games Festival Main Competition.</p></blockquote>
<p>I&#8217;ll be honest, it&#8217;s pretty dense and the fun-to-meh ratio is pretty low, haha. But, there are a few games I&#8217;ve stumbled upon in there that have neat concepts or neat execution. Here&#8217;s a package of 4 that I thought were playable at least. Grab the full torrent if you want to check them all out, otherwise grab this pack:</p>
<p><a href="https://filerelay.it/pickup/35d9e37284c512ed7fb50de07979795388f353ff">IGF Pirate Kart Pack 1</a></p>
<p>Perhaps my favorite of the bunch is &#8220;A Friendship in 4 Colours&#8221; by Damian Sommer. I may try to cull a few more gems out of the pack if I can find the time. Enjoy!</p>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2011/10/29/igf-pirate-kart-pack-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A SublimeText2 Project File for Rails Projects</title>
		<link>http://britg.com/2011/10/27/a-sublimetext2-project-file-for-rails-projects/</link>
		<comments>http://britg.com/2011/10/27/a-sublimetext2-project-file-for-rails-projects/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 16:03:10 +0000</pubDate>
		<dc:creator>britg</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[dev]]></category>

		<guid isPermaLink="false">http://britg.com/?p=24730</guid>
		<description><![CDATA[The fuzzy finder in SublimeText2 is great, but if you&#8217;ve added a rails folder to your project you may see a bunch of cruft in the result list most likely due to cache files. Here&#8217;s a generic rails project file I use that keeps the fuzzy finder pretty clean. Note: this is a Rails 3.0 [...]]]></description>
			<content:encoded><![CDATA[<p>The fuzzy finder in <a href="http://www.sublimetext.com/">SublimeText2</a> is great, but if you&#8217;ve added a rails folder to your project you may see a bunch of cruft in the result list most likely due to cache files. Here&#8217;s a generic rails project file I use that keeps the fuzzy finder pretty clean.</p>
<p><strong>Note:</strong> this is a Rails 3.0 project with <a href="http://documentcloud.github.com/jammit/">jammit</a> and <a href="http://compass-style.org/">compass</a> installed. The exclusion of the <code>assets</code> folder is probably not ideal in a Rails 3.1 project.</p>
<p><script src="https://gist.github.com/1319965.js?file=project.sublime-project"></script></p>
<p><noscript>
<pre>
{
	"folders":
	[
		{
			"path": "/Users/britg/Projects/ponycorn-fanclub.com",
            "folder_exclude_patterns": ["*.sass-cache", "tmp", "log", "assets", "cache"]
		}
	]
}
</pre>
<p></noscript></p>]]></content:encoded>
			<wfw:commentRss>http://britg.com/2011/10/27/a-sublimetext2-project-file-for-rails-projects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
