<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title>mindscratch.org</title>
  <link href="http://mindscratch.org/atom.xml" rel="self"/>
  <link href="http://mindscratch.org/"/>
  <updated>2011-12-19T22:10:59-05:00</updated>
  <id>http://mindscratch.org/</id>
  <author>
    <name>Craig Wickesser</name>
    
      <email>craig@mindscratch.org</email>
    
  </author>

  
  <entry>
    <title>Shared Mongo Configuration Settings in Rails</title>
    <link href="http://mindscratch.org/blog/2011/12/18/shared-mongo-configuration-settings-in-rails/"/>
    <updated>2011-12-18T21:58:00-05:00</updated>
    <id>http://mindscratch.org/blog/2011/12/18/shared-mongo-configuration-settings-in-rails</id>
    <content type="html">&lt;p&gt;I've developed a handful of Rails (3.x) applications which all used MongoDB as the persistence layer. In fact, I've yet to build a SQL backed Rails application during my &quot;day job&quot;. Thus far I've preferred Mongoid vs. MongoMapper, primarily because of the documentation. Although, I haven't gone back to look at MongoMapper in almost a year...but at this point, I don't have a need to change.&lt;/p&gt;

&lt;p&gt;Typically with Mongoid, you'll have a mongoid.yml file that has your database configuration. That's really super when you only use Mongoid to interact with your database. However, if you end up using another library/gem that needs to work with your database you'll have to duplicate your database configuration. NOT! Being a star developer (you know you are), you'll come up with some solution so you don't have to copy your database configuration around to multiple files.&lt;/p&gt;

&lt;p&gt;I ran into this situation when I began using &lt;a href=&quot;https://github.com/bkeepers/qu/&quot;&gt;Qu&lt;/a&gt;. Qu is a library for &quot;queueing and processing background jobs&quot;. It's easy to use, has a dandy API and works with either MongoDB or Redis. It might be worth mentioning here that &lt;a href=&quot;https://github.com/bkeepers&quot;&gt;Brandon Keepers&lt;/a&gt;, the creator of Qu, worked for &lt;a href=&quot;http://orderedlist.com/&quot;&gt;Ordered List&lt;/a&gt; which was recently &lt;a href=&quot;http://orderedlist.com/blog/articles/ordered-list-acquired-by-github/&quot;&gt;acquired&lt;/a&gt; by GitHub.&lt;/p&gt;

&lt;p&gt;Anyways, back to my solution for not duplicating database configuration. I've recently started using the &lt;a href=&quot;https://github.com/binarylogic/settingslogic&quot;&gt;settingslogic&lt;/a&gt; gem on my Rails project to manage my application configuration. I have a &quot;application.yml&quot; file that now contains my database configuration. Using settingslogic is not a requirement, in fact Rails has a &lt;a href=&quot;http://blog.carbonfive.com/2011/11/23/configuration-for-rails-the-right-way/&quot;&gt;built-in method&lt;/a&gt; for dealing with application configuration, so use what you like.&lt;/p&gt;

&lt;p&gt;Once I had my database configuration in a file, I setup two initializers: one for Mongoid and one for Qu. The best way I found was to create a MongoDB &lt;a href=&quot;http://www.mongodb.org/display/DOCS/Connections&quot;&gt;URI formatted&lt;/a&gt; string. Check out the following gist:&lt;/p&gt;

&lt;div&gt;&lt;script src='https://gist.github.com/1269292.js?file='&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;pre&gt;&lt;code&gt;# this is only a partial YAML file from a Rails application
# this YAML file would be loaded and used with the settingslogic gem

defaults: &amp;amp;defaults
  database: &amp;amp;database
    conn_uri: mongodb://username:password@localhost:27001/
    db_name: myapp_default
  job_queue: &amp;amp;job_queue
    db_name: qu

development:
  &amp;lt;&amp;lt;: *defaults
  database:
    &amp;lt;&amp;lt;: *database
    db_name: myapp_development
  job_queue:
    &amp;lt;&amp;lt;: *job_queue
    db_name: qu_development

test:
  &amp;lt;&amp;lt;: *defaults
  database:
    &amp;lt;&amp;lt;: *database
    db_name: myapp_test
  job_queue:
    &amp;lt;&amp;lt;: *job_queue
    db_name: qu_test&lt;/code&gt;&lt;/pre&gt;&lt;/noscript&gt;&lt;/div&gt;


&lt;p&gt;Now Mongoid and Qu use the same database configuration settings and it all comes from one file. Of course, you might want Mongoid and Qu to use different configuration settings, but hopefully you can see the benefit to my approach.&lt;/p&gt;

