<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>@Lathi.net</title>
    <link>http://blog.lathi.net</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>On Life, Fatherhood, Christianity, and Computers</description>
    <item>
      <title>Unit Testing and Mocking for iPhone Apps</title>
      <description>&lt;p&gt;This was so much harder than I expected it to be.  I&amp;#8217;m new to Objective-C, but a long time &lt;span class="caps"&gt;TDD&lt;/span&gt;-er with Ruby.  Being able to write unit tests and mocks is an integral part of any language I work with now.  After much searching and trial and error I got it to work.&lt;/p&gt;


	&lt;p&gt;First, starting with a new iPhone application I followed &lt;a href="http://www.sente.ch/s/?p=535&amp;#38;lang=en"&gt;these directions&lt;/a&gt; on how to get it setup.  The &lt;a href="http://www.sente.ch/"&gt;Sen:Te&lt;/a&gt; guys are who wrote OCUnit in the first place.  There are other directions out there, but don&amp;#8217;t let them lead you astray.  XCode 3 doesn&amp;#8217;t support unit testing iPhone applications out of the box.  Most of the directions for setting up unit testing is for straight Mac &lt;span class="caps"&gt;OS X&lt;/span&gt; Cocoa apps and not iPhone apps.  The gist of the directions are:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Add a new target based on Mac &lt;span class="caps"&gt;OS X&lt;/span&gt; Cocoa Unit Test Bundle.&lt;/li&gt;
		&lt;li&gt;In the new test target&amp;#8217;s inspector window, whack all the &amp;#8220;User-Defined Settings&amp;#8221; in the new build tab&amp;#8217;s settings.&lt;/li&gt;
		&lt;li&gt;Also delete the &amp;#8216;&#8216;Other Linker Flags&amp;#8217; setting.&lt;/li&gt;
		&lt;li&gt;In the General tab, add a dependency to the &lt;code&gt;SenTestingKit.framework&lt;/code&gt;.  Here&amp;#8217;s where it gets tricky.  Don&amp;#8217;t just add any &lt;code&gt;SenTestingKit.framework&lt;/code&gt;.  You need to add the one from:&lt;/li&gt;
	&lt;/ul&gt;


&lt;code&gt;
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.sdk/Developer/Library/Frameworks/SenTestingKit.framework
&lt;/code&gt;

 * Now open the inspector for your application&amp;#8217;s main target and set a direct dependency between it and the test target.  That will make the tests build and run every time you build the app.  Test failure causes a build failure for your main target.

	&lt;p&gt;I also added a &amp;#8220;Unit Tests&amp;#8221; group/folder to the project as a place to store my tests separate from my classes.  When you want to create a new test, you simply add a new file and choose the &amp;#8220;Objective-C test case class&amp;#8221; template.  Make sure you add it to the test target and not your main application target.&lt;/p&gt;


	&lt;p&gt;So that gives you unit tests so you can make assertions; but that&amp;#8217;s about it.  You also need &lt;a href="http://www.mulle-kybernetik.com/software/OCMock/"&gt;OCMock&lt;/a&gt;.  I had a little trouble getting this installed and working, but following &lt;a href="http://mitchellhashimoto.com/using-ocmock-with-xcode-3-in-leopard/"&gt;Mitchell Hasimoto&amp;#8217;s&lt;/a&gt; notes I was able to get it working.  Download the OCMock framework and save it into &lt;code&gt;/Library/Frameworks&lt;/code&gt;.  Then in you test target&amp;#8217;s inspector add it as a dependency.  That should be enough.  Here&amp;#8217;s a little test class that I used to prove to myself it was working:&lt;/p&gt;


	&lt;p&gt;&lt;code&gt;testTruth.h&lt;/code&gt;:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;#import &amp;lt;SenTestingKit/SenTestingKit.h&amp;gt;

@interface testTruth : SenTestCase {

}

- (void) testTruth;
- (void)testAcceptsStubbedMethod;

@end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;&lt;code&gt;TestTruth.m&lt;/code&gt;:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;#import &amp;quot;testTruth.h&amp;quot;
#import &amp;lt;OCMock/OCMock.h&amp;gt;

@implementation testTruth

- (void) testTruth {
    STAssertTrue(1 == 1, @&amp;quot;Must be true&amp;quot;);
}

- (void)testAcceptsStubbedMethod {
    id mock = [OCMockObject mockForClass:[NSString class]];
    [[mock stub] lowercaseString];
    [mock lowercaseString];
}
@end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
      <pubDate>Fri, 06 Feb 2009 14:54:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:9676eda5-d732-487f-b069-37f7f4d3b21c</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2009/02/06/unit-testing-and-mocking-for-iphone-apps</link>
      <category>Programming</category>
      <category>Test Driven Development</category>
      <category>iPhone</category>
      <category>testing</category>
      <category>mocks</category>
    </item>
    <item>
      <title>Suggestion of Demeter</title>
      <description>&lt;p&gt;Frankly, I haven&amp;#8217;t ever really made up my mind about how to address the Law of Demeter in Rails. I&amp;#8217;d like to use this article as a spring board to discuss the alternatives.&lt;/p&gt;


	&lt;p&gt;As found on Wikipedia, the &lt;a href="http://en.wikipedia.org/wiki/Law_of_Demeter"&gt;Law of Demeter&lt;/a&gt; says &#8220;Only talk to your immediate friends.&#8221;   There&amp;#8217;s a good write-up about it by Brian Donovan specifc to rails, &lt;a href="http://brian.maybeyoureinsane.net/blog/2006/12/15/law-of-demeter-or-how-to-avoid-coding-yourself-into-a-corner-in-rails/"&gt;Law of Demeter, or How to avoid coding yourself into a corner in Rails&lt;/a&gt;. In this article he sums up nicely the advantage of delegation.&lt;/p&gt;


	&lt;p&gt;Let&amp;#8217;s look at an example:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;class User &amp;lt; ActiveRecord::Base
  has_one :profile
