<?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>Blog - ShiftEleven</title>
	<atom:link href="http://shifteleven.com/feed" rel="self" type="application/rss+xml" />
	<link>http://shifteleven.com</link>
	<description></description>
	<lastBuildDate>Mon, 09 Jan 2012 04:04:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Mouse Clicks for HTML5 Cavas Entities via Paths</title>
		<link>http://shifteleven.com/articles/2012/01/08/mouse-clicks-for-html5-cavas-entities-via-paths?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mouse-clicks-for-html5-cavas-entities-via-paths</link>
		<comments>http://shifteleven.com/articles/2012/01/08/mouse-clicks-for-html5-cavas-entities-via-paths#comments</comments>
		<pubDate>Mon, 09 Jan 2012 04:04:19 +0000</pubDate>
		<dc:creator>K. Adam Christensen</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://shifteleven.com/?p=138155</guid>
		<description><![CDATA[The canvas element in HTML5 is exciting because it really opens the doors to games, drawing, and animation. This is especially exciting as browsers hardware accelerate canvas and improve its performance. What isn&#8217;t so exciting though is that you do &#8230; <a href="http://shifteleven.com/articles/2012/01/08/mouse-clicks-for-html5-cavas-entities-via-paths">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <code>canvas</code> element in HTML5 is exciting because it really opens the doors to games, drawing, and animation. This is especially exciting as browsers <a title="Unleash the Power of Hardware-Accelerated HTML5 Canvas" href="http://www.htmlgoodies.com/html5/client/unleash-the-power-of-hardware-accelerated-html5-canvas.html">hardware accelerate canvas</a> and improve its performance. What isn&#8217;t so exciting though is that you do have to do a lot more for yourself.</p>
<p>So if you draw something into the canvas, you don&#8217;t get to attach event listeners on the objects you create within the canvas, just on the canvas itself. This means that you have to build your own event system. This isn&#8217;t that difficult if you organize your entities you&#8217;re drawing and rely on&nbsp;<a href="http://www.w3.org/TR/2dcontext/#dom-context-2d-ispointinpath"><code>isPointInPath</code></a> to do the searching for you.</p>
<section>
<h2>Overview</h2>
<p>When you use path methods, like <code>arc</code>, <code>bezierCurveTo</code>, or <code>lineTo</code>, the 2D context keeps track of things really nicely for you. After you add your path, you can ask the context whether or not a point is within the area of said path via the <code>isPointInPath</code> method.</p>
<p>The way to find the object is to render each entity in <strong>reverse</strong> order, draw the path, and then check to see <code>isPointInPath</code>. The reason to go in reverse order is because the most visible, unobstructed object is at the last index in the rendering order.</p>
<p>Paths are great because they are fast, but they are pretty plain. What you if you want to draw images? Well there&#8217;s no rule that you can only use one canvas. This means that you can use one canvas to draw your main stage with images, and then use the light-weight paths to draw the hit detection area.</p>
<p>The <a href="http://shifteleven.com/demo/canvas-hit-detection/">demo</a> will draw the earth and the moon and will print a the name of the selected planet.</p>
</section>
<p><span id="more-138155"></span></p>
<section>
<h2>The Planet Entity Class</h2>
<p>Since we want to manage two different rendering passes, our entity class will have two methods. One to draw the visible image and the other to render the hit detection path.</p>
<pre class="sh_javascript">/**
 * Planet.
 *
 * A planet entity to draw on a canvas.
 */
Planet = function(image, opt_x, opt_y) {
  this.image_ = image;
  this.x_ = opt_x || 0;
  this.y_ = opt_y || 0;
};
/**
 * Draw the planet.
 */
Planet.prototype.draw = function(ctx) {
  ctx.drawImage(this.image_, this.x_, this.y_);
};
/**
 * Draw the hit detection path.
 */
Planet.prototype.drawDetectionPath = function(ctx) {
  ctx.beginPath();
  var radius = this.image_.width / 2;
  ctx.arc(this.x_+radius, this.y_+radius, radius, 0, Math.PI*2, true);
  ctx.closePath();
};</pre>
<p>The <code>drawDetectionPath</code> method draws a circle, which is a pretty good hit detection area for a planet. One thing to note, the path has no fill style nor does it call <code>fill</code>. This is because we&#8217;re not making it visible, we just want the path information.</p>
</section>
<section>
<h2>The Entity Manager</h2>
<p>The entity manager is pretty simple too. The entity manager keeps a list of all the planets to draw. It also performs the logic of trying to identify the entity that exists at an X,Y position in the canvas.</p>
<pre class="sh_javascript">/**
 * Entities Manager.
 *
 * Manage a set of entities to draw them to the screen and to
 * detect mouse hits.
 */
EntitiesManager = function(entities, rendererCtx, detectionCtx) {
  this.entities_ = entities;
  this.rendererCtx_ = rendererCtx;
  this.detectionCtx_ = detectionCtx;
};
EntitiesManager.prototype.draw = function() {
  this.rendererCtx_.clearRect(0, 0, this.rendererCtx_.canvas.width,
                              this.rendererCtx_.canvas.height);
  for (var i = 0; i &lt; this.entities_.length; i++) {
    this.entities_[i].draw(this.rendererCtx_);
  }
};
EntitiesManager.prototype.findEntity = function(x, y) {
  // Clear out the detection canvas.
  this.detectionCtx_.clearRect(0, 0, this.detectionCtx_.canvas.width,
                               this.detectionCtx_.canvas.height);
  // Loop backwards though each entity. After drawing it onto
  // the detection canvas, see if X,Y coordinates from the mouse are
  // within the path drawn onto the canvas.
  for (var i = this.entities_.length-1; i &gt;= 0; i--) {
    var entity = this.entities_[i];
    entity.drawDetectionPath(this.detectionCtx_);
    if (this.detectionCtx_.isPointInPath(x, y)) {
      return entity;
    }
  }
  return null;
};</pre>
<p>To use this class, simply make a new instance of this and pass along an array of planets and the 2 2D canvas context objects. To draw or refresh the display, simply call <code>draw</code>. After you receive a click event on the render canvas, you can pass in the X,Y coordinates into <code>findEntity</code> to see if there are any objects underneath that position. That being said, there&#8217;s a little massaging that needs to happen on the coordinates&nbsp;from the mouse click.</p>
</section>
<section>
<h2>Getting the Mouse Position</h2>
<p>When you listen for the click event on the canvas object, the callback will receive an Event object which will have the X,Y position of the coordinates of where the click happened. The problem with just using those X,Y coordinates are that they aren&#8217;t in the same coordinate space as the coordinate space of the canvas context. Awesomely enough, it&#8217;s easy to rectify. You need to get the coordinates of the mouse click and then subtract the coordinates of top,left point of the canvas element.</p>
</section>
<pre class="sh_javascript">canvasElement.addEventListener('click', function(evt) {
  var rect = renderer.getBoundingClientRect();
  var x = evt.clientX - rect.left;
  var y = evt.clientY - rect.top;

  var entity = entitiesManager.findEntity(x, y);
  // ...
});</pre>
<section>
<h2>About The Demo</h2>
<p>The basics of this code are viewable at <a title="Demo" href="http://shifteleven.com/demo/canvas-hit-detection/">shifteleven.com/demo/canvas-hit-detection/</a>. While it is pretty much the same code that&#8217;s in this blog post, there are a couple of interesting bits to discus.</p>
<h3>Image Manager</h3>
<p>I&#8217;m using images for the earth and the moon. So before I can start drawing with those images, I need to make sure that they are downloaded first. To that end, I use an <code>ImageManager</code> class to download everything and fire a callback when it&#8217;s finished. It&#8217;s not terribly robust, but it gets the job done for the demo.</p>
<h3>Transform Decorator</h3>
<p>To show the performance impact of how many planets are drawn onto the canvas, I needed to draw them in random places and to scale them at different sizes. Rather than adding the transform properties into the <code>Planet</code> entity class, I used a <a href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator</a> to do that dirty work for me. I also only end up making 2 planet instances (one for the earth, the other the moon).</p>
<h3>Performance</h3>
<p>Take it easy before trying to render 100,000 planets onto the canvas as this could take a while. That being said, once you do render all of the planets, notice how fast it is for it to actually find the planet! Paths are pretty fast!<br />
</section>
<script type="text/javascript" src="/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js"></script><script type="text/javascript" src="/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js"></script><script type="text/javascript" src="/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js"></script>]]></content:encoded>
			<wfw:commentRss>http://shifteleven.com/articles/2012/01/08/mouse-clicks-for-html5-cavas-entities-via-paths/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Octave on OSX with MacPorts</title>
		<link>http://shifteleven.com/articles/2011/11/06/installing-octave-on-osx-with-macports?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=installing-octave-on-osx-with-macports</link>
		<comments>http://shifteleven.com/articles/2011/11/06/installing-octave-on-osx-with-macports#comments</comments>
		<pubDate>Sun, 06 Nov 2011 18:53:27 +0000</pubDate>
		<dc:creator>K. Adam Christensen</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://shifteleven.com/?p=60906</guid>
		<description><![CDATA[Most of the time, installing things with MacPorts is pretty easy; however, I have found that GNU Octave can be a little tricky. That being said, it&#8217;s still pretty easy to get Octave up and running in both Snow Leopard &#8230; <a href="http://shifteleven.com/articles/2011/11/06/installing-octave-on-osx-with-macports">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Most of the time, installing things with <a href="http://www.macports.org/">MacPorts</a> is pretty easy; however, I have found that <a href="http://www.gnu.org/software/octave/">GNU Octave</a> can be a little tricky. That being said, it&#8217;s still pretty easy to get Octave up and running in both Snow Leopard and Lion.</p>
<p>At the time of this post, here&#8217;s two version of Octave to choose from: <code>octave</code> (version 3.2.4) and <code>octave-devel</code> (version 3.4.3). For my money, I like <code>octave-devel</code>. In my brief testing with the two, the biggest difference for me was that the graphs plotted in <code>octave-devel</code> looked more like their OS counterparts. With <code>octave</code>, I found the scaling of elements on the graph to be different sizes and that bugged me.</p>
<p>To install Octave, run the following from the <a href="http://www.youtube.com/watch?v=YCsTKUmQFso">terminal</a>:</p>
<pre>sudo port install octave-devel +gcc45</pre>
<p>And then wait&#8230;as there are a lot of things that need being compiled.</p>
<p>I added the <code>gcc45</code> <a href="http://guide.macports.org/chunked/using.variants.html">variant</a> because one of the dependencies, <code>atlas</code>, needs <code>gcc45</code> to compile. This ensures that both of those are in sync.</p>
<h2><span class="Apple-style-span" style="color: #333333; font-weight: 300;">Feel free to add other variants if you like, like X11 support or offline documentation. To get a full list, run:</span></h2>
<pre>port variants octave-devel</pre>
<p><span id="more-60906"></span></p>
<section>
<h2>Plotting</h2>
<p>When you install Octave via MacPorts, <a href="http://sourceforge.net/projects/aquaterm/">AquaTerm</a> also gets installed. AquaTerm is basically a vector renderer which Octave can use to plot its graphs. I like AquaTerm because the graphs look really smooth and nice, like you would expect on a Mac :)</p>
<p>If you have installed the X11 variant, you can also choose to do the rendering from within X11. The way you control this is through the environment variable, <code>GNUTERM</code>.</p>
<p>Set <code>GNUTERM</code> to <code>x11</code> when you want to do your graphing in X11 and set <code>GNUTERM</code> to <code>aqua</code> when you want to do your graphing in AquaTerm. You can read more about <a href="http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x">setting environment variables on StackOverflow</a>.</p>
<p>If you are running Octave and wish to change the <code>GNUTERM</code> there, you can do so with the <code>setenv</code> function, like so.</p>
<pre>&gt;&gt; % Create some sample data
&gt;&gt; x = [-4 -2 0 2 4 6 8];
&gt;&gt; y = x .^ 2;
&gt;&gt;
&gt;&gt; % Plot X in X11.
&gt;&gt; setenv("GNUTERM", "x11");
&gt;&gt; plot(x, y);
&gt;&gt;
&gt;&gt; % Plot X in AquaTerm.
&gt;&gt; setenv("GNUTERM", "aqua");
&gt;&gt; plot(x, y);</pre>
<p>With this, you can also compare the different rendering apps and discover which one you like more.</p>
</section>
]]></content:encoded>
			<wfw:commentRss>http://shifteleven.com/articles/2011/11/06/installing-octave-on-osx-with-macports/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Aliases with Google Closure</title>
		<link>http://shifteleven.com/articles/2011/08/25/aliases-with-google-closure?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=aliases-with-google-closure</link>
		<comments>http://shifteleven.com/articles/2011/08/25/aliases-with-google-closure#comments</comments>
		<pubDate>Thu, 25 Aug 2011 23:28:18 +0000</pubDate>
		<dc:creator>K. Adam Christensen</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[google closure]]></category>

		<guid isPermaLink="false">http://shifteleven.com/?p=937</guid>
		<description><![CDATA[I&#8217;m starting to use the closure library and all of it. The closure compiler is nice because it can compress your JS code down, a LOT. In order to get the biggest bang for your buck. you want to use &#8230; <a href="http://shifteleven.com/articles/2011/08/25/aliases-with-google-closure">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m starting to use the <a title="Google Closure" href="http://code.google.com/closure/">closure library</a> and all of it. The <a title="Google Closure Compiler" href="http://code.google.com/closure/compiler/">closure compiler</a> is nice because it can compress your JS code down, a LOT. In order to get the biggest bang for your buck. you want to use the <a title="Advanced Compilation and Externs" href="http://code.google.com/closure/compiler/docs/api-tutorial3.html">advanced optimization</a> settings. It can eliminate unused code, inline functions, and rename variables.</p>
<p>In order for variable renaming to work, you have to behave by closure&#8217;s rules. One rule closure has is: Let me do the optimization. One of the main reasons for this is that some shortcuts can make it hard to determine your intent.</p>
<p>One shortcut I like to use is to create alias to JavaScript objects that have long names or long <a title="JavaScript Namespaces" href="http://elegantcode.com/2011/01/26/basic-javascript-part-8-namespaces/">namespaces</a>.</p>
<pre class="sh_javascript">(function() {
  var alias = a.very.long.namespace;
  /** @constructor */
  alias.NewClass = function() {};
})();</pre>
<p>Now, to you are I, we can easily tell that I intend to use this self-calling anonymous function as a closure to store my alias; however, how can a compiler know that this was my <em>intent</em>.</p>
<p>Intent is a key concept when you work with the advanced compilation. In the above example, Closure knows that <code>a.very.long.namespace.NewClass</code> is even a class because of the <code>constructor</code> annotation. The way to tell Closure that you intend to make aliases is by using the <code><a title="goog.scope Documentation" href="http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.html#goog.scope">goog.scope</a></code> function<a href="#fn-1"><sup>1</sup></a>.</p>
<pre class="sh_javascript">goog.require('goog.dom');
goog.require('goog.events');
goog.require('goog.events.EventType');

goog.scope(function() {
  var dom = goog.dom;
  var events = goog.events;
  var EventType = goog.events.EventType;

  var elem = dom.getElement('myElement');
  events.addEventListener(elem, EventType.CLICK, function() {
    alert('I was clicked');
  });
});</pre>
<p><span id="more-937"></span></p>
<section>
<h2>Behind the Scenes</h2>
<p>So what does Closure do with this info? Well, if your code is not compiled, nothing :) The implementation of <code>goog.scope</code> will just call the function that was passed in as an argument. Now if you took the time to even investigate aliasing, then you probably care about what happens when you run the code through the compiler.</p>
<p>The compiler will actually expand all of your aliased variables into their fully qualified path in one of the compiler passes through the code before sending it to other passes. Think of it as a preprocessing step.</p>
<h3>Caveats</h3>
<p>Since <code>goog.scope</code> is a special function, you should know that it has special rules that you need to follow. They are pretty easy and you probably won&#8217;t run into them unless you&#8217;re doing something sneaky.</p>
<ul>
<li><strong>You&#8217;re not allowed to use <code>this</code></strong>. If you mean to use window here, just use <code>goog.global</code>.</li>
<li><strong>All local variables need to be references to other namespaces or classes</strong>. This is good because it helps you catch potential errors where you made a new variable at that scope when you shouldn&#8217;t have.</li>
<li><strong>You can only assign an alias name once</strong>. This helps avoid bugs too because if you try to reassign a value to an alias, the change won&#8217;t be available when you leave that scope.</li>
<li><strong>You cannot throw an exception from <code>goog.scope</code></strong>. Now you can throw the exception from a function inside of scoping function.</li>
<li><strong>You cannot return a value nor assign <code>goog.scope</code> to anything</strong>. This makes sense because if you&#8217;re assigning and returning, you&#8217;re doing something more than just aliasing and the compiler won&#8217;t be able to figure out what the hell you&#8217;re doing.</li>
</ul>
</section>
<section>
<h2>Conclusion</h2>
<p>To get the biggest bang for your buck out of the Closure compiler, you sometimes need to give it hints about what you intend to do. <code>goog.scope</code> is just one of those ways that you can provide it with some extra context so that it can do its job better. This extra bit of metadata can also help you do your job better too because the Closure compiler will be able to message you about errors when it sees a mismatch between what you intend to be doing, and what you&#8217;re actually doing.</p>
<p>If you would like to read more about the <code>goog.scope</code> proposal and action plan, check out the <a title="Making Closure less verbose with goog.scope" href="https://docs.google.com/document/pub?id=1ETFAuh2kaXMVL-vafUYhaWlhl6b5D9TOvboVg7Zl68Y">implementation document</a>. It also outlines other options considered for solving the aliasing problem and why they were less ideal. Also, feel free to investigate the <a title="ScopedAliases.java Source Code" href="http://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/javascript/jscomp/ScopedAliases.java">compiler source code for <code>goog.scope</code></a>.</p>
</section>
<section>
<h3>Footnotes</h3>
<ol>
<li id="fn-1"> Yes, I know that you can do this with jQuery simply as <code>$('#myElement').click(function() { alert(...); });</code> :p</li>
</ol>
</section>
<script type="text/javascript" src="/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js"></script><script type="text/javascript" src="/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_javascript.js"></script>]]></content:encoded>
			<wfw:commentRss>http://shifteleven.com/articles/2011/08/25/aliases-with-google-closure/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Snow Leopard and ZendServer CE 4.0.5</title>
		<link>http://shifteleven.com/articles/2009/09/19/snow-leopard-and-zendserver-ce-4-0-5?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=snow-leopard-and-zendserver-ce-4-0-5</link>
		<comments>http://shifteleven.com/articles/2009/09/19/snow-leopard-and-zendserver-ce-4-0-5#comments</comments>
		<pubDate>Sat, 19 Sep 2009 11:19:14 +0000</pubDate>
		<dc:creator>K. Adam Christensen</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snowleopard]]></category>
		<category><![CDATA[watchdog]]></category>
		<category><![CDATA[zendserver]]></category>

		<guid isPermaLink="false">http://shifteleven.com/?p=222</guid>
		<description><![CDATA[So I&#8217;m all upgraded onto the new Snow Leopard and I wanted to see what ZendServer CE was all about.  Well, unfortunately, when I try to run it, I see watchdog errors when I try to start the Java Bridge &#8230; <a href="http://shifteleven.com/articles/2009/09/19/snow-leopard-and-zendserver-ce-4-0-5">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m all upgraded onto the new Snow Leopard and I wanted to see what <a title="ZendServer CE" href="http://www.zend.com/en/products/server-ce/">ZendServer CE</a> was all about.  Well, unfortunately, when I try to run it, I see <a href="http://forums.zend.com/viewtopic.php?f=44&amp;t=1115">watchdog errors when I try to start the Java Bridge and Lighttpd</a>.  Some have updated the <a href="http://forums.zend.com/viewtopic.php?f=44&amp;t=1115&amp;start=10#p7605">lighttpd service script to not use watchdog</a> (which still hoses the JavaBridge), while others tried to <a href="http://www.thisismobility.com/blog/2009/09/02/zend-server-community-edition-vs-snow-leopard/">create a new zend user</a>.  What worked for me was to <a href="http://forums.zend.com/viewtopic.php?f=44&amp;t=1115&amp;start=30#p8304">replace the watchdog application</a>.  After doing that, everything worked fine and I didn&#8217;t have to modify the lighttpd script or create a zend user.</p>
<p>Now that I have that done, I get to play around to see what all the buzz is about.</p>
]]></content:encoded>
			<wfw:commentRss>http://shifteleven.com/articles/2009/09/19/snow-leopard-and-zendserver-ce-4-0-5/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Managing Vim Scripts with a Vimball</title>
		<link>http://shifteleven.com/articles/2009/05/21/managing-vim-plugins-with-a-vimball?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=managing-vim-plugins-with-a-vimball</link>
		<comments>http://shifteleven.com/articles/2009/05/21/managing-vim-plugins-with-a-vimball#comments</comments>
		<pubDate>Fri, 22 May 2009 03:38:27 +0000</pubDate>
		<dc:creator>K. Adam Christensen</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Version Control]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[vimball]]></category>

		<guid isPermaLink="false">http://shifteleven.com/?p=214</guid>
		<description><![CDATA[I am a vim user.  The thing I like about vim is it&#8217;s speed, how universal it is, and it&#8217;s customizations.  These customizations can come in the form of plugins, syntax files, compilers, and code completion utilities; all of which &#8230; <a href="http://shifteleven.com/articles/2009/05/21/managing-vim-plugins-with-a-vimball">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am a <a href="http://www.vim.org">vim</a> user.  The thing I like about vim is it&#8217;s speed, how universal it is, and it&#8217;s customizations.  These customizations can come in the form of plugins, syntax files, compilers, and code completion utilities; all of which are <a href="http://www.vim.org/scripts/index.php">scripts</a>.  Scripts can be a single file like <a href="http://vim.sourceforge.net/scripts/script.php?script_id=159">MiniBufExplorer</a> or can encompass multple files like <a href="http://www.vim.org/scripts/script.php?script_id=1213">vjde</a>.</p>
<p>Single file scripts are fairly easy to manage.  If you notice a new version of your script is released, then simply replace your file with the new version.  Likewise, it&#8217;s very easy to remove the script if you want to just try it out.  However, scripts spanning multiple files are much harder to manage.  For one, the script&#8217;s files get merged in with all of your other script files.</p>
<p>To help know what files are apart of what plugin, I manage <a href="http://github.com/pope/personal/tree/master">my vim scripts in git</a>.  Another way to keep track of things is to use a <a href="http://vimdoc.sourceforge.net/htmldoc/pi_vimball.html">vimball</a>.</p>
<h3>What Are Vimballs?</h3>
<p>Vimballs are essential vim script installers.  Each vimball contains all of the files that are needed for the script to work.  Not only that, but it also has a hook for you to easily uninstall the script as well.</p>
<p><a href="http://www.vim.org/scripts/script.php?script_id=1714">Tail Bundle</a> is a script that mimics <code>tail -f</code> for vim.  The downloadable artifact is a vba file.  That file is the vimball.  To actually install the file:</p>
<ol>
<li><code>vim tail-03.vba</code></li>
<li><code>:so %</code></li>
<li><code>:q</code></li>
</ol>
<p>So what that all means is that you&#8217;re opening the vimball in vim.  From there, you&#8217;re executing the instructions that are in the file.  Lastly, you&#8217;re just quitting.  You see, a vimball is a vim script in of itself.  So executing it writes everything out to where it&#8217;s supposed to go.</p>
<p>While the tail bundle makes use of the vimball, not every script does.  Luckily, it&#8217;s easy to make vimballs out of most script downloads.<br />
<span id="more-214"></span></p>
<h3>Converting Scripts to a Vimball</h3>
<p>In order to make a vimball, it&#8217;s quite easy. List out all of the files you want to include in your bundle, relative to where your current directory is.  For instance:</p>
<pre>doc/myawesomeplugin.txt
plugin/myawesomeplugin.vim
syntax/myawesomeplugin.vim</pre>
<p>Next thing, while in visual mode, type <code>ggVG:MkVimball myawesomeplugin</code>.  The <code>ggVG</code> is a akin to doing a &#8220;select all&#8221;.</p>
<p>This will create your install file named myawesomeplugin.vba.  Now just install it like any other vimball.</p>
<p>You don&#8217;t have to just make vimballs for your own scripts.  I love <a href="http://www.vim.org/scripts/script.php?script_id=2611">xpt</a>, but there are so many files to manage.  Well, you can make the vimball script even when the author does not.</p>
<p>Open a new buffer and use the command <code>:r! find . -type f</code>.  This will find all of the files and print them out into the buffer.  If you want to do any cleanup, like remove blank lines and removing the extra <code>./</code> before each entry, feel free to do so.  Now that you easily got a list of all the files, create the vimball from that.</p>
<p>Now you have records of what went in with the script and you have a super easy way of uninstalling the script too.  Speaking of which&#8230;</p>
<h3>Removing Scripts</h3>
<p>To remove a vimball script, simply execute <code>:RmVimball myawesomeplugin</code>.  That will go through and delete all files created by the plugin.</p>
<p>After figuring this out, I now know that when I want to use and install vim scripts, I&#8217;m going to do so via vimballs.  It&#8217;s too easy not to, and the benefit of having a way to back-out scripts is just too tempting.</p>
]]></content:encoded>
			<wfw:commentRss>http://shifteleven.com/articles/2009/05/21/managing-vim-plugins-with-a-vimball/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Fun with Smart Playlists in iTunes</title>
		<link>http://shifteleven.com/articles/2009/03/08/fun-with-smart-playlists-in-itunes?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fun-with-smart-playlists-in-itunes</link>
		<comments>http://shifteleven.com/articles/2009/03/08/fun-with-smart-playlists-in-itunes#comments</comments>
		<pubDate>Sun, 08 Mar 2009 19:23:57 +0000</pubDate>
		<dc:creator>K. Adam Christensen</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://shifteleven.com/?p=210</guid>
		<description><![CDATA[I use iTunes for managing my music, mostly because I have to or my iPod and iPhone don&#8217;t place nice.  One of my favorite features is the smart playlists.  So when I want a play list of cover songs, I &#8230; <a href="http://shifteleven.com/articles/2009/03/08/fun-with-smart-playlists-in-itunes">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://shifteleven.com/wp-admin/edit.php">iTunes</a> for managing my music, mostly because I have to or my iPod and iPhone don&#8217;t place nice.  One of my favorite features is the <a href="http://www.apple.com/itunes/tutorials/#playlists-smartplaylists">smart playlists</a>.  So when I want a play list of cover songs, I don&#8217;t manually create a playlist, I use this feature to create the playlist for me.</p>
<p><span id="more-210"></span></p>
<p>Say I want a playlist of cover songs.  What I will do is add a comment of &#8220;<strong>&amp;cover</strong>&#8221; directly in the track info.</p>
<p><img class="aligncenter size-full wp-image-211" title="cover-song-info" src="http://shifteleven.com/wp-content/uploads/2009/03/cover-song-info.png" alt="cover-song-info" width="580" height="534" /></p>
<p>The reason I chose to use an <strong>&amp;</strong> in front of the tag is so two fold.  One, so if you have a comment talking about the album cover, it wouldn&#8217;t get added to the list.  If you don&#8217;t like the <strong>&amp;</strong>, leave it our or use your own.</p>
<p>Once I have done that to all of my songs, I create a new playlist with the following settings:</p>
<p><img class="aligncenter size-full wp-image-212" title="smart-playlist-cover" src="http://shifteleven.com/wp-content/uploads/2009/03/smart-playlist-cover.png" alt="smart-playlist-cover" width="656" height="251" /></p>
<p>And now I have my playlist.  The benefit to this is that if I move this song to another computer, say my work desktop, I can easily re-create the playlist.</p>
<p>One last thing.  If you find yourself using this, or wanting to use this, a lot, check out <a href="http://blog.seanmcg.com/?page_id=116">Quick Tag</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shifteleven.com/articles/2009/03/08/fun-with-smart-playlists-in-itunes/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Useless Ruby Tricks: DATA and __END__</title>
		<link>http://shifteleven.com/articles/2009/02/09/useless-ruby-tricks-data-and-__end__?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=useless-ruby-tricks-data-and-__end__</link>
		<comments>http://shifteleven.com/articles/2009/02/09/useless-ruby-tricks-data-and-__end__#comments</comments>
		<pubDate>Tue, 10 Feb 2009 03:20:17 +0000</pubDate>
		<dc:creator>K. Adam Christensen</dc:creator>
				<category><![CDATA[Ruby off Rails]]></category>
		<category><![CDATA[DATA]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[__END__]]></category>

		<guid isPermaLink="false">http://shifteleven.com/?p=207</guid>
		<description><![CDATA[So maybe not totally useless certainly fun. Normally, ruby scripts are finished when you reach the end of a file; however, this is not always the case. You can end your script sooner by using the __END__ keyword in your &#8230; <a href="http://shifteleven.com/articles/2009/02/09/useless-ruby-tricks-data-and-__end__">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So maybe not totally useless certainly fun.  Normally, ruby scripts are finished when you reach the end of a file; however, this is not always the case.  You can end your script sooner by using the <code>__END__</code> keyword in your script.  Once added, everything you type after that will not be parsed by ruby.</p>
<p>So what?</p>
<p>Well, you can use the global variable <code>DATA</code> to get the contents of what you  wrote after the <code>__END__</code> block.  <code>DATA</code> is actually a <code>File</code> object to just that piece of text in your script.</p>
<p><span id="more-207"></span></p>
<p>How about a little sample to make things a little clearer?</p>
<pre class="ruby" title="code">#!/usr/bin/env ruby
%w(yaml pp).each { |dep| require dep }

obj = YAML::load(DATA)

pp obj

__END__
---
-
  name: Adam
  age: 28
  admin: true
-
  name: Maggie
  age: 28
  admin: false</pre>
<p>So with this, I was able to embed a little bit of YAML directly into my script.  I added the YAML after <code>__END__</code>.  <code>YAML::load</code> will accept a <code>File</code> object, so I just passed it <code>DATA</code> and now I have a reconstituted array.</p>
<p>Maybe that&#8217;s not the most practical use of this information; however, <a href="http://www.sinatrarb.com/">Sinatra</a> provides a really awesome use of this.  With Sinatra, you can create a whole web application that lives in one single, solitary ruby file.  Sinatra can use in-file templates.  In-file templates are added into the space after <code>__END__</code> where each view file is annotated with <code>@@view_name</code>.</p>
<pre class="ruby" title="code">require 'rubygems'
require 'sinatra'

get '/' do
  haml :index
end

__END__

@@ layout
%html
  = yield

@@ index
%div.title Hello world!!!!!</pre>
<p>Not bad for a useless trick!</p>
]]></content:encoded>
			<wfw:commentRss>http://shifteleven.com/articles/2009/02/09/useless-ruby-tricks-data-and-__end__/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Converting ERB to HAML snippet</title>
		<link>http://shifteleven.com/articles/2008/06/08/converting-erb-to-haml-snippet?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=converting-erb-to-haml-snippet</link>
		<comments>http://shifteleven.com/articles/2008/06/08/converting-erb-to-haml-snippet#comments</comments>
		<pubDate>Sun, 08 Jun 2008 22:45:39 +0000</pubDate>
		<dc:creator>K. Adam Christensen</dc:creator>
				<category><![CDATA[Ruby off Rails]]></category>
		<category><![CDATA[erb]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://shifteleven.com/?p=80</guid>
		<description><![CDATA[I&#8217;m playing around with merb so I&#8217;m using merb-gen to create some basic scaffolding; however, I&#8217;m not using ERB, the default rendering engine, I want to use haml Haml comes with a script, html2haml, which can take HTML with ERB &#8230; <a href="http://shifteleven.com/articles/2008/06/08/converting-erb-to-haml-snippet">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m playing around with <a href="http://merbivore.com/features.html,">merb</a> so I&#8217;m using <code>merb-gen</code> to create some basic scaffolding; however, I&#8217;m not using ERB, the default rendering engine, I want to use <a href="http://haml.hamptoncatlin.com/.">haml</a></p>
<p>Haml comes with a script, <code>html2haml</code>, which can take HTML with ERB and convert it nicely to haml.  Seeing as I would have to run that command more than once, I have a little command snippet that I like to use to aid with the conversion.</p>
<pre class="bash" title="code">$ find . -name '*erb' | \
xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}'</pre>
<p>That will print out what the <code>html2haml</code> commands would be, it does *not* run the command.  I do that step such that I can review what will be converted.  If I like what&#8217;s going to be done, then I just run that command and pipe it into bash&#8230;like so</p>
<pre class="bash" title="code">$ find . -name '*erb' | \
xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | \
bash</pre>
<p>If you like it, it probably wouldn&#8217;t hurt storing that as a shell script somewhere :)</p>
]]></content:encoded>
			<wfw:commentRss>http://shifteleven.com/articles/2008/06/08/converting-erb-to-haml-snippet/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Code Reviews &#8211; Inherit in Git</title>
		<link>http://shifteleven.com/articles/2008/05/17/code-reviews-inherit-in-git?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=code-reviews-inherit-in-git</link>
		<comments>http://shifteleven.com/articles/2008/05/17/code-reviews-inherit-in-git#comments</comments>
		<pubDate>Sat, 17 May 2008 23:48:30 +0000</pubDate>
		<dc:creator>K. Adam Christensen</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Version Control]]></category>
		<category><![CDATA[codereview]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://shifteleven.com/?p=77</guid>
		<description><![CDATA[Code Reviews are common in software development. One programmer reviews another&#8217;s code to find potential issues or to see if the developer could have used something that the system already provided. With multiple programmers, you can probably expect a versioning &#8230; <a href="http://shifteleven.com/articles/2008/05/17/code-reviews-inherit-in-git">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Code_review">Code Reviews</a> are common in software development.  One programmer reviews another&#8217;s code to find potential issues or to see if the developer could have used something that the system already provided.</p>
<p>With multiple programmers, you can probably expect a versioning system, perhaps a centralized versioning system like SVN or Perforce.  With that system, each programmer would make his/her changes and then would check in his/her changes into the repository.  From there, the programmer&#8217;s peers would review the code.</p>
<p>What&#8217;s the problem with this system?  The code is already checked in.  The pressure is on the peers to ensure that the code is good, and it&#8217;s likely that this could slip through the cracks.  I mean, those peers are working on getting 10 features complete themselves.</p>
<h3>Enter Git</h3>
<p>Well, I would argue that Git has a strong code review process built right in.  This is due to the process of how distributed version control works.</p>
<p><span id="more-77"></span></p>
<p>Programmer <strong>A</strong> creates a <a href="http://railsontherun.com/2008/3/3/how-to-use-github-and-submit-a-patch">fork</a> of the master project. <strong>A</strong> makes his changes and commit his code; however, the code is committed to his local repository and not the master origin.  This is because <strong>A</strong> does not have write access to that repository.</p>
<p><strong>A</strong> has to contact programmer <strong>B</strong>, who has write access. <strong>A</strong> tells <strong>B</strong> that he should pull his code.  Since <strong>B</strong> has to pull the code, this means that <strong>B</strong> has to review the code coming in.</p>
<p>It&#8217;s this workflow that promotes code review.  Now that&#8217;s not to say that you can&#8217;t do code reviews in a centralized model, it just fits a little better in a distributed model</p>
]]></content:encoded>
			<wfw:commentRss>http://shifteleven.com/articles/2008/05/17/code-reviews-inherit-in-git/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Issue Tracking + Git = ticgit</title>
		<link>http://shifteleven.com/articles/2008/05/10/issue-tracking-git-ticgit?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=issue-tracking-git-ticgit</link>
		<comments>http://shifteleven.com/articles/2008/05/10/issue-tracking-git-ticgit#comments</comments>
		<pubDate>Sun, 11 May 2008 00:08:53 +0000</pubDate>
		<dc:creator>K. Adam Christensen</dc:creator>
				<category><![CDATA[Version Control]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[issuetracker]]></category>
		<category><![CDATA[sinatra]]></category>
		<category><![CDATA[ticgit]]></category>
		<category><![CDATA[ticgit-watchtower]]></category>

		<guid isPermaLink="false">http://shifteleven.com/?p=73</guid>
		<description><![CDATA[So not only is git useful for the small projects it&#8217;s also good for keeping track of todos and issues. Ticgit is a distributed ticketing systems based on git. It provides a command line interface as well as a web &#8230; <a href="http://shifteleven.com/articles/2008/05/10/issue-tracking-git-ticgit">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So not only is <a href="http://shifteleven.com/articles/2008/04/30/version-control-isnt-for-just-the-big-projects,">git useful for the small projects</a> it&#8217;s also good for keeping track of todos and issues. <a href="http://github.com/schacon/ticgit">Ticgit</a> is a distributed ticketing systems based on git. It provides a command line interface as well as a web interface via <a href="http://sinatrarb.com">sinatra</a> and stores all of the ticket info in a separate branch, called <code>ticgit</code>. Rather clever I think.</p>
<p><span id="more-73"></span></p>
<p>Ticgit takes a simplistic approach to issue tracking as <a href="http://www.lighthouseapp.com">Lighthouse</a> has done. You can comment, add tags, manage the state of an issue, save views, and change to whom an issue is assigned. There is still more planned, like keeping track of milestones and syncing the tickets to Lighthouse.</p>
<p>As mentioned, there is a web interface to ticgit; however, it wasn&#8217;t my cup of tea. So I have started my own web interface, <a href="http://github.com/pope/ticgit-watchtower">tiwatchtower</a>. It&#8217;s still a little rough around the edges, but I would love to hear any thoughts.</p>
<h3>Conclusion</h3>
<p>So far, I like it and it&#8217;s exciting to see how git can be pushed. It&#8217;s great for keeping track of things that are on my mind without worrying about having to setup <a href="http://trac.edgewall.org/">trac</a> or having to use up a Lighthouse project. It&#8217;s simple, effective, and worth a look at.</p>
]]></content:encoded>
			<wfw:commentRss>http://shifteleven.com/articles/2008/05/10/issue-tracking-git-ticgit/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