&lt;p&gt;Now that I've checked the time, I'm going to get 5 hours of sleep. So, like a chef, I'm cooked.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Map/Reduce With Hadoop and Ruby</title>
    <link href="http://mindscratch.org/blog/2011/12/18/map-reduce-with-hadoop-and-ruby/"/>
    <updated>2011-12-18T21:09:00-05:00</updated>
    <id>http://mindscratch.org/blog/2011/12/18/map-reduce-with-hadoop-and-ruby</id>
    <content type="html">&lt;p&gt;Unless you've been passed out at a bar you've probably heard about Map/Reduce, Hadoop or just the &quot;cloud&quot;. Afterall, it's the &quot;next big thing&quot;, if you're into that sort of stuff.&lt;/p&gt;

&lt;p&gt;At work the &quot;cloud&quot;, Map/Reduce, analytics are all the hotness. I figured I'd try out the &lt;a href=&quot;http://hadoop.apache.org/common/docs/current/streaming.html&quot;&gt;Hadoop Streaming API&lt;/a&gt; by piping data in and out with Ruby. I started out with a very small text file. Next I wrote the mapper which reads lines of text from STDIN and emits results through STDOUT.&lt;/p&gt;

&lt;p&gt;The reducer would be as trivial as the mapper except that it needs to keep track of when the key changes. Unlike the standard reducer API which provides a key with all of its values, the streaming API doesn't do that. Besides that the reducer (at least in my trivial example) is rather simple.&lt;/p&gt;

&lt;p&gt;The best part, is you can do all of this without ever setting up or using Hadoop! Now wait a minute, I thought I was trying out the Hadoop Streaming API. Well, you can do all the work and even test your mapper and reducer without using Hadoop. By simply piping data into and out of the mapper and reducer you can simulate what Hadoop will do. If you want to get real fancy pants you can throw in an intermediate sort before piping data to your reducer.&lt;/p&gt;

&lt;p&gt;Check out my gist which does the minimal thing before getting Hadoop involved.&lt;/p&gt;

&lt;div&gt;&lt;script src='https://gist.github.com/1328410.js?file='&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;pre&gt;&lt;code&gt;Now is definitely the time&lt;/code&gt;&lt;/pre&gt;&lt;/noscript&gt;&lt;/div&gt;


&lt;p&gt;Pretty cool stuff I think. Now I just run this with a real cloudy Hadoop setup and everything will be real groovy!&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Becoming Enumerable</title>
    <link href="http://mindscratch.org/blog/2011/08/18/becoming-enumerable/"/>
    <updated>2011-08-18T20:19:00-04:00</updated>
    <id>http://mindscratch.org/blog/2011/08/18/becoming-enumerable</id>
    <content type="html">&lt;p&gt;My first post on &lt;a href=&quot;http://rubysource.com&quot;&gt;RubySource&lt;/a&gt;, hasn't been published as of 08/18/2011, covers using mixin's in Ruby. Shortly after writing that article I ran across a presentation titled &lt;a href=&quot;http://confreaks.net/videos/607-cascadiaruby2011-the-enumerable-module-or-how-i-fell-in-love-with-ruby&quot;&gt;&quot;The Enumerable Module&quot;&lt;/a&gt; presented by Haris Amin at Cascadia Ruby Conf 2011. The general idea is that you can make your classes enumerable (e.g. have lots of cool methods you're used to seeing when working with Arrays, Hashes, etc).&lt;/p&gt;

&lt;p&gt;Since the process of making a class enumerable requires the use of mixin's I figured I provide a brief demonstration of how to do it.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Followers
    include Enumerable

    def initialize
        @followers = []
    end

    def add_follower(name)
        @followers &amp;lt;&amp;lt; name
    end

    def degrees_of_separation(name)
        # calculate
    end

    # must implement the each method
    def each
        # simple in this example
        @followers.each do |val|
            yield val
        end
    end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;Followers&lt;/code&gt; class stores an array of values which we iterate over in our implementation of the &lt;code&gt;#each&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;Check it out:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;f = Followers.new
f.add_follower 'shaun'
f.add_follower 'cliff'
f.add_follower 'sean'
f.add_follower 'nick'
f.add_follower 'tim'

f.find_all {|val|
  val.match /^s/i
}
# output: [&quot;shaun&quot;, &quot;sean&quot;]

f.collect do |val|
  val.upcase
end
# result: [&quot;SHAUN&quot;, &quot;CLIFF&quot;, ...]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Sorry for the lame example (e.g. &quot;followers&quot;) but I think you get the point.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Writing for rubysource</title>
    <link href="http://mindscratch.org/blog/2011/08/13/writing-for-rubysource/"/>
    <updated>2011-08-13T19:50:00-04:00</updated>
    <id>http://mindscratch.org/blog/2011/08/13/writing-for-rubysource</id>
    <content type="html">&lt;p&gt;I've been writing articles for various online sites (and publications) for the past four years. It really all started