end

class Profile &amp;lt; ActiveRecord::Base
  has_one :address
end

class Address &amp;lt; ActiveRecord::Base
end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Now if you want to find out what country the user lives in you need to access &lt;code&gt;user.profile.address.country&lt;/code&gt;.  That&amp;#8217;s a violation of the LoD.  The problem is if you refactor profile or address you&amp;#8217;ll have to go back and fix all the places you did this access chaining as well.  The common answer is to delegate!&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;class User &amp;lt; ActiveRecord::Base
  has_one :profile
  delegate :country, :to =&amp;gt; :profile
end

class Profile &amp;lt; ActiveRecord::Base
  has_one :address
  delegate :country, :to =&amp;gt; :address
end

class Address &amp;lt; ActiveRecord::Base
end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Now we can just access &lt;code&gt;user.country&lt;/code&gt;.  The problem so far is that (at least in Rails 2.1) if the user&amp;#8217;s profile is &lt;code&gt;nil&lt;/code&gt; or if the profile&amp;#8217;s address is &lt;code&gt;nil&lt;/code&gt; then the call to &lt;code&gt;user.country&lt;/code&gt; will blow up.  There are some patches and work arounds, but the problem exists.  Also, this double delegation smells to me and I don&amp;#8217;t know why.  Maybe it&amp;#8217;s the obtuseness of this particular design.  Maybe double-delegation is a smell of bad modeling.&lt;/p&gt;


	&lt;p&gt;There&amp;#8217;s a new feature in &lt;a href="http://guides.rubyonrails.org/2_2_release_notes.html"&gt;Rails 2.2&lt;/a&gt; that relate to delegation and using a prefix for delegated methods.  This might be a little contrived, but continuing with our above example:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;class User &amp;lt; ActiveRecord::Base
  has_one :profile
  delegate :country, :to =&amp;gt; :profile, :prefix =&amp;gt; true
