<?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>Jason Mooberry</title>
	<atom:link href="http://blog.jasonmooberry.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jasonmooberry.com</link>
	<description>Stuff I did for you.</description>
	<lastBuildDate>Sat, 29 Oct 2011 23:41:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.2</generator>
		<item>
		<title>The how behind the homepage</title>
		<link>http://blog.jasonmooberry.com/2011/10/the-how-behind-the-homepage/</link>
		<comments>http://blog.jasonmooberry.com/2011/10/the-how-behind-the-homepage/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 23:18:23 +0000</pubDate>
		<dc:creator>Jason Mooberry</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[cellular automata]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.jasonmooberry.com/?p=302</guid>
		<description><![CDATA[I recently built a new homepage to celebrate Fall and kill a few weekends playing with canvas, javascript and CA. A little while back I had an idea to use Cellular Automata rules to generate random groupings of xy coordinates. This worked well as a way to generate a rock pattern for my canvas drawing. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently built a <a href="http://jasonmooberry.com">new homepage</a> to celebrate Fall and kill a few weekends playing with canvas, javascript and CA.</p>
<p>A little while back I had an idea to use <a href="http://en.wikipedia.org/wiki/Cellular_automaton">Cellular Automata</a> rules to generate random groupings of xy coordinates.  This worked well as a way to generate a rock pattern for my <a href="http://blog.jasonmooberry.com/2011/05/death-valley-cellular-automata-and-html5-canvas/">canvas drawing</a>.  I even developed a <a href="http://local.jasonmooberry.com/dev/ca_helper.html">little tool</a> to help me refine the parameters to use that produced the pattern I wanted.</p>
<style>
#tools { margin:10px auto; width:620px; height:300px; }
#tools img { border:1px solid #ccc; }
</style>
<div id="tools">
<a href="http://jasonmooberry.com/dev/ca_fluid_animation.html" style="float:right;"><img src="http://jasonmooberry.com/dev/img/ca_animator.gif" /></a><br />
<a href="http://jasonmooberry.com/dev/ca_helper.html" style="float:left;"><img src="http://jasonmooberry.com/dev/img/ca_helper.gif"  /></a>
</div>
<p>I wanted to expand on that approach to make something more abstract and vizzy.  And animation seemed like the next step.  So I built <a href="http://jasonmooberry.com/dev/ca_fluid_animation.html">another tool</a> that allowed me to play around with animating generated CA sets of cells from one state to the next. </p>
<p>It lets you embed js into the callbacks for the driving parameters and even saves your settings into the hash tag so you can bookmark settings that you like and link to them.</p>
<p>So I&#8217;m publishing them both here for you to play with.  <img src='http://blog.jasonmooberry.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jasonmooberry.com/2011/10/the-how-behind-the-homepage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Password management with TrueCrypt and Dropbox</title>
		<link>http://blog.jasonmooberry.com/2011/08/password-management-with-truecrypt-and-dropbox/</link>
		<comments>http://blog.jasonmooberry.com/2011/08/password-management-with-truecrypt-and-dropbox/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 18:39:09 +0000</pubDate>
		<dc:creator>Jason Mooberry</dc:creator>
				<category><![CDATA[command line fu]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[passwords]]></category>

		<guid isPermaLink="false">http://blog.jasonmooberry.com/?p=284</guid>
		<description><![CDATA[Maintaining passwords for multiple servers across multiple development environments is a pain. A few weeks back there was a downed service on one of my servers and I was at a computer without my passwords and hosts files. The debugging session that followed required hopping through multiple servers and in general took a lot longer [...]]]></description>
			<content:encoded><![CDATA[<p>Maintaining passwords for multiple servers across multiple development environments is a pain.  A few weeks back there was a downed service on one of my servers and I was at a computer without my passwords and hosts files.  The debugging session that followed required hopping through multiple servers and in general took a lot longer than it should.  </p>
<p>I decided to use <a href="http://www.dropbox.com/" target="_blank">DropBox</a> and <a href="http://www.truecrypt.org/" target="_blank">TrueCrypt</a> to setup a secure password file that was synchronized across all of my environments.  The setup for both is dirt simple.  I created a 10mb encrypted file called <code>SAFEFILE</code> in my Dropbox, then add a <code>passwords.txt</code> to it.  </p>
<p>Then I evolved some code a friend threw my way for generating passwords.  Creating a password and storing it directly in my passwords.txt file, and retrieving it is now a snap.  The functions copy the password directly to the clipboard for easy pastin.</p>
<p>Adding my <code>~/.ssh</code>, <code>/etc/hosts</code>, <code>~/.profile</code> and a few other dotfiles to my Dropbox and symlinking them to my home directory keeps me standard across any environment I use.</p>
<p>Generate a random string 30 chars long for test.account:</p>
<pre>
jmooberry@local ~ : genpass 30 test.account
password added to passwords.txt as test.account
password copied to clipboard.
//  ole2iUmIGwDxtC9xVqPZiEr34ZJVwD
</pre>
<p>Grab the password for test.account:</p>
<pre>
jmooberry@local ~ : getpass test
password for (test.account) copied to clipboard.
// ole2iUmIGwDxtC9xVqPZiEr34ZJVwD
</pre>
<p><code>.profile</code> helpers functions:</p>
<pre>
# password generator
# Usage: genpass 30 test.account.name
function genpass() {
  if [ $# == 0 ]; then
      length=30
  else
      length=$1
  fi
  pass=$(< /dev/random strings | perl -pe 's/\W//g;' | head -c$length)
  echo -n $pass | pbcopy
  if [ $# == 2 ]; then
    echo -en "\n$2\t$pass" >> /Volumes/SAFEFILE/passwords.txt
    echo "password added to passwords.txt as $2"
  fi
  echo "password copied to clipboard."
}

# password grabber
# Usage: getpass test.account.name
function getpass() {
  pass=$(grep $1 /Volumes/SAFEFILE/passwords.txt | perl -pe 's/.+?(\w+)$/$1/;')
  name=$(grep $1 /Volumes/SAFEFILE/passwords.txt | perl -pe 's/(.+?)\s+\w+$/$1/;')
  echo -n $pass | pbcopy
  echo "password for ($name) copied to clipboard."
}

# it's important.
if [ ! -d "/Volumes/SAFEFILE" ]; then
  echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  echo "TRUECRYPT DIRECTORY NOT MOUNTED!!!"
  echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
fi
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.jasonmooberry.com/2011/08/password-management-with-truecrypt-and-dropbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick encrypt for your coffee shop traffic.</title>
		<link>http://blog.jasonmooberry.com/2011/05/quick-encrypt-for-your-coffee-shop-traffic/</link>
		<comments>http://blog.jasonmooberry.com/2011/05/quick-encrypt-for-your-coffee-shop-traffic/#comments</comments>
		<pubDate>Mon, 16 May 2011 04:19:54 +0000</pubDate>
		<dc:creator>Jason Mooberry</dc:creator>
				<category><![CDATA[command line fu]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[coffee shop]]></category>
		<category><![CDATA[secure networking]]></category>
		<category><![CDATA[socks proxy]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://blog.jasonmooberry.com/?p=276</guid>
		<description><![CDATA[Just a little function to add to your .profile that automatically turns on a socks proxy and tunnels all your traffic through the server of your choice. It&#8217;s a simple setup and &#60;CTRL&#62;-C kills the connection and shuts off the proxy. This assumes that you have shell access to some server that you trust to [...]]]></description>
			<content:encoded><![CDATA[<p>Just a little function to add to your <code>.profile</code> that automatically turns on a socks proxy and tunnels all your traffic through the server of your choice.  It&#8217;s a simple setup and &lt;CTRL&gt;-C kills the connection and shuts off the proxy.  This assumes that you have shell access to some server that you trust to run your traffic through. </p>
<p>I recommend setting up <a href="http://stackoverflow.com/questions/7260/how-do-i-setup-public-key-authentication" target="_blank">public key authentication</a> for ease of use.</p>
<pre>
# warm feet
function socks() {
  networksetup -setsocksfirewallproxy AirPort localhost 9999
  ssh -ND 9999 -C username@domain
  networksetup -setsocksfirewallproxystate AirPort off
}
</pre>
<p>(One caveat:  If you happen to close the window of your terminal without hitting &lt;CTRL&gt;-C first, it will not disable the socks proxy.)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jasonmooberry.com/2011/05/quick-encrypt-for-your-coffee-shop-traffic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Drawing with Cellular Automata and HTML5 Canvas</title>
		<link>http://blog.jasonmooberry.com/2011/05/death-valley-cellular-automata-and-html5-canvas/</link>
		<comments>http://blog.jasonmooberry.com/2011/05/death-valley-cellular-automata-and-html5-canvas/#comments</comments>
		<pubDate>Wed, 11 May 2011 03:00:22 +0000</pubDate>
		<dc:creator>Jason Mooberry</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Me]]></category>
		<category><![CDATA[cellular automata]]></category>
		<category><![CDATA[game of life]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[PHI]]></category>

		<guid isPermaLink="false">http://blog.jasonmooberry.com/?p=227</guid>
		<description><![CDATA[This weekend I set out to do some canvas drawings. The first one ended up being the centerpiece of my home page. It was inspired by the leaves of a tree on my street. Oh it&#8217;s good to be back in the deciduous loving climate. The second drawing was inspired by a recent campout in [...]]]></description>
			<content:encoded><![CDATA[<p>This weekend I set out to do some canvas drawings.  The first one ended up being the centerpiece of my <a href="http://jasonmooberry.com" target="_blank">home page</a>.  It was inspired by the leaves of a tree on my street.  Oh it&#8217;s good to be back in the deciduous loving climate.</p>
<p>The second drawing was inspired by a recent campout in Death Valley.  The contrast of the blue sky, desert floor, and red coleman tent leave a strong imprint on me every time.</p>
<div style="text-align:center;">
<a href="http://jasonmooberry.com/dev/img/dv.jpg" target="_blank" ><img src="http://jasonmooberry.com/dev/img/dv_sm.jpg" style="margin:10px;" /></a> <a href="http://jasonmooberry.com/dev/dv_drawing.html" target="_blank"><img src="http://jasonmooberry.com/dev/img/dv_drawing.jpg" style="margin:10px;width:300px;height:225px;" /></a>
</div>
<p>The end result should resemble the <a href="http://jasonmooberry.com/dev/dv_drawing.html" target="_blank">picture on the right.</a>  The page load time is a few seconds on my MBP and it looks quite a lot better in Chrome.  The canvas size is determined at load so if you have the horses, full-screen your browser.  </p>
<p>I say resemble because the drawing is generated using canvas and cellular automata, and derived from a random data set every time it is rendered.  </p>
<p>One of the difficulties of drawing a picture of landscape is the seemingly random variations found in it.  Not totally random because each element interacts and affects the others.  The stone pattern on the drawing was the first thing I set out to solve.</p>
<p>Initially I was hoping to hit on some semi-random scatter pattern using PHI and a lot of trial and error.  This produced a fairly uniform random scatter of stones.  What I wanted to draw resembled clumps more than anything.  </p>
<p>While scatter patterning away I happened to over hear a gentlemen at the coffee shop mentioning cellular automata and emergent systems as they explain the state of the universe.  It&#8217;s kindof a hippie coffee shop but this guy is clearly in a league of his own.  At first I dismissed it and then the idea grew on me that I could generate these clumps with CA.  I had used CA for Conway&#8217;s game of life and a few other toy systems to experiment in the past and it was always fun.</p>
<p>So I generated a map of pixels that were randomly turned on.  I weighted the initial data set to be very switched on (baby!).  My reasoning was that I wanted grouping to occur within a few mutations and a seriously overcrowded starting set should do just that.  The size of the canvas element was prohibitively large so I added a resolution factor.  It causes striations in the starting set view but it doesn&#8217;t affect the CA mutations.</p>
<pre>
// set up psuedo random cell set
for (var i=0; i < total; i++) {
  if (Math.random() > .2) {
    cells[i] = 1;
  }
}
</pre>
<div style="text-align:center;"><a href="http://jasonmooberry.com/dev/ca_helper.html" target="_blank"><img src="http://jasonmooberry.com/dev/img/dv_initial_set.gif" /></a><br />
with resolution factor:<br />
<a href="http://jasonmooberry.com/dev/ca_helper.html" target="_blank"><img src="http://jasonmooberry.com/dev/img/dv_initial_set_r.gif" /></a></div>
<p>Let&#8217;s grind this set down with Conway&#8217;s game of life rules and see what comes out:</p>
<pre>
// mutate m number of times
while (m--) {
  var next = {};
  for (p in cells) { next[p] = 1; }

  for (var i=0; i < total; i++) {
    var above = i-w < 0 ? i-w+total : i-w,  // wrap
      below = i+w > total ? i+w-total : i+w, // wrap
      neighbors = [above-1,above,above+1,i-1,i+1,below-1,below,below+1],
      active = 0,
      j = neighbors.length-1;

    while (j--) {
      active += (typeof cells[neighbors[j]] === 'number' &#038;&#038; cells[neighbors[j]] === 1)|0;
    }
    // rule check
    // Any dead cell with exactly three live neighbours becomes a live cell.
    if (active === 3 &#038;&#038; typeof cells[i] === 'undefined') {
      next[i] = 1;
    }
    // Any live cell with two or three live neighbours lives on to the next generation.
    // Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
    // Any live cell with more than three live neighbours dies, as if by overcrowding.
    else if (active < 2 || active > 3) {
      delete next[i];
    }
  }
  var cells = {};
  for (p in next) { cells[p] = 1; }
}
</pre>
<div style="text-align:center;"><a href="http://jasonmooberry.com/dev/ca_helper.html" target="_blank"><img src="http://jasonmooberry.com/dev/img/dv_pass_1.gif" /></p>
<p><img src="http://jasonmooberry.com/dev/img/dv_pass_3.gif" /></p>
<p><img src="http://jasonmooberry.com/dev/img/dv_pass_8.gif" /></a></div>
<p>As you can see the first pass cleared out a bunch of em.  The resolution factor has spaced the pixels apart but you can see the basics of game of life players emerging.  By pass 3 it&#8217;s in a much more spare state but still larger groups than I want.  By pass 8 the groups have moved away from each other a bit more and formed a decent pattern. Since this pattern is generated fresh from a random data set every time, we just need something that&#8217;s right most of the time.  </p>
<p>What I like about this approach is that it gives some credence to the hippie coffee shop guy&#8217;s words.  I don&#8217;t think the world runs on CA rules, but iterative, interactive rules seem to give rise to interesting &#8220;random&#8221; patterns.</p>
<p>The dataset produced from these mutations can now be used to render a rock pattern with a little magic for the coloring/size.  </p>
<pre>
for (var i in cells) {
  c.beginPath();
  var x = (i*r)%w,
    y = (i*r)/w|0;
  c.strokeStyle = (['rgba(116,116,108,.7);','rgba(87,93,55,.9);'])[i%15===0|0];
  c.lineWidth = Math.max(30,50*(y/h));
  c.arc(x,y,3,0,360,false);
  c.stroke();
}
</pre>
<div style="text-align:center;"><a href="http://jasonmooberry.com/dev/ca_helper.html" target="_blank"><img src="http://jasonmooberry.com/dev/img/dv_render.gif" /></a></div>
<h3>tl dr;</h3>
<p>Using Cellular Automata rules to mutate random datasets can produce interesting and unique landscape patterns.  This approach was super useful for me in drawing an impressionist picture of my favorite camping spot.</p>
<p>I wrote a <a href="http://jasonmooberry.com/dev/ca_helper.html" target="_blank">simple tool</a> to experiment with different factors for generating these patterns.</p>
<p>And <a href="http://jasonmooberry.com/dev/dv_drawing.html" target="_blank">here&#8217;s the picture</a> that is generated from random CA patterns.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jasonmooberry.com/2011/05/death-valley-cellular-automata-and-html5-canvas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to refactor other&#8217;s code.</title>
		<link>http://blog.jasonmooberry.com/2011/02/how-to-refactor-others-code/</link>
		<comments>http://blog.jasonmooberry.com/2011/02/how-to-refactor-others-code/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 03:14:16 +0000</pubDate>
		<dc:creator>Jason Mooberry</dc:creator>
				<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[people]]></category>

		<guid isPermaLink="false">http://blog.jasonmooberry.com/?p=222</guid>
		<description><![CDATA[I was in a position today to refactor some code that didn&#8217;t belong to me. Without going into much detail I was asked to implement a feature that required some significant changes to some fresh code. A friend was online at the time. I remembered he had a very gentle way of dealing with other [...]]]></description>
			<content:encoded><![CDATA[<p>I was in a position today to refactor some code that didn&#8217;t belong to me.  Without going into much detail I was asked to implement a feature that required some significant changes to some fresh code.  </p>
<p>A friend was online at the time.  I remembered he had a very gentle way of dealing with other programmers.  He happens to be very smart and, as such, was in a position to review/teach most of the people at the company we worked at together.  I asked him how to do it:</p>
<p>me:</p>
<blockquote><p>hey i have a question.  how do you refactor someone else&#8217;s code without being &#8220;that jerk who&#8217;s refactoring my code&#8221;?  is it possible?
</p></blockquote>
<p>him: </p>
<blockquote><p>That is very hard.  When I approach that issue I always remember a quotation even though I forgot who said it: &#8220;To successfully critique something you must first learn to love it.&#8221;</p>
<p>Also I&#8217;m probably rewriting the quote somehow</p>
<p>If you approach someone about refactoring their code and show them that you&#8217;ve taken the time to understand why their code was written the way it was, or, if it&#8217;s super crappy, why they were in a compressed time schedule while writing it, or why it would help them to work with you to learn it better, etc. etc…. basically if you approach them with respect and compassion, and they get all pissy, at that point it&#8217;s their fault </p>
<p>But the best thing is to communicate period, often times I&#8217;ve seen people shrink away from communicating because they don&#8217;t want to confront the other person, and they end up rewriting the code without consulting with the original coder, or, worse, not dealing with the issue and leaving the bad code to rot.  Confrontation, even if it pisses the person off, is always better than doing nothing or doing something around the person
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.jasonmooberry.com/2011/02/how-to-refactor-others-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ecsmas and Tron</title>
		<link>http://blog.jasonmooberry.com/2010/12/ecsmas-and-tron/</link>
		<comments>http://blog.jasonmooberry.com/2010/12/ecsmas-and-tron/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 08:09:19 +0000</pubDate>
		<dc:creator>Jason Mooberry</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[ecsmas]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tron]]></category>

		<guid isPermaLink="false">http://blog.jasonmooberry.com/?p=212</guid>
		<description><![CDATA[Well I really had a blast working with @darkgoyle on the Merry Ecsmas project on Christmas Eve. It was my first attempt at a canvas creation and it came together great. I am still finding myself creating snowflakes there! All this canvas exposure and seeing how @darkgoyle does his maths got me in a mood [...]]]></description>
			<content:encoded><![CDATA[<p>Well I really had a blast working with <a href="http://twitter.com/@darkgoyle">@darkgoyle</a> on the <a href="http://ecsmas.com">Merry Ecsmas</a> project on Christmas Eve.  It was my first attempt at a canvas creation and it came together great.  I am still finding myself creating snowflakes there!  <img src='http://blog.jasonmooberry.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>All this canvas exposure and seeing how <a href="http://twitter.com/@darkgoyle">@darkgoyle</a> does his maths got me in a mood to experiment!  So I played around with implementing variations on a Fibonacci graph and many other different oddities involving timestamps and Phi.  The one I liked the most was pretty simple.  It is a rotation at 160 degrees with a 10px increment on the line length at each iteration.  Here&#8217;s what it produces:</p>
<div style="text-align:center"><a href="http://jasonmooberry.com/img/160d.png"><img src="http://jasonmooberry.com/img/160d_sm.png" /></a></div>
<p>I think it&#8217;s rad in a simple Trony sortof way.  Here&#8217;s the code to generate it:</p>
<pre>
// get the canvas
var canvas = document.getElementsByTagName('canvas')[0],
  c = canvas.getContext('2d'),
  center = { x: canvas.width/2, y: canvas.height/2 };

// setup starting state
c.translate(center.x,center.y);

// base styles
c.lineCap = 'round';
c.lineWidth = 2;
c.strokeStyle = 'rgba(0,0,255,.7)';

var f = 1;
while (f < 500) {
  c.beginPath();
  c.moveTo(0,0);
  c.rotate(160*(Math.PI/180)); // convert degrees to radians
  c.lineTo(f,f);
  c.translate(f,f);
  c.stroke();
  f += 10;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.jasonmooberry.com/2010/12/ecsmas-and-tron/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DumbledORM version 0.1 released!</title>
		<link>http://blog.jasonmooberry.com/2010/12/dumbledorm-version-0-1-released/</link>
		<comments>http://blog.jasonmooberry.com/2010/12/dumbledorm-version-0-1-released/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 09:32:22 +0000</pubDate>
		<dc:creator>Jason Mooberry</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[dumbledorm]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[novelty orm]]></category>
		<category><![CDATA[php 5.3]]></category>

		<guid isPermaLink="false">http://blog.jasonmooberry.com/?p=204</guid>
		<description><![CDATA[I&#8217;m happy to announce the release of DumbledORM 0.1. It&#8217;s a major revamp from the initial release. It&#8217;s still the same ~200 loc, but now chocked full of comments and under the MIT license. A few noteworthy changes. PDO now throws exceptions by default. The standard default in PDO is to fail silently. This was [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m happy to announce the release of DumbledORM 0.1.  It&#8217;s a major revamp from the initial release.  It&#8217;s still the same ~200 loc, but now chocked full of comments and under the MIT license.</p>
<p>A few noteworthy changes.</p>
<ol>
<li>PDO now throws exceptions by default.  The standard default in PDO is to fail silently.  This was unintended and thanks to <a href="http://twitter.com/#!/jimplush" target="_blank">@jimplush</a> for reporting it.  Be sure to try/catch your code appropriately.</li>
<li><code>Db::execute()</code> method added.  All of the Db methods are publicly accessible and this method is for executing sql that doesn&#8217;t require a fetch (inserts, updates, deletes, etc).  The requirement for this method became clear after turning on exceptions in PDO.</li>
<li>Better docs.  The docs in the README have been updated and reformatted.</li>
</ol>
<p>DumbledORM received a lot of great feedback and attention after it&#8217;s release.  Thank you for all the positive response to this little ORM.  I hope it continues to grow in use and remains small in size.  <img src='http://blog.jasonmooberry.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Download DumbledORM and get started here:<br />
<a href="https://github.com/jasonmoo/DumbledORM">https://github.com/jasonmoo/DumbledORM</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jasonmooberry.com/2010/12/dumbledorm-version-0-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MEMP: PHP 5.3 with FPM and nginx via MacPorts</title>
		<link>http://blog.jasonmooberry.com/2010/12/memp-php-5-3-with-fpm-and-nginx-via-macports/</link>
		<comments>http://blog.jasonmooberry.com/2010/12/memp-php-5-3-with-fpm-and-nginx-via-macports/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 01:16:38 +0000</pubDate>
		<dc:creator>Jason Mooberry</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MacPorts]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php 5.3]]></category>
		<category><![CDATA[php-fpm]]></category>

		<guid isPermaLink="false">http://blog.jasonmooberry.com/?p=158</guid>
		<description><![CDATA[I&#8217;ve been considering diving into nginx for a bit now. Rumors of it&#8217;s speed and Cyrillic error messages have intrigued me. With recent forays into node.js apps and their requirement for a free port, I wanted to find a nice solution that complimented the evented speed of node.js without exposing a port publicly for each [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been considering diving into <a href="http://nginx.org/">nginx</a> for a bit now.  Rumors of it&#8217;s speed and Cyrillic error messages have intrigued me.  With recent forays into <a href="http://nodejs.org/">node.js</a> apps and their requirement for a free port, I wanted to find a nice solution that complimented the evented speed of node.js without exposing a port publicly for each app.  As it turns out Nginx is suited quite nicely to this.  But that wasn&#8217;t where it ended.  I found nginx to have a much more interesting and dynamic config language.  And even beyond that it gave me a good excuse to learn more about running PHP as a FastCGI process and how <a href="http://php.net/manual/en/install.fpm.php">PHP-FPM (baked in as of 5.3.3)</a> fits into the picture.  Not sure if MEMP is the correct acronym, but since I&#8217;ve seen talk of <a href="http://library.linode.com/lemp-guides/">LEMP servers</a>, I&#8217;ll run with it.</p>
<p><a href="http://www.macports.org/">MacPorts</a>.  If you&#8217;re not already familiar with it, I recommend reading up before proceeding.</p>
<p>Since I already have MySQL set up and configured I won&#8217;t bother covering it here.  It&#8217;s pretty well documented around the webs.  The main focus here is going to be getting nginx installed and setting up PHP as a service to it with an emphasis on local development.  No need to tweak this for production on my Macbook Pro.</p>
<p>PHP 5.3.3 introduced PHP-FPM (FastCGI Process Manager) to the codebase.  Building it requires a few extra config flags and generates a php-fpm binary.  The binary will manage spawning cgi processes and handling the FastCGI passthru from nginx.  Currently MacPorts does not have an option to build PHP with PHP-FPM.  After some hacking on the current Portfile I arrived at a working solution.  It includes the correct flags, a dependency on libevent, and a startup item.</p>
<p>First things first.</p>
<pre class="brush: bash">
sudo port selfupdate

# recommended but probably not a requirement
sudo port upgrade outdated
sudo port uninstall inactive
</pre>
<p>(If you&#8217;ve already got the php5 package installed, uninstall it and it&#8217;s cohorts to ensure a clean install process going forward.)</p>
<p>This is a bit of a hack and there&#8217;s probably a better way, like submitting a proper patch to MacPorts, but this will get the job done for today.</p>
<pre class="brush: bash">
# replace this file with the Portfile from the gist below
/opt/local/var/macports/sources/rsync.macports.org/release/ports/lang/php5/Portfile
</pre>
<p><a href="https://gist.github.com/724449" target="_blank">https://gist.github.com/724449</a></p>
<p>Then run the regular port install.</p>
<pre class="brush: bash">
sudo port install nginx php5 +fastcgi php5-apc php5-mysql +mysqlnd
</pre>
<p>Next we&#8217;ll need to set up the configs.  There&#8217;s two basic configs that require attention.  First is the nginx config.  Since this is just for a local development env we can be pretty lean on what we need.</p>
<pre class="brush: bash">
# /opt/local/etc/nginx/nginx.conf

worker_processes  1;

error_log  /var/log/nginx/error.log;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile           on;
    keepalive_timeout  65;

    server {
      listen 80;
      server_name   ~^local\.(?<site>.+?)\.com$;
      root  /Users/jason/Sites/$site/web;
      index  index.php index.html;

      location = /favicon.ico {
        log_not_found off;
      }

      location ~ \.php$ {
         fastcgi_pass   unix:/tmp/php-fpm.sock;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
      }
    }
}
</pre>
<p>This is the config that I&#8217;m currently using as my generic site config.  It has a few nice features.  First the server name is matched against a regular expression.  So any site that matches <code>local.xxxx.com</code> will be parsed and use the <code>xxxx</code> as a sub-directory in my Sites folder.  This is nice.  So I only need to create a new directory and add my <code>local.xxxx.com</code> domain to <code>/etc/hosts</code> pointed at <code>127.0.0.1</code> and I can immediately begin developing.  Gone are the days of creating a new v-hosts file, enabling it, and restarting apache every time I want to play with a new site&#8217;s code.  The other nicety here is we&#8217;re using a unix socket for the fastcgi passthru.  This is unnoticeably faster on my Mac, but again frees up the need to be concerned with another open port on my system. </p>
<p>It&#8217;s worth noting that any <code>fastcgi_param</code> that you define in this config is available within PHP as a <code>$_SERVER</code> variable. </p>
<p>The second config is the FPM config.  Copy <code>/opt/local/etc/php-fpm.conf.default</code> to <code>/opt/local/etc/php-fpm.conf</code> and open it up. Here are the important ones to modify:</p>
<pre class="brush: plain">
pid = /opt/local/var/run/php-fpm.pid
error_log = /opt/local/var/log/php-fpm.log
listen = /tmp/php-fpm.sock
listen.owner = _www
listen.group = _www
pm.max_children = 1
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.max_requests = 500
slowlog = /opt/local/var/log/php-fpm.log.slow
</pre>
<p>It&#8217;s pretty straight-forward.  Lean cus we can. Save and continue.</p>
<p>At this point we&#8217;ve got all the pieces in place.  We just need a way to start/stop/restart nginx and FPM.  I looked for a cleaner way to accomplish this but in the end it came down to a handful of aliases.  Add these to your <code>~/.profile</code>. </p>
<pre class="brush: bash">
# nginx
alias nginx_start='sudo launchctl load /Library/LaunchDaemons/org.macports.nginx.plist'
alias nginx_stop='sudo launchctl unload /Library/LaunchDaemons/org.macports.nginx.plist'
alias nginx_restart='nginx_stop; nginx_start;' 

# php-fpm
alias fpm_start='sudo launchctl load /Library/LaunchDaemons/org.macports.php-fpm.plist'
alias fpm_stop='sudo launchctl unload /Library/LaunchDaemons/org.macports.php-fpm.plist'
alias fpm_restart='fpm_stop; fpm_start'
</pre>
<p>Reopen the Terminal window to enable the new aliases.  Start or restart nginx and FPM as the case may be.</p>
<p>At this point you should be able to create a site directory, add a domain to <code>/etc/hosts</code> and drop in an <code>index.php</code> with <code>phpinfo();</code> to verify that PHP is working.</p>
<p>Hopefully this will be of some use to other aspiring MEMP devs out there.  I found it intensely fun.  <img src='http://blog.jasonmooberry.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jasonmooberry.com/2010/12/memp-php-5-3-with-fpm-and-nginx-via-macports/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>tunr &#8211; a puzzle game</title>
		<link>http://blog.jasonmooberry.com/2010/11/tunr-a-puzzle-game/</link>
		<comments>http://blog.jasonmooberry.com/2010/11/tunr-a-puzzle-game/#comments</comments>
		<pubDate>Fri, 05 Nov 2010 05:06:47 +0000</pubDate>
		<dc:creator>Jason Mooberry</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[puzzle]]></category>

		<guid isPermaLink="false">http://blog.jasonmooberry.com/?p=147</guid>
		<description><![CDATA[tunr is a game. It&#8217;s a simple puzzle of sorts. Imitation and pacing. I built it after a long walk through the neighborhood when I had the idea of synchronizing with simple rhythms in a computer. Most games are about speed and end up leaving you in a state of stress. tunr is about pace [...]]]></description>
			<content:encoded><![CDATA[<p>tunr is a game.  It&#8217;s a simple puzzle of sorts.  Imitation and pacing.  I built it after a long walk through the neighborhood when I had the idea of synchronizing with simple rhythms in a computer.  Most games are about speed and end up leaving you in a state of stress.  tunr is about pace and I always feel a little quieter when I play it.  The rhythms were designed to give you a rest.</p>
<p>If you&#8217;re able to finish it, you can share your score through the Facebook and Twitter buttons.</p>
<p>I sincerely hope you enjoy my simple little <a href="http://tunr.jasonmooberry.com">tunr</a>.</p>
<div style="margin-top:40px;">(For a technical breakdown on how I built tunr, see <a href="http://blog.jasonmooberry.com/2010/11/the-long-dark-tea-time-of-the-node/">The long dark tea-time of the node</a>)</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.jasonmooberry.com/2010/11/tunr-a-puzzle-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The long dark tea-time of the node</title>
		<link>http://blog.jasonmooberry.com/2010/11/the-long-dark-tea-time-of-the-node/</link>
		<comments>http://blog.jasonmooberry.com/2010/11/the-long-dark-tea-time-of-the-node/#comments</comments>
		<pubDate>Fri, 05 Nov 2010 04:52:13 +0000</pubDate>
		<dc:creator>Jason Mooberry</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[ndistro]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://blog.jasonmooberry.com/?p=91</guid>
		<description><![CDATA[Looking back I would&#8217;ve never guessed this project would have had so many twists and turns. I set out to build a game that was about synchronizing with computer generated rhythms. Ie. Make the box move at the same rhythm as a sine wave. I really liked the idea of something so simple requiring intense [...]]]></description>
			<content:encoded><![CDATA[<p>Looking back I would&#8217;ve never guessed this project would have had so many twists and turns.  I set out to build a game that was about synchronizing with computer generated rhythms.  Ie. Make the box move at the same rhythm as a sine wave.  I really liked the idea of something so simple requiring intense concentration.  It&#8217;s immersive but really really simple.  Anyways, I set out to craft this thing with some jQuery, plain js, and recursive timeouts.  At some point I thought it might be fun to track the score and even make an easy way to share your score on Twitter or Facebook.  I figured I&#8217;d make some type of nodejs app to handle the sharing and the rest could be static html pages.</p>
<p>What followed was a journey through two different types of oauth implementations, several nodejs modules and many greps through codebases to figure out how and why this worked or didn&#8217;t.  Since much of this will be useful to some other poor sap building with the same tools, I&#8217;ll outline here what I did and how it all works together.</p>
<h3>Javascript, front to back</h3>
<p><strong>Animation</strong><br />
Building the game itself took some time but was pretty straight-forward.  jQuery is extremely useful for binding events and such, but I tried to use bare js inside the loops for efficiency.  Since I&#8217;m not using canvas here, just manipulating positions of dom objects, it&#8217;s fairly processor intensive.  With that said Chrome and Safari handle it with ease.  Firefox will make your processor fan spin up.</p>
<p>The core of the animation stuff is variations on this simple recursive timeout:</p>
<pre class="brush:js">
block = $('#block');
move_timeout = null;
(function send_it_down() {
  move_timeout = setTimeout(function() {
    block.css('top',block.css('top')+1);
    send_it_down();
  },30);
})();
// to stop animation
// clearTimeout(move_timeout);
</pre>
<p>jQuery has some nice animation functionality but it&#8217;s all based on a fixed time of execution in which each step&#8217;s timeout is based on the amount of steps to execute and the total time for the animation to run.  Rolling my own animation code allowed me to control an infinitely executing constant speed animation.</p>
<p>The <a href="http://api.jquery.com/">jQuery api docs</a> and <a href="http://www.w3schools.com/jsref/default.asp">w3schools js ref</a> got me through anything tricky and <a href="http://mathworld.wolfram.com/Nephroid.html">Wolframs Mathworld</a> was the key to the color game (intially it was a spirograph pattern, then a simpler nephroid, finally a circle).</p>
<p><strong>OAuth</strong><br />
First thing&#8217;s first.  What is <a href="http://oauth.net/">OAuth</a> and how do I use it?  In order to make sharing your score easy I had to write an app that interfaced with both <a href="http://dev.twitter.com/doc">Twitter</a> and <a href="http://developers.facebook.com/docs/">Facebook&#8217;s</a> apis.  I heard Twitter was simpler and their docs were better so I started there.  A link in the twitter docs to this <a href="http://hueniverse.com/oauth/">Oauth Guide</a> made for an easy introduction.  Twitter is currently using an OAuth 1.0 implementation that is pretty true to what you would expect after reading the guide.  The only difference was that Twitter seems to store your callback url for you on your request token call so you don&#8217;t need to supply it on your auth token call.  Facebook has an OAuth 2.0 implementation that requires ssl and has fewer steps.  The only catch on Facebook is they&#8217;re sticklers for your callback url.  It must be present in both your authorize call as well as your auth token call and it must match exactly.  </p>
<p>Now that I know what OAuth is and have a basic understanding of how to interface with Twitter and Facebook&#8217;s apis, I searched out an OAuth module for nodejs.  </p>
<p><strong>Nodejs</strong><br />
I found some buzz around <a href="http://github.com/ciaranj/node-oauth">Ciaranj&#8217;s node-oauth</a> and found it to a pretty good wrapper for the functionality I would need.  It&#8217;s lacking a way to make POST requrests in the OAuth2 code, but writing my own wasn&#8217;t too tough.  I had my eye on <a href="http://expressjs.com/">Expressjs</a> as a framework for building http handlers for this app.  It&#8217;s a sweet little implementation with a very simple premise and good docs.  For my datastore I decided to take another crack at <a href="http://www.mongodb.org/">MongoDB</a>.  I&#8217;ve built PHP apps that interfaced with Mongo but nothing with nodejs yet.  </p>
<p>So far Nodejs has been a great tool for ad hoc api clients and prototypes.  This is the first server app I&#8217;ve written with nodejs.  A few things I noticed that were unexpected.  One, nesting callbacks can become tedious.  This was especially true with the MongoDB module.  I don&#8217;t see any way to get around it, but it&#8217;s ugly.  The other thing was that error handling with callbacks is much different than exception handling within a single thread of execution.  Wrap anything with a callback in a try/catch and you&#8217;ll see it&#8217;s useless.  So becoming expectant on an onError() method for all of the connections is the norm.  </p>
<p>Other challenges with nodejs included: since my nodejs app is listening on a different port than my html pages are being served from, I had to do some extra redirection at the end of my OAuth process so that my final landing page of my popup would be able to call back to the main window and trigger a success event.  And any exception that I didn&#8217;t catch takes down my app completely.  </p>
<p>With that aside I was able to craft a sweet little app in less than a couple hundred lines that is fast and easy.  I can manage the sharing process with a couple ajax calls and a bind to my custom success event.</p>
<p><strong>nDistro</strong><br />
Installing nodejs modules can be done a few different ways.  Initially I was using <a href="http://npmjs.org/">npm</a>.  It worked ok but since it installs to a central npm repository, and nodejs and it&#8217;s modules version so quickly, it made more sense to use <a href="http://github.com/visionmedia/ndistro">nDistro</a>.  It allows you to manage your nodejs versions as well as your module versions from a simple config file.  This is super useful since I can literally break my app with the wrong version.  </p>
<p>I found one oddity using nDistro to install <a href="http://github.com/christkv/node-mongodb-native">MongoDB&#8217;s node module</a>.  If you compile the C version of the BSON parser and intend to use it with your code, it will not be available.  The reason for this is that nDistro symlinks each module to a common lib/node directory.  There is a relative path that is broken in one of mongodb&#8217;s require statements for including the compiled BSON parser.  I was able to fix this by setting up a symlink in the lib directory.  Another issue with the MongoDB module is that in order to compile the native BSON parser you need to have a full nodejs install with the node-waf binary in an available path.  The node binary installed by nDistro is not sufficient.  After all of this I had errors compiling BSON on my vps that were not on my mac..  The js parser will work fine given the size of my records.</p>
<p><strong>MongoDB</strong><br />
<a href="http://www.mongodb.org/">MongoDB</a> showed up on my radar over a year ago and since then it&#8217;s gotten easier to use and more reliable.  The 10gen developers have put a lot of effort into building good libraries in many languages to interface with MongoDB.  With the <a href="http://groups.google.com/group/mongodb-user/browse_thread/thread/528a94f287e9d77e">postmortem</a> after <a href="http://blog.foursquare.com/2010/10/05/so-that-was-a-bummer/">FourSquare&#8217;s recent outage</a>, I got a little window into the scale that mongo seems to be handling well.  FTA the outage was due to overactivity in one of the shards that was running too close to memory capacity.  Given that FourSquare is running multiple 66GB RAM EC2 mongodbs and they just hit their <a href="http://blog.foursquare.com/2010/10/06/quite-the-way-to-celebrate-our-200-millionth-check-in/">200 millionth checkin</a> I am confident that my 2 dozen friend&#8217;s tweet/post counts will be handled with grace and speed.  <img src='http://blog.jasonmooberry.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Installing MongoDB is pretty much a matter of unzipping a tgz and running mongod from the command line.  </p>
<h3>Putting it all together</h3>
<p>This post has been short on code snippets cus I&#8217;m hosting the entire codebase at the <a href="https://github.com/jasonmoo/tunr">Github</a>.  This is my first run at a nodejs app with mongo running live and I am curious to see how stable everything is.  My new linode server is purring like a kitten with anything I throw at it.  Hopefully the tunr app continues the trend.  </p>
<p>Oh and you can <a href="http://tunr.jasonmooberry.com">play tunr here</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jasonmooberry.com/2010/11/the-long-dark-tea-time-of-the-node/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.227 seconds -->