after I got to know Scott Delap, the guy behind &lt;a href=&quot;http://www.clientjava.com&quot;&gt;Client Java&lt;/a&gt;. I was a Java 2D and Swing developer
from 2003 - 2008, and the Client Java site was a great resource. I ended up doing some consulting type work for Scott and
he ended up asking me about writing for &lt;a href=&quot;http://www.infoq.com/author/Craig-Wickesser&quot;&gt;InfoQ&lt;/a&gt;. I did some trial type posts and ended up getting the
gig.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.infoq.com/news/2007/08/scala-overview&quot;&gt;Catching Up with Scala&lt;/a&gt; was my first post and was published on August 22, 2007. That post was published jointly with Scott, but my first
&quot;solo&quot; post was titled &lt;a href=&quot;http://www.infoq.com/news/2007/09/jpa-dao&quot;&gt;&quot;Has JPA Killed the DAO?&quot;&lt;/a&gt;.  I ended up writing 32 news articles and 2 featured articles during my 2+ years with InfoQ (my last news article was published on December 12, 2009, titled &lt;a href=&quot;http://www.infoq.com/news/2009/12/intellij-idea-9&quot;&gt;&quot;IntelliJ IDEA 9: Java EE6, OSGi, Flex and More&quot;&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Before I stopped writing for InfoQ I got in contact with Michael Kimsal, founder of &lt;a href=&quot;http://webdevpub.com&quot;&gt;webdev publishing&lt;/a&gt;, &lt;a href=&quot;http://groovymag.com&quot;&gt;GroovyMag&lt;/a&gt;, &lt;a href=&quot;http://jsmag.com&quot;&gt;JSMag&lt;/a&gt; and plenty of other things, about an opportunity to work on the GroovyMag publication (a digital magazine, in PDF format).
Here's the original email I sent to Michael on February 4, 2009:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Hi,
  I recently started subscribing to/reading GroovyMag and I really enjoy it.  I am a software engineer by day (java/swing/flex/python/jython...groovy/grails hopefully) and Java Editor for InfoQ by night/weekends (part-time).  I am learning Groovy and Grails because I believe there is a lot of potential and usefulness and I hope to incorporate them into my day job sometime (sooner than later hopefully).&lt;/p&gt;

&lt;p&gt; Anyhow, I saw there opportunities to write for GroovyMag and I was wondering how I might be able to get involved.  If it seems like a possibility hit me back and we'll go from there.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I officially got started as a technical editor for both publications (GroovyMag and JSMag) on February 12, 2009 and I continued through April/May 2010. During that time I also wrote several articles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easy Behavior Driven Development, Using easyb for BDD (sept 2009)&lt;/li&gt;
&lt;li&gt;Metaprogramming with Groovy, part 1 (dec 2009)&lt;/li&gt;
&lt;li&gt;Metaprogramming with Groovy, part 2 (jan 2010)&lt;/li&gt;
&lt;li&gt;Catching Up with Griffon, Q&amp;amp;A with Andres Almiray (feb 2010)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Working on GroovyMag was interesting and frustrating. The frustration usually came from waiting for authors to submit their posts for review and having to sort through some pretty poor grammar and spelling (and believe me, I'm nowhere near perfect myself).&lt;/p&gt;

&lt;p&gt;This leads me to my latest endeavor, writing for &lt;a href=&quot;http://www.rubysource.com&quot;&gt;RubySource&lt;/a&gt;. I've chosen to take on this opportunity because I've been working with Ruby for about 6 months and I'd like to share my experiences and learn more (through the process of writing). I've worked with &lt;a href=&quot;http://twitter.com/#!/aaron_osteraas&quot;&gt;Aaron Osteraas&lt;/a&gt; to get started
and I'm looking forward to having my first post on the site in the next couple of weeks.&lt;/p&gt;

&lt;p&gt;On a side note, I also signed up to be a moderator for the super-awesome &lt;a href=&quot;http://www.railscasts.com&quot;&gt;RailsCasts&lt;/a&gt; site. &lt;a href=&quot;http://twitter.com/rbates&quot;&gt;Ryan Bates&lt;/a&gt; has published 278 free screencasts covering all sorts of Rails aspects including lots of 3rd party gems/plugins.
Ryan has used moderators to help fight spam, keep the comments formatted properly and help find any mistakes in the videos or the associated source code.&lt;/p&gt;

&lt;p&gt;In short, here's the timeline of my writing/editing career:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;InfoQ: 08/2007 - 12/2009&lt;/li&gt;
&lt;li&gt;GroovyMag/JSMag: 02/2009 - 05/2010&lt;/li&gt;
&lt;li&gt;RailsCasts Moderator: 07/2010 - ?&lt;/li&gt;
&lt;li&gt;RubySource: 08/2011 - ?&lt;/li&gt;
&lt;/ul&gt;

</content>
  </entry>
  
</feed>