end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Means that now we call &lt;code&gt;user.profile_country&lt;/code&gt; instead of &lt;code&gt;user.country&lt;/code&gt;.  Instead of passing &lt;code&gt;true&lt;/code&gt; to the prefix option, you can also pass a string that will get used instead of the delegator object name.&lt;/p&gt;


	&lt;p&gt;I question why &lt;code&gt;user.profile_country&lt;/code&gt; is any better than &lt;code&gt;user.profile.country&lt;/code&gt;.  If you rename the profile class, you&amp;#8217;re almost always going to want to rename that prefix too.  So everywhere in your code you called &lt;code&gt;user.profile_country&lt;/code&gt; you&amp;#8217;ll end up changing it to &lt;code&gt;user.foobar_country&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;Finally, I&amp;#8217;m going to bring up Jay Field&amp;#8217;s &lt;a href="http://blog.jayfields.com/2007/03/rails-presenter-pattern.html"&gt;Presenter Pattern&lt;/a&gt;.  Basically, this is creating an object that aggregates multiple objects so they can easily be presented on the same form simply.  In addition, the presenter object gives you a place to put formatting and some computational logic that sometimes finds its way into views.&lt;/p&gt;


	&lt;p&gt;The Presenter Pattern seems neat, but I&amp;#8217;m not sure when to use it instead of delegation straight from the &amp;#8220;parent&amp;#8221; object.  In the example on Jay&amp;#8217;s page he talks about a user_account, user_credential, and an address.  All that gets aggregated into a &lt;code&gt;CompletePresenter&lt;/code&gt;.  But really, that seems contrived too.  His user account only has a name and the credentials has the username and password.  It seems more likely that you&amp;#8217;d just define a user that has a name, username, and password and allow the user to has_one address.  Why not just delegate the address attributes directly from the now combined user class?&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ll also mention the Rails &lt;code&gt;fields_for&lt;/code&gt; helper.  This seems to be an effort to address having multiple objects on the same web form.  Personally, I think the net effect of that is to push more logic into your controller to deal with these multiple groups of fields.  Both the presenter pattern and straight up method delegation push this back into the models and out of the controllers.  Maybe I just don&amp;#8217;t understand how this is meant to be used.&lt;/p&gt;


	&lt;p&gt;So I&amp;#8217;ll close with these questions.  When is the Presenter Pattern better than delegation from your already existing models?  When is the added complexity of an additional layer of objects worth it?  What about double delegation?  Is it a smell and for what?  Should I just get over my unease when I see double delegation? What&amp;#8217;s the real value of using a prefix for delegated methods?  What are the legitimate uses of &lt;code&gt;fields_for&lt;/code&gt;? Also, why doesn&amp;#8217;t the Rails &lt;code&gt;delegate&lt;/code&gt; method handle the case where the delegation target is nil?  I know there are work arounds and patches, but it seems like the Rails implementation of &lt;code&gt;delegate&lt;/code&gt; is broke.&lt;/p&gt;</description>
      <pubDate>Fri, 24 Oct 2008 12:30:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:de226190-bed5-42b3-a7b4-2525f111663a</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2008/10/24/suggestion-of-demeter</link>
      <category>Programming</category>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Rails</category>
      <category>demeter</category>
      <category>delegate</category>
      <category>presenter</category>
      <category>pattern</category>
      <category>design</category>
    </item>
    <item>
      <title>Scripting Screen</title>
      <description>&lt;p&gt;I do pretty much all my work using &lt;a href="http://www.google.com/url?sa=U&amp;#38;start=1&amp;#38;q=http://www.gnu.org/software/screen/"&gt;&lt;span class="caps"&gt;GNU&lt;/span&gt; Screen&lt;/a&gt; inside a terminal. I use a different screen session for each project and have pretty much the same window configuration for each session.  After finally getting tired of manually setting up my screen sessions, here&amp;#8217;s how  I managed to script new session setup.&lt;/p&gt;


	&lt;p&gt;Like many I have a development directory where all my projects live.  Inside this &lt;code&gt;devel&lt;/code&gt; dir I have the trunk of each project checked out from version control.  Most of my projects haven&amp;#8217;t been converted to &lt;code&gt;git&lt;/code&gt; yet, so I&amp;#8217;m not sure how different it&amp;#8217;d be compared to &lt;code&gt;svn&lt;/code&gt;.  My screen session is made up of several windows.  Inside the first, I run emacs.  The second is autotest.  The third I run &lt;code&gt;./script/server&lt;/code&gt;.  I also have a window for &lt;code&gt;./script/console&lt;/code&gt; and a database prompt; but the order isn&amp;#8217;t that important.  After those I&amp;#8217;ll have a window or two for misc. bash prompts.&lt;/p&gt;


	&lt;p&gt;One solution to automatically setting all this up is to put screen commands inside your &lt;code&gt;.screenrc&lt;/code&gt; to create and name the windows.  You can even specify what command to run in the windows.  The problem is that when you exit that command for whatever reason, the screen window is killed with it.  That&amp;#8217;s not so handy when you need to restart autotest or your server.  Also, the &lt;code&gt;.screenrc&lt;/code&gt; file doesn&amp;#8217;t allow for any type of scripting for dynamically generating any of your startup information.&lt;/p&gt;


	&lt;p&gt;After digging in the &lt;code&gt;man&lt;/code&gt; page a little bit I found a few screen commands that allow it to be scripted fairly well from outside scripts.  I&amp;#8217;ll show the important commands here.&lt;/p&gt;


&lt;code&gt;
screen -d -m -S &amp;lt;screen session name&amp;gt;
&lt;/code&gt;

	&lt;p&gt;This will create a new screen session detached but with an input/output stream.  The &lt;code&gt;-S&lt;/code&gt; names the screen session to make it easier to refer to it later.&lt;/p&gt;


&lt;code&gt;
screen -X -S &amp;lt;session name&amp;gt; screen -t test 1
&lt;/code&gt;

	&lt;p&gt;This sends a screen command to the screen session with the given name.  In this case, the screen command is to create a new screen window named &amp;#8220;test&amp;#8221; as window 1.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
screen -X -S &amp;lt;session name&amp;gt; -p 1 stuff "cd $DEVEL/$PROJECT; autotest
" 
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This again sends a screen command to the named session.  In this case we&amp;#8217;re sending the &lt;code&gt;stuff&lt;/code&gt; command directly to window 1.  The &lt;code&gt;stuff&lt;/code&gt; command sends the string into stdin of the running application in that window.  In this case the running app is a bash prompt.  Note the trailing newline inside the string will cause the command &amp;#8220;typed&amp;#8221; at the bash prompt to be run.&lt;/p&gt;


	&lt;p&gt;The only other problem I ran into is that when creating screen windows like this, they didn&amp;#8217;t show up on my hard status line automatically.  My solution was to setup a little for loop and select each window like this:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
for i in 0 1 2 3 4
do
   screen -X -S &amp;lt;session name&amp;gt; select $i
done
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Finally, when all is setup the way you want the last thing to do is join the resulting screen session like this:&lt;/p&gt;


&lt;code&gt;
screen -x &amp;lt;session name&amp;gt; -p 0
&lt;/code&gt;

	&lt;p&gt;The trailing &lt;code&gt;-p 0&lt;/code&gt; says to start in the first window.&lt;/p&gt;


	&lt;p&gt;You can download my resulting script &lt;a href="http://lathi.net/files/start-screen.sh"&gt;here&lt;/a&gt;.  One thing to note is that I have an entry in &lt;code&gt;/etc/services&lt;/code&gt; for each of my projects.  I use this so that when I run &lt;code&gt;./script/server&lt;/code&gt; I always start on the same port for each project.  Also, I&amp;#8217;m making use of &lt;code&gt;bash&lt;/code&gt;&amp;#8217;s &lt;code&gt;select&lt;/code&gt; command for prompting with project (or which already started screen session) to join/start.  It&amp;#8217;s a little clumsy in that &lt;code&gt;select&lt;/code&gt; wants to keep prompting you for input after you&amp;#8217;re done with the screen session; but it&amp;#8217;s a lot better than what I had.&lt;/p&gt;</description>
      <pubDate>Sat, 13 Sep 2008 09:11:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:820ca81c-1dc9-4248-9f67-fb57a21ad284</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2008/09/13/scripting-screen</link>
      <category>Programming</category>
      <category>script</category>
      <category>screen</category>
      <category>emacs</category>
    </item>
    <item>
      <title>Simple Expense Tracking with Google Docs</title>
      <description>&lt;p&gt;As my family prepares for our pending Disney trip, I&amp;#8217;m thinking about clever ways to take advantage of my wife&amp;#8217;s iPhone.  One of the things we&amp;#8217;ve done is budget the trip based on a few simple categories of expenses.  There&amp;#8217;s a lot of ways to track expenses to budgets, but I&amp;#8217;m particularly happy with how this worked out using Google Documents and the iPhone.&lt;/p&gt;


	&lt;p&gt;The kicker is that Google Docs are only viewable from the iPhone.  My initial hopes of editing a spreadsheet directly from the phone were quashed rudely in a live demo with the wife.  Plan B is to use Google Doc&amp;#8217;s forms to add individual expenses.  This is really a better solution as it&amp;#8217;s much easier for my wife to fill out three text fields than to worry about editing a spreadsheet in the right cells.&lt;/p&gt;


	&lt;p&gt;So the expense sheet of the document is simply the form entries: description, amount, and type.  I added help text that listed the valid values I was looking for: food, gas, tickets, junk.&lt;/p&gt;


	&lt;p&gt;The budget sheet has four rows; one for each budget type.  One column has the budgeted amount, and another uses &amp;#8220;SUMIF&amp;#8221; to sum up all the expense entries if the type matches the budget category.  I can then subtract these two to get how much of our budgeted money remains in that category.&lt;/p&gt;


	&lt;p&gt;I bookmarked the form url on the iPhone for my wife and she can fill it out repeatedly.  I also bookmarked the actual spreadsheet.  It&amp;#8217;s unfortunate that the Google Doc forms don&amp;#8217;t let you specify a &amp;#8220;thank you&amp;#8221; url instead of a thank you message.  Anyway, I bookmarked the actual Google Document so we can check the budget remaining easily while out and about.  It seems that the iPhone has some trouble changing sheets while viewing Google Documents, so I made the budget sheet the first and default page.&lt;/p&gt;


	&lt;p&gt;All in all it&amp;#8217;s very simple and has a high wife approval factor.  Plus, the whole thing took me less than 30 minutes to setup including several &amp;#8220;customer approval testing&amp;#8221; iterations.  Spreadsheets with Google Docs are really fun.  Adding in these forms is almost like rapid prototyping custom web apps.&lt;/p&gt;</description>
      <pubDate>Mon, 28 Apr 2008 12:57:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9f82cce2-70ca-495d-86aa-10c501ab478b</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2008/04/28/simple-expense-tracking-with-google-docs</link>
      <category>iPhone</category>
      <category>Google</category>
      <category>budget</category>
      <category>finances</category>
      <category>Disney</category>
      <category>vacation</category>
      <category>expenses</category>
    </item>
    <item>
      <title>Dynamic Constants and their Pitfalls</title>
      <description>&lt;p&gt;I&amp;#8217;ve just fixed a bug in production that took me more than eight hours to find.  When I show you the code, you&amp;#8217;ll wonder why it took me so long.  I have lots of excuses, but it&amp;#8217;s a fairly interesting bug to think about.  It shows some of the weaknesses in my usual modus operandi.  The code that looks something like this:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;class Article
  CURRENT=&amp;quot;start_publish_on &amp;lt;= #{Date.today} AND stop_publish_on &amp;gt; #{Date.today}&amp;quot;

  def self.find_latest
    find(:all, :conditions =&amp;gt; CURRENT)
  end
end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;In retrospect the bug is obvious and probably is obvious to you as well.  The Article::CURRENT constant is dynamically generated using the date at the time the class is evaluated.  With rails in production mode, that could be a long time; certainly more than a day.  The conclusion to draw here is to be very, very careful about dynamically generating constant strings.  As a rule, I might suggest not doing it.&lt;/p&gt;


	&lt;p&gt;The most interesting thing about this is you can&amp;#8217;t write a test to catch this error.  I think that&amp;#8217;s the the biggest thing that took me so long to find the error.  I tend to be over confident in our test suite.  As the new guy to the project, I&amp;#8217;m proud of them for how conscientious they are about testing their code.  I&amp;#8217;m trying to fix this bug by triggering it in a test.  Well, it can&amp;#8217;t be done.  The difference is how the production environment cache classes versus how testing and development does it.&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s another tidbit that threw me off the trail for a long time.  Our copy editor that is responsible for publishing articles says to fix it she simply back dates the articles by a day.  So I spent a lot of time looking for off-by-one errors.  I had recently fixed a problem with comparing times to dates and causing off-by-one, so I thought that might be it.  As it turns out, this was a red herring.  There&amp;#8217;s such a tight loop for feature request, implement, deploy that the production environment gets restarted fairly regularly (like nearly every day).&lt;/p&gt;


	&lt;p&gt;I guess what prompted me to write about this particular bug was what it said about our testing.  Clearly automated testing can&amp;#8217;t find all the bugs.  It also says something about our rapid development.  As long as we&amp;#8217;re really busy, this bug didn&amp;#8217;t bite us.  It&amp;#8217;s not until our deployment slows down (like a weekend) that it showed up.&lt;/p&gt;</description>
      <pubDate>Tue, 05 Feb 2008 15:35:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:d67c52df-4bbb-44f6-b6ec-f0bb1ca407b2</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2008/02/05/dynamic-constants-and-their-pitfalls</link>
      <category>Programming</category>
      <category>Ruby on Rails</category>
    </item>
    <item>
      <title>My First Day of Freedom</title>
      <description>&lt;p&gt;Friday was my last day at the company that won&amp;#8217;t let me blog about them.  I am very excited to be 100% independent freelancing!  This has been a goal of mine for many years and it&amp;#8217;s finally come true.&lt;/p&gt;


	&lt;p&gt;This morning &lt;a href="http://railsstudio.com/"&gt;Mark Windholtz&lt;/a&gt; is coming over to pair with me on a contract we share.  It&amp;#8217;s his good for not making me commute on my first day of independence.  I&amp;#8217;m looking forward to working with him and several other independent developers.&lt;/p&gt;


	&lt;p&gt;Hopefully now that I&amp;#8217;m not under corporate thumbs I&amp;#8217;ll be able to blog more about the types of problems I&amp;#8217;m seeing and methods for overcoming.  I&amp;#8217;ve specifically been asked to write an article on my experiences working remotely on a Scrum project.&lt;/p&gt;


	&lt;p&gt;In addition to writing more, I&amp;#8217;m also hoping to be able to contribute back to the open source community.  It&amp;#8217;s tricky when your family depends on your billable hours to also give your work away.  However, I think it&amp;#8217;s good balance to work on things my clients require as well as things I&amp;#8217;m interested in.  At first, this is likely to be helping &lt;a href="http://technomancy.us/"&gt;Phil Hagelberg&lt;/a&gt; shape up Emacs for ruby development.&lt;/p&gt;


	&lt;p&gt;So, there you go.  I&amp;#8217;m going to be working with some good guys; doing more writing; and working on more open source.  Wish me luck!&lt;/p&gt;</description>
      <pubDate>Mon, 21 Jan 2008 07:49:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:d00b9c36-9e06-403f-aafd-5c7528d1483c</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2008/01/21/my-first-day-of-freedom</link>
      <category>family</category>
      <category>consulting</category>
      <category>emacs</category>
      <category>Ruby</category>
      <category>Rails</category>
    </item>
    <item>
      <title>Small Victories in Customer Service</title>
      <description>&lt;p&gt;I bought my wife a &lt;span class="caps"&gt;GPS&lt;/span&gt; from Amazon as an early Christmas present before Thanksgiving.  I guess I was a little too eager because I ended up paying too much for it.  Just a couple weeks later, Amazon advertised to me in one of their &amp;#8220;may we suggest&amp;#8221; ads the very same &lt;span class="caps"&gt;GPS&lt;/span&gt; for a lot less money.  In the end, they refunded me the difference in price; but I can&amp;#8217;t help but feel a little miffed by the whole experience.&lt;/p&gt;


	&lt;p&gt;Let me start by saying trying to sell me the exact same device I&amp;#8217;ve already bought from them at a lower price in a targeted ad is pretty stupid.  They know everything I&amp;#8217;ve bought.  In fact, the ad said something like &amp;#8220;we know you&amp;#8217;ve looked at these &lt;span class="caps"&gt;GPS&lt;/span&gt;&amp;#8217;, may we suggest this other one?&amp;#8221;  Why would they advertise to me something I&amp;#8217;ve already bought.  And why advertise it to me if you know I paid more for the same device?  We in the web development world who control how these ads get generated need to do better than that.&lt;/p&gt;


	&lt;p&gt;I couldn&amp;#8217;t let them rub this price drop in my face, so I called up customer service.  The &lt;span class="caps"&gt;CSR&lt;/span&gt; was unsympathetic to my plight.  Nothing I said phased her.  I was nice and undemanding.  I pointed out that I was within my return window and I could just return the device for a refund and then go buy it somewhere else.  It all was a no go.  There was no getting a refund from her.&lt;/p&gt;


	&lt;p&gt;So I pulled the standard &amp;#8220;let me talk to your manager&amp;#8221; trick.  She made me wait on hold for what seemed like five to 10 minutes.  When the supervisor came on the phone she quickly summarized what she thought my concern was and then just as quickly told me she&amp;#8217;d refund me the difference between what I paid and the new price.&lt;/p&gt;


	&lt;p&gt;One the surface, I&amp;#8217;m pleased.  I paid way too much for the &lt;span class="caps"&gt;GPS&lt;/span&gt; and I&amp;#8217;m glad I didn&amp;#8217;t loose out.  Money&amp;#8217;s tight this time of year and every little bit helps.  Also, it didn&amp;#8217;t cost me too much effort to get the refund.  All told probably 30 minutes.  The refund as an hourly wage is pretty good.&lt;/p&gt;


	&lt;p&gt;On the other hand, I&amp;#8217;m frustrated by the way they handled me.  First, as I said above, why even advertise the price drop to me?  It&amp;#8217;s true I was already aware other places (like Wal-Mart) had it cheaper.  But the ad was definitely insult to injury.  Second, and this is the real kicker, why didn&amp;#8217;t the original &lt;span class="caps"&gt;CSR&lt;/span&gt; handle my concern?  Why did she resist so hard to giving me a refund when her supervisor just came on the phone and gave it to me without me having to even ask?&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m trying to think what lesson I can learn about this in dealing with people.  I wonder if the original &lt;span class="caps"&gt;CSR&lt;/span&gt; knew her manager was going to give me what I wanted?  It seems like there&amp;#8217;s times when people have wanted things from me that I knew I&amp;#8217;d eventually give them.  For some reason though I can recall making them &amp;#8220;work for it&amp;#8221;.  Maybe such a delayed &amp;#8220;giving in&amp;#8221; has some value, but on the receiving end I&amp;#8217;m not so sure.  I think this no-then-yes tactic really just comes across as being difficult to work with.&lt;/p&gt;


	&lt;p&gt;I think the lesson to walk away from here is that when someone asks for something really think about it before you say &amp;#8220;no&amp;#8221;.  Are you saying &amp;#8220;no&amp;#8221; just because you hope they&amp;#8217;ll go away but you know the right thing to do is say &amp;#8220;yes&amp;#8221;?  There are definitely times to say &amp;#8220;no&amp;#8221; just as there are definitely times to say &amp;#8220;yes&amp;#8221;.  I guess what I&amp;#8217;m trying to come up with is don&amp;#8217;t play games with your yeses and noes.  Shoot straight.  Let your &amp;#8220;yes&amp;#8221; be yes and your &amp;#8220;no&amp;#8221; be no.&lt;/p&gt;


	&lt;p&gt;Oh, and the other lesson to walk away from here is don&amp;#8217;t give in so easily when talking to customer service.&lt;/p&gt;</description>
      <pubDate>Sat, 01 Dec 2007 11:20:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:2f3575d6-9255-40bd-81bb-f081adadeae2</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2007/12/01/small-victories-in-customer-service</link>
      <category>amazon</category>
      <category>customer</category>
      <category>service</category>
      <category>kindness</category>
      <category>honesty</category>
      <category>refund</category>
    </item>
    <item>
      <title>Jumping to Specific Windows in Emacs</title>
      <description>&lt;p&gt;OK, last emacs tip for a while.  It&amp;#8217;s ironic, but the last two years I&amp;#8217;ve written some cool elisp while at RubyConf.  I typically run emacs full screen and split buffers both vertically and horizontally to arrange bits of code.  It&amp;#8217;s not uncommon for me to end up with three, four, five or even six visible windows in emacs.  The problem though is navigating between them.&lt;/p&gt;


	&lt;p&gt;The out-of-the-box solution is to use &lt;code&gt;other-window&lt;/code&gt; (bound to C-x o) and just cycle through them.  If you&amp;#8217;re fancy you can give a prefix argument to &lt;code&gt;other-window&lt;/code&gt; and go backwards.  This window cycling is tedious to me though and I&amp;#8217;d like something faster.  Particularly when I&amp;#8217;m mostly bouncing back and forth between two windows.&lt;/p&gt;


	&lt;p&gt;To solve this problem I wrote &lt;code&gt;jump-to-buffer&lt;/code&gt;.  Of course, right now I&amp;#8217;m really enamored with the fuzzy matching in &lt;code&gt;ido-completing-read&lt;/code&gt;.  That&amp;#8217;s what allows you to type non-sequential characters to match the buffer name.  It&amp;#8217;s very similar to TextMate&amp;#8217;s pattern matching.  So, &lt;code&gt;jump-to-buffer&lt;/code&gt; uses &lt;code&gt;ido-completing-read&lt;/code&gt;.  The buffers it gives you as options for completion are only the buffers in visible windows.  It also sorts those buffers in the order of the &lt;code&gt;buffer-list&lt;/code&gt;; which is in the order of most recently accessed.&lt;/p&gt;


	&lt;p&gt;To make this work, I&amp;#8217;ve written two helper functions: &lt;code&gt;rotate-list&lt;/code&gt;, and &lt;code&gt;sort-by-other-list&lt;/code&gt;.  Without further ado:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;(defun dka-sort-by-other-list (to-sort-list other-list)
  (let* ((index 0)
         (other-alist (mapcar (lambda (buffer) 
                                (setq index (+ index 1))
                                (cons buffer index))
                              other-list))
         (swartz (mapcar (lambda (item) 
                           (cons (cdr (assoc item other-alist)) item))
                         to-sort-list))
         (sorted-list (sort swartz (lambda (a b) (&amp;lt; (car a) (car b))))))
    (mapcar 'cdr sorted-list)))

(defun rotate-list (list count)
  &amp;quot;Rotate the LIST by COUNT elements&amp;quot;
  (cond
   ((= count 0) list)
   ((not list) list)
   (t
    (rotate-list (nconc  (cdr list) (list (car list)) '()) (1- count)))))

(defun dka-jump-to-window ()
  &amp;quot;Interactively jump to another visible window based on it's `buffer-name' using `ido-completing-read'&amp;quot;
  (interactive)
  (let* ((visible-buffers (mapcar '(lambda (window) (window-buffer window)) (window-list)))
         (sorted-visible-buffers (dka-sort-by-other-list visible-buffers (buffer-list)))
         (rotated-buffer-list (rotate-list sorted-visible-buffers 1))
         (visible-buffer-names (mapcar (lambda (buffer) (buffer-name buffer)) rotated-buffer-list))
         (buffer-name (ido-completing-read &amp;quot;Enter buffer to jump to: &amp;quot; 
                                           visible-buffer-names
                                           nil t))
         (window-of-buffer
          (delq nil 
                (mapcar '(lambda (window) 
                           (if (equal buffer-name (buffer-name (window-buffer window)))
        window nil)) (window-list)))))
    (select-window (car window-of-buffer)))
)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I&amp;#8217;m definitely interested in feedback on this code.  The &lt;code&gt;dka-sort-list-by-other-list&lt;/code&gt; method was particularly tricky for me to write.  I think it&amp;#8217;s both right and fast.  I haven&amp;#8217;t dove into &lt;a href="http://www.emacswiki.org/cgi-bin/wiki/ElUnit"&gt;elunit&lt;/a&gt; yet to know for sure if it&amp;#8217;s right.&lt;/p&gt;</description>
      <pubDate>Wed, 07 Nov 2007 20:58:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:d67cf0f1-66d6-4070-8fab-f497f3942676</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2007/11/07/jumping-to-specific-windows-in-emacs</link>
      <category>Emacs</category>
      <category>Programming</category>
      <category>elisp</category>
      <category>elunit</category>
      <category>transform</category>
      <category>schwartz</category>
      <category>sorting</category>
      <category>emacs</category>
    </item>
    <item>
      <title>Sharing the Mac Clipboard with Emacs</title>
      <description>&lt;p&gt;While I&amp;#8217;m sharing emacs hacks, I finally got around to researching this and/or figuring it out.  I almost always run emacs inside the terminal in a &amp;#8220;no window&amp;#8221; mode.  It&amp;#8217;s pretty natural for me to use M-w to copy something from emacs and then try to Cmd-V it in another Terminal window or likewise Cmd-C something in Terminal and then try paste it into emacs with C-y.  Until now, I haven&amp;#8217;t known how to share the clipboard with emacs.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;(defun copy-from-osx ()
  (shell-command-to-string &amp;quot;pbpaste&amp;quot;))

(defun paste-to-osx (text &amp;amp;optional push)
  (let ((process-connection-type nil)) 
      (let ((proc (start-process &amp;quot;pbcopy&amp;quot; &amp;quot;*Messages*&amp;quot; &amp;quot;pbcopy&amp;quot;)))
        (process-send-string proc text)
        (process-send-eof proc))))

(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;This takes advantage of the &lt;code&gt;pbcopy&lt;/code&gt; and &lt;code&gt;pbpaste&lt;/code&gt; command line programs to access the clipboard and offers them up as elisp method for emacs&amp;#8217; &lt;code&gt;interprogram-*-functions&lt;/code&gt;.  Easy, peasy, pumkin weasy.&lt;/p&gt;


	&lt;p&gt;I need to give some props to Mark Aufflick for his post on &lt;a href="http://mark.aufflick.com/blog/2006/10/30/automatic-copy-from-x11-app-to-macos-clipboard"&gt;Automatic Copy from &lt;span class="caps"&gt;X11&lt;/span&gt; App to Mac OS Clipboard&lt;/a&gt;.  My &lt;code&gt;paste-to-osx&lt;/code&gt; is pretty much a straight rip from him.&lt;/p&gt;</description>
      <pubDate>Wed, 07 Nov 2007 20:09:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:d76e1e03-86bc-423e-95ce-eca0874b9166</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2007/11/07/sharing-the-mac-clipboard-with-emacs</link>
      <category>Emacs</category>
      <category>Mac OS X</category>
      <category>pbcopy</category>
      <category>pbpaste</category>
      <category>mac</category>
      <category>clipboard</category>
      <category>emacs</category>
    </item>
    <item>
      <title>Navigating Your Projects in Emacs</title>
      <description>&lt;p&gt;One of the things that&amp;#8217;s really nice about TextMate is the Cmd-T navigation of files in your project.  It pops up this little dialog with fancy pattern matching input to select one of the files in your project and then jumps to that file.  There&amp;#8217;s a similar command once your in a file to jump to symbols in that file.  I&amp;#8217;ve tried a couple things to achieve that behavior in emacs that I&amp;#8217;d like to talk about.&lt;/p&gt;


	&lt;p&gt;The first thing I tried was a method called &lt;code&gt;find-file-in-project&lt;/code&gt;.  It was originally implemented by &lt;a href="http://technomancy.us/"&gt;Phil Hagelberg&lt;/a&gt; as part of his &amp;#8220;Another Ruby on Rails Mode&amp;#8221; (arorem) and then also ported over to the current &lt;a href="http://rinari.rubyforge.org/"&gt;Rinari Is Not a Rails &lt;span class="caps"&gt;IDE&lt;/span&gt;&lt;/a&gt;.  Basically, it indexes all the files in a &amp;#8220;project&amp;#8221; and then provides a nice interactive completing read to switch between them.  It basically works just like Cmd-T in TextMat.  I did quite a bit of work optimizing the completing read so that it would behave nicely.  The problem is that emacs is slow to index the files in your project.&lt;/p&gt;


	&lt;p&gt;What I&amp;#8217;m using now is the tried and true &lt;code&gt;find-tag&lt;/code&gt; method which is part of &lt;code&gt;etags.el&lt;/code&gt;.  ETags depends on an external &lt;code&gt;TAGS&lt;/code&gt; file as an index of all the symbols in your project.  When you invoke &lt;code&gt;find-tag&lt;/code&gt; (by default bound to M-.) it prompts you with completing read for the symbol to find.  It then jumps directly to the file and location where that symbol is defined.  It&amp;#8217;s basically combining the find-file-in-project with find-symbol-in-buffer.  It&amp;#8217;s also very, very fast.&lt;/p&gt;


	&lt;p&gt;As an added bonus, you can use &lt;code&gt;tags-search&lt;/code&gt; to search through your project finding places that tag is used.  This is similar to TextMate&amp;#8217;s slowly grep all the files and render a buffer with those results in it, but much faster.&lt;/p&gt;


	&lt;p&gt;The bad news is you have to manually build the &lt;code&gt;TAGS&lt;/code&gt; file periodically.  Emacs is pretty good about continuing to work when you&amp;#8217;ve made modifications to the files, but if you add new methods, new files, or refactor significantly where thing are located then it gets confused.  When that happens, simply rebuild the &lt;code&gt;TAGS&lt;/code&gt; file.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://onestepback.org/"&gt;Jim Weirich&lt;/a&gt; gave me a nice little rake task to do the job:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;module Tags
  RUBY_FILES = FileList['**/*.rb'].exclude(&amp;quot;pkg&amp;quot;)
end

namespace &amp;quot;tags&amp;quot; do
  task :emacs =&amp;gt; Tags::RUBY_FILES do
    puts &amp;quot;Making Emacs TAGS file&amp;quot;
    sh &amp;quot;xctags -e #{Tags::RUBY_FILES}&amp;quot;, :verbose =&amp;gt; false
  end
end

task :tags =&amp;gt; [&amp;quot;tags:emacs&amp;quot;]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Just put that in &lt;code&gt;lib/tasks/tags.rake&lt;/code&gt; and then run &lt;code&gt;rake tags:emacs&lt;/code&gt; when you invoke &lt;code&gt;find-tag&lt;/code&gt; and it can&amp;#8217;t find it.  That shouldn&amp;#8217;t happen very often.  I&amp;#8217;ve found it&amp;#8217;s also very fast to build the &lt;code&gt;TAGS&lt;/code&gt; file.  I might consider putting that tags task as part of the normal run tests task, but I&amp;#8217;m not sure that&amp;#8217;s necessary.&lt;/p&gt;


	&lt;p&gt;The other catch here is that the rake task above calls out the &lt;a href="http://ctags.sourceforge.net/"&gt;exuberant ctags&lt;/a&gt; rather than the ctags that comes with emacs.  The exuberant ctags knows how to parse ruby files whereas the ctags that comes with emacs can&amp;#8217;t.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve installed exuberant ctags from MacPorts.  It is xctags even though MacPorts doesn&amp;#8217;t install it that way.  So (for better or worse) I&amp;#8217;ve renamed the ctags files installed with ports to xctags.  This also gets around the conflict that MacPorts thinks there is between the ctags installed with emacs and the exuberant ctags.&lt;/p&gt;


	&lt;p&gt;Give this a spin and let me know what you think.  I&amp;#8217;ve found it to be very accurate and very fast.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;:&lt;/strong&gt;  I&amp;#8217;ve added a github repository for my &lt;a href="http://github.com/dougalcorn/find-file-in-project/tree/master"&gt;find-file-in-project&lt;/a&gt;.  Feel free to do with it as you will.&lt;/p&gt;</description>
      <pubDate>Wed, 07 Nov 2007 10:04:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:75998427-5d70-4875-a222-b755d83f4b9a</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2007/11/07/navigating-your-projects-in-emacs</link>
      <category>Emacs</category>
      <category>Programming</category>
      <category>Lisp</category>
      <category>Ruby on Rails</category>
      <category>Mac OS X</category>
      <category>TextMate</category>
      <category>Ruby</category>
      <category>emacs</category>
      <category>rinari</category>
      <category>xctags</category>
      <category>etags</category>
    </item>
  </channel>
</rss>

