<?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>SQUARISM</title>
	<atom:link href="http://squarism.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://squarism.com</link>
	<description>I&#039;m from the valley of the heavy heads.</description>
	<lastBuildDate>Thu, 09 May 2013 02:10:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Using a Redis as a Database</title>
		<link>http://squarism.com/2013/05/04/using-redis-as-a-database/</link>
		<comments>http://squarism.com/2013/05/04/using-redis-as-a-database/#comments</comments>
		<pubDate>Sat, 04 May 2013 16:37:43 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1847</guid>
		<description><![CDATA[The Spike I was spiking on Redis recently. I wanted to use the redis-objects gem to simulate a shopping cart app even though the README specifically says Just use MySQL, k? I wanted to see what would happen if I tried it anyway. So the README and examples for the redis-objects gem are great so [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2013/05/pixel-ribbon_cor.png" alt="pixel-ribbon_cor" width="576" height="24" class="aligncenter size-full wp-image-1971" /></p>
<h2>The Spike</h2>
<p>I was spiking on Redis recently.  I wanted to use the <a href="https://github.com/nateware/redis-objects">redis-objects gem</a> to simulate a shopping cart app even though the README specifically says</p>
<blockquote><p>Just use MySQL, k?</p></blockquote>
<p>I wanted to see what would happen if I tried it anyway.  So the README and examples for the redis-objects gem are great so I&#8217;m not going to rehash what&#8217;s there.  However, I will say though that the example has you hardcode the id field to 1.  That detail snuck up on me.</p>
<p>If you don&#8217;t set an ID then you can&#8217;t work with a redis-object instance.  You get an exception: <code>Redis::Objects::NilObjectId: Attempt to address redis-object :name on class User with nil id (unsaved record?)</code></p>
<p>It&#8217;s basically trying to tell you, &#8220;hey, save the record first or set an ID&#8221;.  Well, honestly, I don&#8217;t want to set an id myself.  This is where the meat of the README is.  Redis-objects really fits organically in an existing ActiveRecord model.  That means Rails.  In this case though, I don&#8217;t want an entire Rails app.  I can see the value though in a plain old Rails app.  Just look at the examples if you want to see more.</p>
<p>Anyway, continuing on with the spiking, I tried to integrate the Supermodel gem with Redis-objects.  That sort of worked.  You just <code>class User < Supermodel::Base</code> and you can sort of get it to work.  This is great because Supermodel gives you finders like <code>User.find_by_email('bob@yahoo.com')</code> to make it act like ActiveRecord but you can't use <code>.create(email: 'bob@yahoo.com')</code> to begin with because of the same errors as I mentioned above.  Redis-objects really wants the record to have an ID already.  Even using Supermodel's RandomID mixin didn't work.  The initialize order and callback hooks don't really work (or at least I couldn't get them to work).</p>
<p>Finally, I tried combining just redis-objects and datamapper redis.  That worked.  And it's pretty nice.  Check it out.</p>
<p></p><pre class="crayon-plain-tag">require 'redis-objects'
require 'dm-core'
require 'dm-redis-adapter'

DataMapper.setup(:default, {:adapter  =&gt; &quot;redis&quot;})

# you would move this to a common location
Redis.current = Redis.new(:host =&gt; '127.0.0.1', :port =&gt; 6379)

class User
  include Redis::Objects
  include DataMapper::Resource

  # datamapper fields, just used for .create
  property :id, Serial
  property :email, String

  # use redis-objects fields for everything else
  value :disabled
  value :name
  list :cart, :marshal =&gt; true

end

# absolutely need this line for dm-redis
User.finalize</pre><p></p>
<p>So using this is pretty easy.</p>
<p></p><pre class="crayon-plain-tag">u = User.create(email: 'test@test.com')
u.name = 'Testy McTesterson'</pre><p></p>
<p>When you look at Redis, the keys are already composited for you and magic has happened.</p><pre class="crayon-plain-tag">redis 127.0.0.1:6379&gt; keys *
user:test@test.com:name

redis 127.0.0.1:6379&gt; get user:test@test.com:name
Testy McTesterson</pre><p></p>
<p>Yay!</p>
<p>The name field is from redis-objects and the create uses datamapper.  This is a really odd pairing but I like the fact that I have no sql database in the mix but still have finders similar to an ORM.  Something to keep in mind, datamapper's finders are a bit different than the Rails 3 ones (no .where method).</p>
<h2>Benchmarking A Million Things</h2>
<p>Ok fine.  So maybe this works, maybe it doesn't.  Maybe it's not the right idea.  What about the good stuff?  Like, how fast can we load a whole lot of names into MySQL versus Redis using  the above code and techniques?  Is it even relevant?</p>
<p></p><pre class="crayon-plain-tag">Summary
-------------------------------------------------------------------------------
(PL = pipelined redis operation)
 
Loading one million random names (full names) like John Smith, Patty Gerbee Sr)
MySQL:                   06:05
Redis:                   02:45
Redis C ext              01:32
Redis pipelined:         00:56
Redis pipelined C ext:   00:19
Ruby just loading array: 387ms
 
 
Loading 10k ecommerce-style data (orders, users, products)
MySQL:    00:09.40
Redis:    00:14.50
Redis PL: 00:02.72</pre><p>A gist of these <a href="https://gist.github.com/squarism/5234519">test results is here</a>.</p>
<h2>A More Complete Example</h2>
<p>If you know the ID and don't need something like an auto-incrementing column outside your code/control then you can greatly simplify the code above by getting rid of Datamapper.  You can simply use redis-objects to fake an ORM.  I had great success using it as long as you <em>USE NATIVE REDIS TYPES</em>.  Listen to the redis-objects author, don't try to force the tool into the use case.</p>
<p></p><pre class="crayon-plain-tag"># What if we want to use redis-objects as a database but
# try to stick with native redis objects?
#
# For example, Supermodel is a great gem but using the Redis
# mixin causes Supermodel to serialize to JSON strings in Redis
# which is going to kill performance.  You have to model your
# problem using native Redis objects to keep the speed up.
#
# At the same time, I miss the finders from ActiveModel
# like: Person.find('Joe')
# Supermodel does give you those finders so you will feel right at
# home coming from Rails.  I tried using ActiveModel mixins with
# redis-objects but it didn't work for me.
#
# I found the below a nice compromise but it requires a lot of
# custom methods.  :(


require 'redis-objects'

class Person
  attr_reader :name
  alias :id :name

  include Redis::Objects

  def initialize name
    @name = name
  end

  def self.exists? name
    # Here's a big assumption, if the id attribute exists, the entire
    # object exists.  This might not work for your problem.
    self.redis.exists &quot;name:{#name}:id&quot;
  end

  def self.find name
    # new behaves like find when a record exists, so this works like
    # find_or_create()
    self.new name
  end

  # native redis attributes with redis-objects
  value :age
  list :favorite_foods
end

# example usage

joe = Person.new 'Joe'
joe.age = 34
joe.favorite_foods &lt;&lt; ['cake', 'pie']  # it will flatten arrays, don't worry
joe.favorite_foods &lt;&lt; 'bacon'          # or you can do this

Person.find('Joe').age = 56

# find and initialize
Person.find('Stan').age = 21

# you cannot just .favorite_foods = ['Steak]' because that's not how native
# Redis objects work
Person.find('Stan').favorite_foods &lt;&lt; 'Steak'

# deleting a field
Person.find('Stan').favorite_foods.del  # notice it's .del and not .delete (del is the redis cmd)</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2013/05/04/using-redis-as-a-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Blub Paradox and Delicious Pie</title>
		<link>http://squarism.com/2013/04/21/the-blub-paradox-and-delicious-pie/</link>
		<comments>http://squarism.com/2013/04/21/the-blub-paradox-and-delicious-pie/#comments</comments>
		<pubDate>Sun, 21 Apr 2013 16:59:17 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1875</guid>
		<description><![CDATA[Anything worth doing is worth doing well. &#8220;That&#8217;s Good Enough&#8221; isn&#8217;t good enough. There are some cases where you are writing a one-off script but those tasks are few and far between. Most people don&#8217;t get paid to write throw-away code. Most developers aren&#8217;t sysadmins writing procedural code on the level and complexity of Bash. [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2013/04/good_enough-580x24.png" alt="good_enough" width="580" height="24" class="aligncenter size-large wp-image-1878" /><br />
Anything worth doing is worth doing well.  &#8220;That&#8217;s Good Enough&#8221; isn&#8217;t good enough.  There are some cases where you are writing a one-off script but those tasks are few and far between.  Most people don&#8217;t get paid to write throw-away code.  Most developers aren&#8217;t sysadmins writing procedural code on the level and complexity of Bash.  Even if you are, is this the only style you know?  Do you shy away from more complex tasks?  Can you not break down an any size problem into smaller pieces?</p>
<p>A musician practices their art constantly.  An athlete trains.  And yet, we in the tech community have to go out of our way to find people who work on personal projects on the side or have the will/motivation to learn new things outside of &#8220;the job&#8221;.  If you don&#8217;t learn on your own then you have to figure it out as you go.  And you are already very busy so I know you&#8217;re just skimming over this post anyway.  So let&#8217;s break this down in a bulleted list.</p>
<ul>
<li>Developers work best when they&#8217;re challenged but not overwhelmed.  Optimal work is a run, not a jog or a sprint.</li>
<li>Developers will step-up or fill-in a task to make it challenging as stated above.</li>
<li>Your classic boss doesn&#8217;t really care how you solve problems.</li>
<li>Culture takes 20 years to change.</li>
<li><a href="http://c2.com/cgi/wiki?BlubParadox">The Blub Paradox</a> says (among other things) that you can&#8217;t make anyone understand the power of a different language because developers become sedentary.</li>
<li>Good consultants are already busy so no one is going to save you.</li>
<li>Training or bootcamps won&#8217;t change your skillset or habits by a large percentage.</li>
</ul>
<p>Let me put this another way.</p>
<p>My cat will play with a toy on the floor.  And after a while, it becomes boring.  So she swats the toy under a cabinet.  And now it&#8217;s exciting!  She can barely reach the toy and its a challenge.  When she gets the toy out, she&#8217;ll bat it under the cabinet again.  What is she going to do?  Be bored again?  She&#8217;s good at reaching for the toy and using her claws to hook stuff, tail counter-balance to stay in control and seeing in dark places.  She needs to be playing under the cabinet and not given an mouse in a barrel.  This is what you must do.  You must improve your skills by going beyond &#8220;Good enough&#8221;.  Otherwise, you will stagnate and have limited tools and approaches to problems.</p>
<p>But how do you even know what to learn?  When you are looking up and down the power continuum in a problem domain, how can you grow beyond your own knowledge boundaries to see advantages that other people are enjoying?  If you were looking at a menu of pies, how would you choose which one you will like?</p>
<p>Here&#8217;s the pie menu.  Pick the one that you like!</p>
<p><code><br />
PIE MENU<br />
(all pies come with whipped cream on the side)<br />
---------------------------------------------<br />
Cranston Ermu Supreme Pie<br />
Tagasnackle Mound Blat Pie<br />
Rumination Flip Pie<br />
Rainclouds and Humility Pie<br />
Are You Seeing The Problem Pie</p>
<p>$3.99 per slice<br />
</code></p>
<p>What?  This is terrible.  This isn&#8217;t fair.  Certainly technology cannot be like this.  This is computer science!  How can you choose?  How can you know?</p>
<blockquote><p>
Hungry: &#8220;Waiter.  What&#8217;s in humility pie?&#8221;<br />
Waiter: &#8220;Humility.&#8221;<br />
Hungry: &#8220;What does that mean?&#8221;<br />
Waiter: &#8220;Have you ever literally tasted humility?&#8221;<br />
Hungry: &#8220;No.&#8221;<br />
Waiter: &#8220;Well it&#8217;s kind of like tasting regret but also different than pride.  You kind of taste like you should have prepared more or set expectations lower.&#8221;<br />
Hungry: &#8220;That doesn&#8217;t make any sense.&#8221;<br />
Waiter: &#8220;Of course it doesn&#8217;t.  It&#8217;s an experience.  It&#8217;s not a definition.&#8221;
</p></blockquote>
<p>Given enough questions, the Waiter will quit unless the Hungry customer chooses a pie or leaves.</p>
<p>Now let&#8217;s look at some horrifyingly contrived personalities looking down (or not looking down) the pie continuum.</p>
<h2>The Eternal Procedural Coder</h2>
<p>Let&#8217;s say you are a developer who just writes scripts all the time.  You piece things together and when they work the first time, you ship it (whatever shipping means to you).  If a more complicated task comes along, you don&#8217;t change your design, tools or strategy, you just change the amount of time you throw at it.  Once it works, you call it done.</p>
<li>If you don&#8217;t know how to build something in a variety of ways then you are always going to build it the same way.</li>
<li>If you don&#8217;t pre-learn outside work then you have to run to catch up to change your habits.</li>
<li>You can&#8217;t train new developers easily on what you are doing because everything you build is &#8220;your way&#8221;.</li>
<li>You can&#8217;t learn new techniques, tools or study good design because you don&#8217;t have time at work.</li>
<li>You don&#8217;t feel like learning on the weekend or after work.</li>
<li>When you look at another style, it looks like a bunch of crap and you don&#8217;t see the value/power/happiness/productivity/peace-of-mind because you haven&#8217;t gone through even one example yet.</li>
</ul>
<p>Exactly what is the exit strategy here?  What&#8217;s the end game?  Who or what is going to save you or change your situation?  What would the disruption look like?  What would the disruption be called?</p>
<p>Meanwhile, you hate looking at old code.  You wonder &#8220;what was I thinking?&#8221; or &#8220;I must have had a lot of coffee this day&#8221;.  Projects come and go, you hope you never have to go back to old projects.  You leave things alone because they are terrible but do the job.  You continually start new tasks but they all come out the same.  Huge single files, huge methods/functions.  One mess after another.  No wonder why they call this &#8220;work&#8221; right?  Who would do this for fun or learning?</p>
<p>What&#8217;s interesting is that The Blub Paradox applies here too.  It&#8217;s difficult to explain what development is supposed to be like to someone who has never had a success.  Success breeds success.  Failure is of course crucial to learning and courage is needed to fail when trying to succeed.  But experience really is the success side of trying and learning.  You can gain experience through failure but in terms of visualizing the ideal, success is very important.</p>
<h2>The It Can&#8217;t Be Done Guy</h2>
<p>Let&#8217;s say there&#8217;s a website called Searchbox.com that&#8217;s a stripped down version of Google.  In a meeting, everyone is talking about how Facebook search and Twitter are all hot right now and you feel like you are behind the curve.  So you decide you want to add friends, followers and other social features to Searchbox.com.  Your rockstar lead developer says &#8220;it can&#8217;t be done&#8221;.  No one questions him.  The idea dies, jokes are cracked and the grapes were probably sour anyway.  Yay team?</p>
<p>Software is supposed to be soft.  So why can certain things be so easy and other things be so hard?  I understand certain problems just &#8220;are hard&#8221; (concurrency, cache invalidation).  But not even entertaining ideas or experiments could be a sign of bad design.  Even with crappy procedural scripts, simple changes mean omfg-lots-of-lines changed.  Design isn&#8217;t about avoiding change (and change will happen), it&#8217;s about reducing the cost of change.</p>
<p>If you want to learn from a master, <a href="http://www.amazon.com/Practical-Object-Oriented-Design-Ruby-Addison-Wesley/dp/0321721330/ref=sr_1_1?ie=UTF8&#038;qid=1366558082&#038;sr=8-1&#038;keywords=poodr">read POODR</a>.  Sandi says:</p>
<blockquote><p>&#8230;successful but undesigned applications carry the seeds of their own destruction; they are easy to write but gradually become impossible to change.</p></blockquote>
<p>POODR is full of these insightful observations and Sandi doesn&#8217;t just give you advice.  She walks you through refactoring code and demonstrates the concepts that are related to these insights.</p>
<p>Anyway, back to our example project.  If searchbox.com is broken up into modules then there is a user class or object.  Surely this class could be forked into a feature branch and worked on in isolation by a few team members to add Friend and Follower traits/mixins/interfaces?  Or is the user really a session cookie combined with a database row and &#8220;who knows&#8221; how to change it?</p>
<p>If there isn&#8217;t really a concept of a user but it&#8217;s just a bunch of hacks then yes, no one is going to entertain massive changes to this concept of a &#8220;user&#8221;.  It&#8217;s too hard (in your system).  However, if a system was explicitly designed thoughtfully (not by default or by accident) then features are easy to add.  The software stays soft.  This is what Sandi is talking about in POODR.</p>
<h2>The Waterfall by Default Guy</h2>
<p>Let&#8217;s say there&#8217;s a guy in charge of a project.  He hasn&#8217;t ever tried Agile of any sort.  He&#8217;s read about it and he&#8217;s confident that he knows all about it.  He thinks it sounds crazy, lazy and chaotic.  He&#8217;s done plenty of projects in the past that have come out under-budget and on-time so why change anything?  On the other hand, he&#8217;s not technical so his opinion of past projects is completely dependent on the feedback given to him by developers.  If developers ever felt like talking to him was a waste of time then his opinion of how good &#8220;waterfall&#8221; is could be slightly off.  The real question is, can you explain how delicious Agile Pie is to him?</p>
<p>Here&#8217;s the wheelhouse of agile type stuff.</p>
<ul>
<li>Developers aren&#8217;t going to want to work with you again if you burn them out.</li>
<li>Project heroes burn out.</li>
<li>You can&#8217;t hire your way out of a failing project.</li>
<li>Most people don&#8217;t like the term Waterfall because it&#8217;s viewed old.</li>
<li>If you don&#8217;t declare a methodology it&#8217;s Waterfall by default.</li>
<li>You can&#8217;t do Agile.  Agile is a type of thing.  Like Car.  You have to buy a type of Car.</li>
</ul>
<p>So when you try to explain any type of agile techniques to someone who doesn&#8217;t have any experience with it, it&#8217;s the same thing as the Blub Paradox.  The Waterfall Guy is happy enough doing no explicit methodology, why would he change?  When asked how to prevent projects from getting off-track he will say, &#8220;before you start working on a project, you need to know what you are building&#8221;.  Even though Agile (and common sense) says that <strong>both the customer and the developers</strong> are the stupidest at the beginning of a project.  Big Design Up Front (BDUF) doesn&#8217;t work.  BDUF is undesigned project methodology.  BDUF is how you put together simple things like grocery lists and legos.  BDUF isn&#8217;t how you deal with change and complicated systems where developers will upscale the project difficulty until it becomes interesting.</p>
<p>So even if you discuss these items with Waterfall Guy, he&#8217;s not going to get a taste of Agile Pie without eating it.  You could talk all day long about the ingredients, how people keep eating it, how there&#8217;s these case studies showing it&#8217;s delicious.  &#8220;Meh, whatever.  I have my dessert already.&#8221;  At the same time, Waterfall Guy is always asking for visibility as to what developers are doing through status reports.  In his heart he knows that he has a few hero developers and if he loses them, he&#8217;s screwed.  That&#8217;s ok, that&#8217;s why they call it work right?</p>
<h2>The Non-Tester</h2>
<p>There&#8217;s a team who are running a production app.  They have a testing team.  When developers are working on &#8220;omg the really important thing&#8221;, they tell the testing team to run &#8220;whatever test&#8221;.  It usually involves someone manually going down a list with a pencil.  When a problem is found then a tester will tell a developer something went wrong.  &#8220;It showed me this error 0&#215;2123 when I did the thing you told me to do.&#8221;</p>
<p>Except a lot of the time there isn&#8217;t anything wrong.  A lot of times the problem is the testers aren&#8217;t developers.  Otherwise, they&#8217;d be developers.  A lot of times the tester doesn&#8217;t really understand the system and the developer has to explain the system to them.  So while the developer is working on &#8220;omg the next really important thing&#8221; the tester is asking questions and the developer is getting annoyed.  Jokes are made &#8220;you only come to me when there&#8217;s a problem, haha&#8221;.  Or, &#8220;I bug you so much I owe you a beer!  Haha.&#8221;.</p>
<p>Looking down the power continuum, a developer looks at testing libraries.  They look annoying and time-consuming.  Who needs this hassle?  They don&#8217;t have time to find out if they do.  They don&#8217;t understand the different levels of testing (from most involved and beneficial):</p>
<ul>
<li>No testing at all &#8211; you have to hit refresh in a browser and you have no idea if you broke anything else.  Old bugs pop up.</li>
<li>Some testing &#8211; unit tests but you have a team run through end-to-end scenarios.</li>
<li>A lot of testing &#8211; you have unit and integration tests and maybe even code coverage reports and CI.</li>
<li>Test-first development &#8211; you write your tests before code but that&#8217;s the end of that methodology.</li>
<li>Test-driven development (TDD) &#8211; you let your tests completely drive the design of the system.</li>
<li>Testing end game &#8211; You do red-green-refactor.  Your tests run fast.  You do UI testing.  Your customer requirements map to easily read executable stories.  You spend very little time in red.  You ping-pong pair with TDD.  No code is committed without passing CI.  Your testing tools and process are constantly evolving in response to pain points.</li>
</ul>
<p>The non-tester doesn&#8217;t see the value or the constant effort people are making to try to get to the <em>Testing End Game</em>.  &#8220;I&#8217;m not a tester!  Why would I test!&#8221;  Meanwhile, they complain about how little time they have because they have to manually have to see if their code works.  Or maybe they are embarrassed / mad / frustrated that they broke the development/production build.  In essence, the Blub Paradox is telling us that they can&#8217;t see their problems through the lens of Blub because they don&#8217;t know Blub.  Meanwhile, Blub (TDD) practitioners can&#8217;t imagine doing it the way the non-tester does it.  In fact, TDD practitioners are honing their craft so much that it is a rare event when they&#8217;ll take the time to explain TDD or the End Game to a non-tester.  Even if they do, both will be frustrated because any insight or evangelizing will be misunderstood.</p>
<h2>The Long Time Ignorant</h2>
<p>Take any of the above and put it in the context of time.  How long has SQL been around?  Does someone on your team not know SQL?  Is it because they haven&#8217;t needed it?  What if they are writing flat database files by hand and do need SQL?  Have they just been living under a rock or can no one change their mind?  What can you do as an individual to change such a blind eye?</p>
<p>How long has JUnit been around?  Is there a Java developer you know that hasn&#8217;t written a unit test?  Or they have written a few but they don&#8217;t anymore because they think they don&#8217;t have time to do it?</p>
<h2>That Seems Hard</h2>
<p>Someone who can only write code in a procedural style can&#8217;t break down problems into easily solvable bits.  Without concepts like Mixins/Traits, Composing Behavior and TDD; a complex problem is just going to seem too hard.  &#8220;I don&#8217;t do that kind of stuff.&#8221;  When someone that has OO or Functional experience might say &#8220;here&#8217;s how I would do it, who wants to help me?&#8221;  Of course there are things that are just too big but the difference is in experience.  A Bash scripter isn&#8217;t ever going to understand ncurses events because they haven&#8217;t ever written a desktop GUI.  So even though ncurses can be great for turning &#8220;scripts&#8221; into &#8220;programs&#8221;, they are going to shy away from ncurses because &#8220;wtf that seems hard&#8221;.</p>
<ul>
<li>You can&#8217;t explain the benefits of a web framework because of the Blub Paradox.</li>
<li>You can&#8217;t explain the benefits of an ORM vs raw SQL because of the Blub Paradox.</li>
<li>You can&#8217;t explain the advantages of tmux to someone because of the Blub Paradox.  Even while they keep losing their ssh sessions over unstable wifi.  Given a simple enough problem, you might be able to convince them to try it out.</li>
</ul>
<p>Tmux is a perfect example.  No one understands how great it is until they use it.  Then and only then do they never want to go back.  Tmux isn&#8217;t always great though.  Sometimes the terminal gets all weird with certain keyboards or maybe you want the native buffer scrollback to work.  So it&#8217;s not some silver bullet default.  However, once you grok tmux, you know when to use it and miss it when you don&#8217;t have it.  This is true for many things that people evangelize.  However, sometimes you need to understand their world view and take that into consideration.</p>
<p>Tmux pie is delicious.  Ask anyone who has tried it.</p>
<h2>Answers</h2>
<p>I don&#8217;t have all the answers.  Ok, see you later.  *silence*  Well listening to Rubyrogues and reading POODR has given me some memorable advice which I&#8217;ll repeat here.</p>
<ul>
<li>Spike on foreign concepts.  Ok, you don&#8217;t know OOP and breaking down problems.  Make up a problem and do it.  Don&#8217;t try to learn in your main project.  Spike on a concept and throw the code away.</li>
<li>Pair with someone who knows this stuff and check your ego at the door.  When you are lost, don&#8217;t play with your iPhone.  Ask questions.  Pretend to be stupid.  Check your ego.</li>
<li>Learn a different tech stack.  When I write Java (poorly these days), I bring Ruby experiences back with me.</li>
<li>Watch conference videos and screencasts.  Pre-learn before work.  You have no choice.  No one is going to pay you to get better.</li>
<li>Read the POODR book even if you&#8217;re not a Rubyist.</li>
<li>If you are resistent to an idea, change sides.  Let&#8217;s say you don&#8217;t like soccer.  Take the position of a soccer fan and argue with yourself.  You might be amazed at the argument you make just looking from another perspective.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2013/04/21/the-blub-paradox-and-delicious-pie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby p385 benchmarks</title>
		<link>http://squarism.com/2013/02/16/ruby-p385-benchmarks/</link>
		<comments>http://squarism.com/2013/02/16/ruby-p385-benchmarks/#comments</comments>
		<pubDate>Sat, 16 Feb 2013 19:14:56 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1814</guid>
		<description><![CDATA[I was playing around with the falcon p385 patch to see if it&#8217;s any faster than some of the more recent MRI rubies. TL;DR version: looks like p192 is faster than p385 of any type or tweak. Here&#8217;s how to get a p385 Ruby version patched with funny falcon&#8217;s performance patches using RVM. mkdir ~/.rvm/patches/ruby/1.9.3/p385 [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2013/02/pixel-ribbon_electric_fun.png" alt="pixel-ribbon_electric_fun" width="576" height="24" class="aligncenter size-full wp-image-1991" /></p>
<p>I was playing around with the falcon p385 patch to see if it&#8217;s any faster than some of the more recent MRI rubies.<br />
<strong>TL;DR version: looks like p192 is faster than p385 of any type or tweak.</strong></p>
<p>Here&#8217;s how to get a p385 Ruby version patched with funny falcon&#8217;s performance patches using RVM.<br />
<code><br />
mkdir ~/.rvm/patches/ruby/1.9.3/p385<br />
curl https://github.com/funny-falcon/ruby/compare/p385...p385_falcon.diff > \<br />
$rvm_path/patches/ruby/1.9.3/p385/falcon.patch<br />
rvm install 1.9.3-p385 -n perf --patch falcon<br />
</code><br />
Then rvm use 1.9.3-p385-perf or set it as your global ruby.  </p>
<h3>Test Setup</h3>
<p>The following benchmarks were run on an i7 server with a RAID5 array.  The disk is slow (lack of large cache) but the benchmarks were run on the same box so it should compare apples-to-apples.</p>
<p>From here on out, here are the definitions for the Ruby versions.<br />
p194 = 1.9.3p194 default<br />
p385 = 1.9.3p385 default<br />
falcon = 1.9.3p385 with the above falcon diff patch applied<br />
gcc_tweak = the falcon patches with GCC compile flags tweaked.</p>
<p>So what are these GCC tweaks?  Explicitly setting the CFLAGS for your machine&#8217;s CPU type and recompiling ruby with the Falcon patches applied.</p>
<h3>Micro and Macro Benchmarks</h3>
<p>I used the <a href="https://github.com/acangiano/ruby-benchmark-suite">ruby-benchmark-suite</a> to run these tests.</p>
<p>Here are some example results.  I can&#8217;t list them all.  There are over 100 benchmarks.  These are results for the mean times in seconds.</p>
<table>
<th>test</th>
<th>1.9.3p194</th>
<th>1.9.3p385</th>
<th>falcon</th>
<th>gcc_tweak</th>
<tr>
<td>bm_sudoku.rb</td>
<td>1.379112226</td>
<td>1.598182153</td>
<td>1.495923579</td>
<td>1.526717563</td>
</tr>
<tr>
<td>bm_open_many_files.rb</td>
<td>0.175602996</td>
<td>0.197096826</td>
<td>0.197673286</td>
<td>0.194135045</td>
</tr>
</tr>
<td>&#8230; etc etc</td>
</tr>
</table>
<p>Here&#8217;s the winner summary for mean times.  This is the number of times the ruby version was the fastest for a particular benchmark.<br />
1.9.3p194 &#8211; 64 wins<br />
1.9.3p385 &#8211; 29 wins<br />
1.9.3p385-falcon with GCC tweaks &#8211; 10 wins<br />
1.9.3p385-falcon 5 wins</p>
<h3>Boot time and IO</h3>
<p>Timing rails boot time is a bit more important to me.  If you want to know how to really save &#8220;rails boot time&#8221; see the <a href="https://www.destroyallsoftware.com/screencasts/catalog/fast-tests-with-and-without-rails">DAS screencast on not loading Rails at all</a>.</p>
<p>Even when using domain objects and lib tricks, it&#8217;s nice to have Rails and all I/O boot fast.  The main thing that funny falcon&#8217;s patches do is speed up requires and I/O.</p>
<p>So let&#8217;s benchmark booting a Rails app.<br />
$ time bundle exec rake environment</p>
<table>
<th>Ruby Version</th>
<th>Seconds</th>
<tr>
<td>p385 patched with falcon and GCC tweaks</td>
<td>2.481 total</td>
</tr>
<tr>
<td>p374 defaults</td>
<td>3.336 total</td>
</tr>
<tr>
<td>2.0.0-rc2</td>
<td>2.613 total</td>
</tr>
</table>
<p>In conclusion, p194 looks faster on the macro and micro benchmarks but Falcon patches boot Rails faster.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2013/02/16/ruby-p385-benchmarks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hash Choices</title>
		<link>http://squarism.com/2013/02/12/hash-choice/</link>
		<comments>http://squarism.com/2013/02/12/hash-choice/#comments</comments>
		<pubDate>Wed, 13 Feb 2013 04:26:27 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1799</guid>
		<description><![CDATA[As I&#8217;ve previously talked about, Hashes of Hashes are weird to work with. In the previous post about Captain Planet, I showed how to select, filter and manipulate 2D hashes and arrays but ultimately concluded that a hash of hashes is both weird and unnecessary (most of the time). If you can control the data, [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2013/02/bttf.png" alt="bttf" width="188" height="91" class="alignright size-full wp-image-1803" /></p>
<p>As I&#8217;ve <a href="http://squarism.com/2011/12/04/hash-of-hashes-and-captain-planet/">previously talked about</a>, <em>Hashes of Hashes</em> are weird to work with.  In the previous post about Captain Planet, I showed how to select, filter and manipulate 2D hashes and arrays but ultimately concluded that a hash of hashes is both weird and unnecessary (most of the time).</p>
<p>If you can control the data, inline your key into the hash data and make an <em>Array of Hashes</em>.  It&#8217;s really where it belongs.  If you don&#8217;t, you&#8217;ll find yourself doing a few extra iterations or work.  Below you&#8217;ll see a simple example of the two data structures.</p>
<p></p><pre class="crayon-plain-tag"># Hash of Hashes
{
  :dave =&gt; { :age =&gt; 1, :height =&gt; 2 },
  :tony =&gt; { :age =&gt; 1, :height =&gt; 2 }
}</pre><p></p>
<p></p><pre class="crayon-plain-tag"># Better --&gt; Array of Hashes
[
  { :id =&gt; 'dave', :age =&gt; 1, :height =&gt; 2 },
  { :id =&gt; 'tony', :age =&gt; 1, :height =&gt; 2 }
]</pre><p></p>
<p>In this case of an array of hashes, the data is easier to manipulate with array operations and filters.  But before talking about matching on arrays of hashes, I want to talk about matching on dates.</p>
<p></p><pre class="crayon-plain-tag">doc = Date.parse &quot;Nov 12 1955&quot;
marty = Date.parse &quot;Oct 27 1985&quot;
future = Date.parse &quot;Jan 13 2094&quot;
doc &lt; marty
=&gt; true</pre><p></p>
<p>So comparisons with dates work like you might expect.  But fuzzy matches do not.  Take this example.  Is Marty in between Doc Brown and the distant future?  The answer should be true.</p>
<p>We use a Range (x..y) object to make a date range.  Then we can use === to check if we get a match.</p><pre class="crayon-plain-tag">marty === (doc .. future)  # wrong, wrong, wrong
=&gt; nil</pre><p></p>
<p>But wait, === on Date is different than === on Range.  The method === on Date checks to see if it&#8217;s the same Date whereas === on Range checks to see if the argument is within the range.  So if you flip it, it returns true.</p>
<p></p><pre class="crayon-plain-tag">(doc .. future) === marty
=&gt; true</pre><p></p>
<p></p><pre class="crayon-plain-tag">require 'date'

holidays = {
  :halloween =&gt; { :date =&gt; Date.parse(&quot;Oct 31 2012&quot;), :presents =&gt; false },
  :christmas =&gt; { :date =&gt; Date.parse(&quot;Dec 25 2012&quot;), :presents =&gt; true },
  :july_fourth =&gt; { :date =&gt; Date.parse(&quot;July 4 2013&quot;), :presents =&gt; false },
  :valentines_day =&gt; { :date =&gt; Date.parse(&quot;Feb 14 2013&quot;), :presents =&gt; true },
  :thanksgiving =&gt; { :date =&gt; Date.parse(&quot;Nov 28 2012&quot;), :presents =&gt; false }
}

# turn hash of hashes into array of hashes
holiday_array = []
holidays.keys.each do |key|
  holiday_array &lt;&lt; { :id =&gt; key }.merge(holidays[key])
end

# find all the holidays with presents
puts &quot;yay presents!&quot;
puts holiday_array.select {|holiday| holiday[:presents] == true }

# find all the holidays within a date range
winter = (Date.parse(&quot;Dec 21 2012&quot;)..Date.parse(&quot;Mar 20 2013&quot;))

puts &quot;Winter holidays&quot;
puts holiday_array.select {|h| winter === h[:date] }</pre><p></p>
<p>So what we did in the middle there was flatten the hash of hashes into an array of hashes by merging the key with the &#8216;data&#8217; part of the hash.  Hopefully that makes sense.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2013/02/12/hash-choice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What a tech stack has to do on our first date</title>
		<link>http://squarism.com/2012/11/30/what-a-tech-stack-has-to-do-on-our-first-date/</link>
		<comments>http://squarism.com/2012/11/30/what-a-tech-stack-has-to-do-on-our-first-date/#comments</comments>
		<pubDate>Sat, 01 Dec 2012 02:04:09 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1784</guid>
		<description><![CDATA[Listen to Dave Thomas Watch this video -> please. Start at 45:50 and watch at least 10 minutes. I tell a lot of people about this video. I don&#8217;t tell 10,000 people up on a stage on some world tour. But whenever I get into a good discussion with geeks, I reference this video and [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2012/11/monolingual.png" alt="" title="monolingual" width="319" height="156" class="aligncenter size-full wp-image-1789" /></p>
<h2>Listen to Dave Thomas</h2>
<p>Watch this video -> <a href="http://www.confreaks.com/videos/368-rubyconf2010-keynote">please</a>.  Start at 45:50 and watch at least 10 minutes.</p>
<p>I tell a lot of people about this video.  I don&#8217;t tell 10,000 people up on a stage on some world tour.  But whenever I get into a <em>good</em> discussion with geeks, I reference this video and tell them to watch it.  So I tell a lot of people in terms of <strong>percentage</strong> in conversations that I&#8217;m enjoying.  So in other words, I really like the video personally, it struck a chord (or a brain-thorn) and I want other people to consider his point of view.  Specifically, Dave Thomas says you <em>should learn a new language every year</em>.  Invariably, I&#8217;ll tell people that Dave Thomas writes books and a few times people will dismiss his main idea because they think he&#8217;s selling books.</p>
<p>Dismissing Dave Thomas&#8217; opinion that you should learn a new language every year just because he is an author is a crap position to take.  First, FUD.  Second, Dave Thomas doesn&#8217;t sell books about the languages he says to check out in the video.  Thirdly, I trust Dave Thomas.  This isn&#8217;t some fucking Larry Ellison power play.</p>
<p>So in terms of following his advice, I might pick up Scala.  It&#8217;s different enough and anti-hipster-omg-embrace-the-java-enterprise enough that it will challenge me and/or be different than say continuing with Python (will is really Ruby like Spanish to Portugese) learning.  I&#8217;ve picked up <a href="http://www.amazon.com/Programming-Scala-Comprehensive-Step---Step/dp/0981531644/ref=sr_1_1?ie=UTF8&#038;qid=1353200587&#038;sr=8-1&#038;keywords=scala">a Scala book</a> but haven&#8217;t started it yet.  I looked at the Lift docs and was completely deflated.  <a href="https://twitter.com/chadfowler">Chad Fowler</a> tweeted about the Play! framework (thanks for the reminder) and thank god this looks better.</p>
<p>If I get sick of a city, I might move.  When I move, I&#8217;m looking for something new.  Similarly, starting out with Scala is going to be a bit like jumping into a new town.  Ok, I need to find the equivalents of the old things that I&#8217;m used to.  But wait, I moved to a new town to do something new!  If I bring my old habits with me, I&#8217;ll just be <em>writing Ruby code in Scala</em>.  And that&#8217;s crap.</p>
<blockquote><p>
Marge: I&#8217;ve dug myself into a happy little rut here and I&#8217;m not about to<br />
       hoist myself out of it.<br />
Homer: Just bring the rut with ya, Honey.<br />
&#8211; &#8220;<a href="http://www.snpp.com/episodes/3F23.html">You Only Move Twice</a>&#8221;
</p></blockquote>
<h2>What any technology stack is going to have to do on our first date</h2>
<p>I need a list of libraries at least searchable by category and popularity.  Popular gems are likely to be used and therefore good.  This is great to get to higher level operations and gain productivity.  For example, <a href="http://ruby-toolbox.com">ruby-toolbox.com</a>.</p>
<p>I need screencasts ordered by date so you can learn community trends.  I&#8217;m going to need a way to keep up with the Jones&#8217; and know what&#8217;s falling out of favor in the community because a shiny new library, technique or concept is getting the attention of key people.  This also operates as curated content.  For example, everyone is talking about CORS.  I&#8217;m sure there will be a <a href="http://railscasts.com">Railscast</a> on CORS even though CORS is not specific to Ruby or Rails.</p>
<p>Related to that last point, the community should be of high quality.  I know people like to hate on PHP but if you took a <a href="http://en.wikipedia.org/wiki/Core_sample">core sample</a> of PHP-land, I think you wouldn&#8217;t be too happy.  Of course there are exceptions, for example, Facebook is full of brilliance.</p>
<p>Some easy way to install things that&#8217;s Internet-enabled.  Maven is close.  Rubygems is good.  NPM is good.  Yum beats plain RPM.  Pip is fine.  CPAN is crap.  All these package managers connect to the Internet and resolve dependencies.  As a bonus, being able to repackage, bundle, freeze or tar up libs into a lib directory is great for corporate firewalls or making deployment not suck so hard.</p>
<p>I need a way to separate projects from one another.  Gemsets with RVM does this.  Virtualenv does this with projects.  Lib implicitly does this in Java (although CLASSPATH issues suck).  Explicit project isolation with libs is great.</p>
<p>Give me videos from the community like <a href="http://confreaks.com/">Confreaks</a>.  Video community talks are necessary.  The JavaOne video site sucks and only because of the content.  It doesn&#8217;t have to be flashy and overly-produced.  Oracle publishes <a href="http://www.oracle.com/javaone/live/on-demand/index.html">3 minute videos</a> with zero details and zero content.  Yay?</p>
<p>I need quick feedback.  This means a REPL and/or event-based test suite runners.  If I save a file, I want a test to run (Ruby&#8217;s Guard gem).  If I want to figure out how to do something, I want it to be instant feedback.  About the farthest thing I can think of away from this is deploying to Tomcat, reloading the webapp and hitting refresh in a browser (#fml).</p>
<h2>I&#8217;ll call Scala back</h2>
<p>So far, Scala has the REPL thing down (just type $ scala).  And the SBT tool does auto-reloading similar to Guard.  Of course, it has to compile things so it&#8217;s slightly a slower feedback loop but it&#8217;s not terrible.  SBT also seems to have a manifest thing going on for the equivalent of gemsets.  It all goes in project/plugins.sbt which is great.  There&#8217;s also a concept of a global project in a ~/.sbt folder.  This reminds me a lot of NPM.</p>
<p>I haven&#8217;t discovered the community side of things yet like screencasts (railscasts) or a news site (rubyflow).  On the negative side, there seems to be some Java crosstalk.  For example the Play! framework can generate a Scala or a Java project.  So if you are trying to get away from Java, this is a good step away but not a clean break.  I get a feeling of Java refugee camp (which is fine).</p>
<p>Something I&#8217;m working on right now is understanding the IDE landscape.  Eclipse was a bit weird with loading the Scala plugins and Intellij is coming out with a new version of IDEA soon.  Also I need to grok the sbt-console inside the IDEA plugin vs command line.  Are they the same?  I had this same challenge when trying RubyMine.  At some point you have to get a feel for what the One True Way was intended to be.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/11/30/what-a-tech-stack-has-to-do-on-our-first-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Hawtnesses</title>
		<link>http://squarism.com/2012/11/12/new-hawtnesses/</link>
		<comments>http://squarism.com/2012/11/12/new-hawtnesses/#comments</comments>
		<pubDate>Mon, 12 Nov 2012 17:04:25 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1776</guid>
		<description><![CDATA[Wow, how can anyone keep up? Zeus Video of Zeus in action. Is it the new spork? Super fast Rails boot times, but not just booting. Everything! Like DRB on steroids. FishFish shell `brew install fishfish`. The new ZSH? A fork of the Fish shell. Featured in the above video link. Be sure to uninstall [...]]]></description>
				<content:encoded><![CDATA[<p>Wow, how can anyone keep up?</p>
<h2>Zeus</h2>
<p><a href="https://vimeo.com/46795747">Video of Zeus in action</a>.  Is it the new spork?<br />
<img src="http://squarism.com/wp-content/uploads/2012/11/zeus-580x307.png" alt="" title="zeus" width="580" height="307" class="aligncenter size-large wp-image-1778" /><br />
Super fast Rails boot times, but not just booting.  Everything!  Like DRB on steroids.</p>
<h2>FishFish shell</h2>
<p>`brew install fishfish`.  The new ZSH?  A fork of the Fish shell.  Featured in the above video link.  Be sure to uninstall fish through homebrew if you have already.  It&#8217;s not the same thing.</p>
<h2>YADR</h2>
<p><img src="http://squarism.com/wp-content/uploads/2012/11/yadr-580x444.png" alt="" title="yadr" width="580" height="444" class="aligncenter size-large wp-image-1777" /><br />
<a href="http://skwp.github.com/dotfiles/">YADR</a> &#8211; for me, the new codegram/vimfiles?  Impressive documentation, will really change my muscle memory.</p>
<h2>Prezto</h2>
<p>Included with YADR, looks to be a replacement for oh-my-zsh (my fav).  Will have to try it out and update this.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/11/12/new-hawtnesses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVN vs Git Speed</title>
		<link>http://squarism.com/2012/10/12/svn-vs-git-speed/</link>
		<comments>http://squarism.com/2012/10/12/svn-vs-git-speed/#comments</comments>
		<pubDate>Sat, 13 Oct 2012 03:00:57 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1754</guid>
		<description><![CDATA[This is a bit of shooting fish in a barrel but I really wanted to see if for myself. After using SVN for many years, I knew Git was fast. Funny enough, I didn&#8217;t know SVN was slow until I saw Git was fast. Hah. Anyway, I wrote a script that does this: Creates a [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2012/10/git_logo-300x125.png" alt="" title="git_logo" width="300" height="125" class="alignright size-medium wp-image-1758" /><br />
This is a bit of shooting fish in a barrel but I really wanted to see if for myself.  After using SVN for many years, I knew Git was fast.  Funny enough, I didn&#8217;t know SVN was slow until I saw Git was fast.  Hah.</p>
<p>Anyway, I wrote a script that does this:</p>
<ul>
<li>Creates a repo</li>
<li>Unzips Linux 3.6.1 source</li>
<li>Add all files / commit all files</li>
<li>Branch / Modify / Commit / Merge (3 times)</li>
<li>Cleans up branches, cleans up temp directories</li>
</ul>
<p>The Linux kernel source is 79MB, ~42,000 files.  So this is a bit excessive.  You probably won&#8217;t be working with a project this large.  However, it&#8217;s a good way to show speed and performance.</p>
<p>The other interesting thing that I found while doing this test is how much longer my SVN script turned out to be.  Both scripts do the same thing but the Git script was much shorter.  So in a way, Git seems to be faster and easier (or at least less typing) at the same time.</p>
<p>A note about the benchmarks.  The Raid 5 test was done on a web server with a Raid controller that has very little cache.  No question that these spinning disks are a bit slow under load.  However, the tests were done on the same box so it&#8217;s still a fair comparison.  The SSD row is a virtual ubuntu machine on an SSD; a different machine all together.</p>
<p><strong>Benchmark Times mm:ss</strong></p>
<table>
<th>Disk type</th>
<th>SVN</th>
<th>Git</th>
<tr>
<td>Raid5</td>
<td>14:56</td>
<td>01:08</td>
</tr>
<tr>
<td>SSD</td>
<td>17:12</td>
<td>02:09</td>
</tr>
</table>
<p>Git has a bit of an advantage by doing 3 branches because it does its garbage collection only once on the first merge.  So I apologize for the bias.  I can say for sure that the one branch test was something like this: SVN 20min, Git 2min.</p>
<p>Here are the links to the scripts I wrote if you want to try them yourself.<br />
<a href="https://gist.github.com/3882985">svn_stress.sh</a><br />
<a href="https://gist.github.com/3882986">git_stress.sh</a></p>
<p>Run the scripts with the time command:</p><pre class="crayon-plain-tag">$ time ./svn_stress.sh /tmp/stress_test
233.78s user 81.81s system 35% cpu 14:56.48 total</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/10/12/svn-vs-git-speed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby DCamp 2012!</title>
		<link>http://squarism.com/2012/10/01/ruby-dcamp-2012/</link>
		<comments>http://squarism.com/2012/10/01/ruby-dcamp-2012/#comments</comments>
		<pubDate>Mon, 01 Oct 2012 22:47:22 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1744</guid>
		<description><![CDATA[Great conference! There&#8217;s a lot to be said about it. I am not going to post it all, it would take a long of writing. You can find things about #coderetreat meetups out there. After decompressing and reflecting, I came to a philosophical realization. Rubyists were not taught Ruby in school or elsewhere, they willed [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2012/10/rubydcamp_2012-580x434.jpg" alt="" title="rubydcamp_2012" width="580" height="434" class="aligncenter size-large wp-image-1747" /><br />
Great conference!  There&#8217;s a lot to be said about it.  I am not going to post it all, it would take a long of writing.  You can find things about #coderetreat <a href="http://coderetreat.org/profiles/blogs/coderetreat-london-29-09-12">meetups out there</a>.</p>
<p>After decompressing and reflecting, I came to a philosophical realization.</p>
<ul>
<li>Rubyists were not taught Ruby in school or elsewhere, they willed their skill into existence.</li>
<li>Internet access came through the air over cell and we suddenly had dev environments in the middle of the woods.</li>
<li>The wikipedia description of game of life was just some english bullet points that were implemented 100 times</li>
</ul>
<p>So in these three ways, we willed things out of the ether and that is awesome.</p>
<p>For a less philosophical run-down of what happened, check out <a href="http://brandonhays.com/blog/2012/10/04/ruby-dcamp-what-i-learned-on-summer-vacation/">Brandon Hays&#8217;s blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/10/01/ruby-dcamp-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing the TextMate Comment Banner</title>
		<link>http://squarism.com/2012/09/24/changing-the-textmate-comment-banner/</link>
		<comments>http://squarism.com/2012/09/24/changing-the-textmate-comment-banner/#comments</comments>
		<pubDate>Tue, 25 Sep 2012 03:39:59 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1736</guid>
		<description><![CDATA[I like to put a little date banner on files that are like a CHANGELOG. The Insert Comment Banner in Textmate is great for this. You just hit Ctrl+Shift+B and this appears: ========= = Banner ========= And the equal signs on top and bottom adjust as you type in &#8220;Banner&#8221;. It&#8217;s pretty cool. But what [...]]]></description>
				<content:encoded><![CDATA[<p>I like to put a little date banner on files that are like a CHANGELOG.  The Insert Comment Banner in Textmate is great for this.  You just hit Ctrl+Shift+B and this appears:<br />
<code>=========<br />
= Banner<br />
=========</code><br />
And the equal signs on top and bottom adjust as you type in &#8220;Banner&#8221;.  It&#8217;s pretty cool.  But what I wanted is a timestamp in the banner.  So I&#8217;d leave Banner highlighted and then right click in Textmate and select &#8220;Filter through command&#8221; and put the Unix command date in there.  That&#8217;s great except it puts Fri Jan 20 21:46:13 EDT 2034 in there which is a bit long.</p>
<p><code>===============================<br />
= Fri Jan 1 21:46:13 EDT 2034<br />
===============================</code></p>
<p>Too long.  So here&#8217;s what you can do.  Go to Bundles->Bundle Editor->Show Bundle Editor.  Then go to the Source category.  You can filter at the top for Snippets if it&#8217;s easier.  See this picture.</p>
<p><img src="http://squarism.com/wp-content/uploads/2012/09/snippet_banner-580x431.png" alt="" title="snippet_banner" width="580" height="431" class="aligncenter size-large wp-image-1739" /></p>
<p>Then put this code in:</p><pre class="crayon-plain-tag">${TM_COMMENT_START/\s*$//}==${1/(.)|(?m:\n.*)/(?1:=)/g}==${TM_COMMENT_END/^\s*(.+)/ $1/}
${TM_COMMENT_START/\s*$//}= ${1:${TM_SELECTED_TEXT:`date +'%a %b %d %Y'`}} =${TM_COMMENT_END/\s*(.+)/ $1/}
${TM_COMMENT_START/\s*$//}==${1/(.)|(?m:\n.*)/(?1:=)/g}==${TM_COMMENT_END/\s*(.+)/ $1/}</pre><p></p>
<p>This will give you a banner like this:<br />
<code>===================<br />
= Fri Jan 1 2034 =<br />
===================</code></p>
<p>And it&#8217;ll be the right length automatically.  Nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/09/24/changing-the-textmate-comment-banner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Caching an Object in Rails is Easy</title>
		<link>http://squarism.com/2012/09/23/caching-an-object-in-rails-is-eas/</link>
		<comments>http://squarism.com/2012/09/23/caching-an-object-in-rails-is-eas/#comments</comments>
		<pubDate>Mon, 24 Sep 2012 00:11:08 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1490</guid>
		<description><![CDATA[Caching in Rails is really simple (straight from the docs): You can set up your application’s default cache store by calling config.cache_store= in the Application definition inside your config/application.rb file or in an Application.configure block in an environment specific configuration file (i.e. config/environments/*.rb). The first argument will be the cache store to use and the [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2013/04/good_enough_mono-580x24.png" alt="good_enough_mono" width="580" height="24" class="aligncenter size-large wp-image-1880" /></p>
<p>Caching in Rails is really simple (straight from the docs):</p>
<p><em>You can set up your application’s default cache store by calling config.cache_store= in the Application definition inside your config/application.rb file or in an Application.configure block in an environment specific configuration file (i.e. config/environments/*.rb). The first argument will be the cache store to use and the rest of the argument will be passed as arguments to the cache store constructor.<br />
</em></p>
<p>Originally, I didn&#8217;t even know it was there.  So I was thinking I&#8217;d just create a hash in memory.  So I wrote my own cache class like this (homegrown_cache.rb):</p><pre class="crayon-plain-tag"># not exactly a pure cache, implements the lookup or expensive operation too
# probably needs to be decoupled

class Cache
  def initialize
    @cache = {}
  end

  def cache(name, values = {})
    if values = {}
      return @cache[name.to_sym]
    else
      @cache[name.to_sym] ||= values
    end
  end

  def search(name)
    if @cache.keys.include?(name.to_sym)
      puts &quot;getting name from cache instead of expensive operation&quot;
      return @cache[name.to_sym]
    else
      self.cache(name, Expensive::Search(name))
      return @cache[name.to_sym]
    end
  end

  def clear
    cache_size = @cache.length
    @cache = {}
    return cache_size
  end

  def to_s
    &quot;#&lt;Cache:#{self.object_id} Cache Size: #{@cache.length}&gt;&quot;
  end

  def size
    @cache.length
  end

end</pre><p></p>
<p>Then you might want to use it in an implementation like like CacheEnabledSearch or something like that within your app.</p>
<p>But it&#8217;s way easier and smarter to just use the <del datetime="2011-12-08T17:24:46+00:00">goddamn</del> caching that&#8217;s built into Rails.  Specifically, if you use the in memory store, since Rails 3.0 <strong>it&#8217;s thread safe</strong>.  Meaning if two clients hit your cache, you&#8217;re not going to have weird bugs pop up.  It&#8217;s very easy to configure and use.</p>
<p>I&#8217;m posting the Cache class anyway though it&#8217;s interesting how simple an object it is without being thread-safe.  But even then, I&#8217;d recommend using the cache class from Rails outside of Rails.</p>
<p>So here&#8217;s how you&#8217;d use Rails caching &#8220;without&#8221; Rails.  In other words, a console app.</p><pre class="crayon-plain-tag"># using the Rails caching class outside of rails
require 'active_support'

# 
cache = ActiveSupport::Cache::MemoryStore.new
cache.write('user', 'bob')
# =&gt; true
puts cache.read('user')
# =&gt; bob</pre><p></p>
<p>Not particularly interesting.  This would be way more useful inside of a Rails app where a singleton class called Rails.cache is set <a href="http://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-memorystore">if you have something set in your config</a>:<br />
<code>config.cache_store = :memory_store</code></p>
<p>Let&#8217;s avoid the Rails situation for now and create a file cache directory for a file based cache:<br />
<code>$ mkdir /tmp/poro_cache</code></p>
<p>Here&#8217;s a complete example.</p><pre class="crayon-plain-tag"># using the Rails caching class outside of rails
require 'active_support'

cache = ActiveSupport::Cache::FileStore.new &quot;/tmp/poro_cache&quot;
if cache.read('user').nil?
  cache.write('user', 'bob')
  puts &quot;wrote to cache, run me again&quot;
else
  puts &quot;Reading from filestore cache: #{cache.read('user')}&quot;
end</pre><p></p>
<p>If we run this one time, we get this:<br />
<code>ruby rails_cache_poro.rb<br />
wrote to cache, run me again</code></p>
<p>And running it again:<br />
<code>ruby rails_cache_poro.rb<br />
Reading from filestore cache: bob</code></p>
<p>Reset it with <code>rm -rf /tmp/poro_cache</code></p>
<p>Ok, so that&#8217;s ActiveSupport caching outside of Rails.  Wiring Rails up to do this inside a controller, lib class, helper or other ruby object is trivial once you have followed the <a href="http://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-memorystore">caching guide</a>.  You won&#8217;t instantiate ActiveSupport::Cache anymore directly but you&#8217;ll do it indirectly through the config block for your environment.</p>
<p>And then all the statements will look like this:</p><pre class="crayon-plain-tag">&gt;&gt; Rails.cache.write 'foo', 'bar'
=&gt; true</pre><p></p>
<p>But it works the same.  Really easy.  Of course, the next subject which is more complicated is <a href="http://jeffdickey.info/cache-correctly-stop-invalidating">when to invalidate your cache</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/09/23/caching-an-object-in-rails-is-eas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making Rails Development on Windows Not Suck</title>
		<link>http://squarism.com/2012/09/22/rails-development-on-windows-not-suck/</link>
		<comments>http://squarism.com/2012/09/22/rails-development-on-windows-not-suck/#comments</comments>
		<pubDate>Sat, 22 Sep 2012 23:04:57 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1615</guid>
		<description><![CDATA[One of these strategies will probably work for you. I have a Windows 7 box. Normally I dev on Mac (not perfect but sucks less). I had built a Linux VM (ubuntu) but wanted to share my projects from the VM to windows to use sublime text 2. Editing through the shell is ok but [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2012/09/ruby_on_windows-300x300.png" alt="" title="ruby_on_windows" width="300" height="300" class="alignright size-medium wp-image-1717" /><br />
One of these strategies will probably work for you.</p>
<p>I have a Windows 7 box.  Normally I dev on Mac (not perfect but sucks less).  I had built a Linux VM (ubuntu) but wanted to share my projects from the VM to windows to use sublime text 2.  Editing through the shell is ok but I wanted a full text editor instead of vi (which I haven&#8217;t gotten my speed up on).  So I normally watch my files for changes with Guard as previously blogged.</p>
<p>So I share out my ~/projects directory through VMWare to Windows.  Great!  Now I can have all the unix tools in the VM and a GUI editor without doing the console screen painting through VMWare. The problem is, libevent doesn&#8217;t trigger through the shared folder feature of VMware.  I have no idea why.</p>
<p>So I pivoted.  I tried the windows rails installer.  Even though it tries to pre-patch mingw32 right before the native gem install, it didn&#8217;t work well with native libs like nokogiri (just to name one).</p>
<p>So I tried cygwin and apt-cyg (apt-get for Cygwin, nice, sorta).  It didn&#8217;t work well with compiling ruby even after googling flags and installing gcc.  Was getting &#8220;could not find C compiler&#8221;.</p>
<p>So this journey continues.  I installed the latest version of VMware workstation on Windows, going to try shared directory again with new vmware version and ubuntu 12.04.  Maybe there will be some magic in the upgrades.  I doubt it but I will try.</p>
<p>I could also try my <a href="http://squarism.com/2012/09/15/a-different-repl-workflow-in-ruby/">inline rspec</a> trick even though that still uses libevent for triggering the test execution.</p>
<p>If you have no idea what I&#8217;m talking about but am curious, leave a comment and I&#8217;ll make a video or follow-up.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/09/22/rails-development-on-windows-not-suck/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Splitting a sentence in Ruby and keeping the punctuation</title>
		<link>http://squarism.com/2012/09/21/splitting-a-sentence-in-ruby-and-keeping-the-punctuation/</link>
		<comments>http://squarism.com/2012/09/21/splitting-a-sentence-in-ruby-and-keeping-the-punctuation/#comments</comments>
		<pubDate>Sat, 22 Sep 2012 02:51:14 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1368</guid>
		<description><![CDATA[Update:Doh! You can just do text.split(/(\.)\s+/) to make the regex keep the delimiter with the parens group match. Then you have to join in groups and some other stuff. I keep the post below for posterity. :) When you split a string on a character, you get an array back without the split character. When [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2012/09/reversing_sentences.png" alt="" title="reversing_sentences" width="178" height="178" class="aligncenter size-full wp-image-1699" /></p>
<p><strong>Update:</strong>Doh!  You can just do text.split(/(\.)\s+/) to make the regex keep the delimiter with the parens group match.  Then you have to join in groups and some other stuff.  I keep the post below for posterity. :)</p>
<p>When you split a string on a character, you get an array back without the split character.  When splitting sentences, the period goes away with the split.  So we can employ some rather nasty behind regex tricks to remember the puntuation and still do the split.  Pretty great!</p>
<p>Here&#8217;s some code I stole from stackoverflow that splits sentences fairly well.  Pay no attention to the complexity of this unchained beast.</p><pre class="crayon-plain-tag"># oniguruma regex to split on multiple sentence
# delimeters but preserve delimeter character.

text = &quot;Hipsters are everywhere! Even in Home Depot? Flannel wrench set in ma face.&quot;

result = text.split(/((?&lt;=[a-z0-9)][.?!])|(?&lt;=[a-z0-9][.?!]&quot;))\s+(?=&quot;?[A-Z])/)

puts result</pre><p></p>
<p>When you run it:<br />
<code><br />
Hipsters are everywhere!<br />
Even in Home Depot?<br />
Flannel wrench set in ma face.<br />
[Finished in 0.3s]<br />
</code></p>
<p>That&#8217;s great but it does a fat lot of good when trying to modify it to reverse sentences.  Not to mention, regexes falling down on edge cases (the above doesn&#8217;t work for shouting sentences like this one?!!</p>
<p>Ok, whatever.  That&#8217;s regex stuff.  Let&#8217;s try applying what we&#8217;ve learned from our <a href="http://squarism.com/2012/09/15/a-different-repl-workflow-in-ruby/">last post</a> and create an inline rspec test to do what we want.</p>
<p>First, we&#8217;ll test the simplest case with <em>See spot run.</em>  And then we&#8217;ll add multiple sentences in.</p>
<p></p><pre class="crayon-plain-tag"># oniguruma regex engine testing to split on multiple sentence
# delimeters but preserve delimeter character.

require 'pry'

class Reverse

  def sentences(text)
    split_everything = text.strip.split(/(\.|\?|\!)/)
    sentences = split_everything.each_slice(2).to_a.map {|pair| pair.join}

    sentences.collect do |sentence|
      punc = sentence[-1]
      sentence.chop!
      sentence.downcase!
      words = sentence.split(&quot; &quot;)
      reversed = words.reverse.join(&quot; &quot;) &lt;&lt; punc
      reversed.capitalize!
    end.join(&quot;  &quot;)
  end

end

describe Reverse do
  it &quot;reverses words in one sentence&quot; do
    text = &quot;See spot run.&quot;
    reversed = subject.sentences(text)
    reversed.should == &quot;Run spot see.&quot;
  end

  it &quot;reverses all sentences in some text&quot; do
    text = &quot;See spot run.  Run spot run.  Your soul is mortal spot.&quot;
    reversed = subject.sentences(text)
    reversed.should == &quot;Run spot see.  Run spot run.  Spot mortal is soul your.&quot;
  end

end</pre><p></p>
<p>Works pretty well.  We can keep adding edge case tests to handle weird punctuation situations or the dreaded &#8220;Mr. Smith goes to college!&#8221; sentence.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/09/21/splitting-a-sentence-in-ruby-and-keeping-the-punctuation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Different REPL Workflow in Ruby</title>
		<link>http://squarism.com/2012/09/15/a-different-repl-workflow-in-ruby/</link>
		<comments>http://squarism.com/2012/09/15/a-different-repl-workflow-in-ruby/#comments</comments>
		<pubDate>Sun, 16 Sep 2012 01:42:45 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1671</guid>
		<description><![CDATA[Normally what I do is open an editor and start coding. In Textmate, I&#8217;ll hit Cmd+R to just run it as a big procedural file for something simple. If it gets too complicated, I&#8217;ll put it in a class. If something is confusing, I&#8217;ll break out to irb. The problem with this workflow is that [...]]]></description>
				<content:encoded><![CDATA[<p>Normally what I do is open an editor and start coding.  In Textmate, I&#8217;ll hit Cmd+R to just run it as a big procedural file for something simple.  If it gets too complicated, I&#8217;ll put it in a class.  If something is confusing, I&#8217;ll break out to irb.  The problem with this workflow is that you have to copy and paste a lot of code back and forth to get to &#8220;the breakpoint&#8221;.</p>
<p>In rails, I&#8217;d just put a binding.pry and magically, I&#8217;m at the breakpoint to play around at that point in time.  No copying and pasting.  Nice.</p>
<p>After watching a bunch of destroyallsoftware screencasts though, I like his one setup from episode #7 where he inlines rspec tests.  Combine this with watchr and I might have a new favorite.</p>
<p>Let&#8217;s say I had the following hello world example.</p><pre class="crayon-plain-tag">class Hello
  attr_reader :message

  def initialize
    @message = &quot;Hello Variable!&quot;
  end

  def say_hello
    puts @message
  end

end</pre><p></p>
<p>When I run it in Textmate with Cmd+R, it doesn&#8217;t do anything.  Because there&#8217;s no &#8220;main&#8221;.  So then I have to add:</p>
<p></p><pre class="crayon-plain-tag">Hello.new.say_hello</pre><p></p>
<p>Great!  But wait a minute, when I use it in another class, it&#8217;s going to print &#8220;Hello Variable!&#8221; out.  So then I take it out?  Then to test it again, I put it back in?  This workflow although easy kind of sucks.</p>
<p>So let&#8217;s just inline some rspec.  But before we even do that, we need rspec and watchr.  We are going to use watchr to watch our files for changes.  It&#8217;s best to install rev (Linux) or ruby-fsevent (Mac) for filesystem event firing.</p>
<p><code>gem install watchr rspec ruby-fsevent</code></p>
<p>Next, run this in a terminal and put it so where you can see it run while in your editor:<br />
<code>watchr -e 'watch("hello.*\.rb") {|m| system("clear &#038;&#038; rspec -c #{m};") }'</code></p>
<p>Like this:<br />
<img src="http://squarism.com/wp-content/uploads/2012/09/rspec_repl-580x308.png" alt="" title="rspec_repl" width="580" height="308" class="aligncenter size-large wp-image-1672" /></p>
<p>When you save the file (even without changes), it should say:<br />
<code>No examples found.</p>
<p>Finished in 0.00007 seconds<br />
0 examples, 0 failures</code></p>
<p>Ok, now let&#8217;s inline some rspec tests to test our class.</p><pre class="crayon-plain-tag">class Hello
  attr_reader :message

  def initialize
    @message = &quot;Hello Variable!&quot;
  end

  def say_hello
    puts @message
  end

end

describe Hello do
  it &quot;has a say_hello method&quot; do
    subject.respond_to?(:say_hello)
  end
end</pre><p></p>
<p>Now we will get this nice rspec to the right <font color="green"><strong>in color</strong></font> immediately upon saving:<img src="http://squarism.com/wp-content/uploads/2012/09/rspec_pry_pass-580x308.png" alt="" title="rspec_pry_pass" width="580" height="308" class="aligncenter size-large wp-image-1679" /></p>
<p>So how about irb?  What if we want to learn/play in the code?  Well now that we have a class and a shell instead of Textmate, we can use pry again.</p>
<p></p><pre class="crayon-plain-tag">require 'pry'

class Hello
  attr_reader :message

  def initialize
    @message = &quot;Hello Variable!&quot;
  end

  def say_hello
    puts @message
  end

end

describe Hello do
  it &quot;has a say_hello method&quot; do
    binding.pry
    subject.respond_to?(:say_hello)
  end
end</pre><p></p>
<p>And now when we save, we&#8217;ll be popped into a Pry shell.<br />
<img src="http://squarism.com/wp-content/uploads/2012/09/pry_rspec.png" alt="" title="pry_rspec" width="600" height="400" class="aligncenter size-full wp-image-1682" /></p>
<p>So give this a shot and see if you like this as an alt workflow.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/09/15/a-different-repl-workflow-in-ruby/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Computer is Not a Calculator</title>
		<link>http://squarism.com/2012/09/13/a-computer-is-not-a-calculator/</link>
		<comments>http://squarism.com/2012/09/13/a-computer-is-not-a-calculator/#comments</comments>
		<pubDate>Fri, 14 Sep 2012 02:23:06 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1535</guid>
		<description><![CDATA[A common metaphor for a computer is that it&#8217;s a giant calculator. It&#8217;s easy to imagine a larger and larger machine. Pictures of a small desk calculator evolving into a slightly larger version, morphing into something the size of a breadbox with more buttons, changing into something the size of a refrigerator and finally we [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2012/09/not_a_calculator.png" alt="" title="not_a_calculator" width="256" height="256" class="alignright size-full wp-image-1659" /><br />
A common metaphor for a computer is that it&#8217;s a giant calculator.  It&#8217;s easy to imagine a larger and larger machine.  Pictures of a small desk calculator evolving into a slightly larger version, morphing into something the size of a breadbox with more buttons, changing into something the size of a refrigerator and finally we nod our heads and say &#8220;it&#8217;s a calculator but bigger&#8221;.  That&#8217;s why it&#8217;s so powerful!  It&#8217;s a huge calculator!  But it&#8217;s not.  </p>
<p>It&#8217;s a state machine.</p>
<p>What huge numbers would a calculator be unable to calculate anyway?  You know that scientific notation<br />
<code>1.274921411340194917490141234 × 10^27</code>?  I&#8217;ve seen that in a calculator.  Doesn&#8217;t that let the calculator handle a number of extremely large size?  Is that why it can&#8217;t play games?  Does a calculator not calculate enough?  Or, is a state machine that is too slow to render real-time graphics.</p>
<p>It&#8217;s not that a calculator can&#8217;t store big numbers.  It&#8217;s that a computer is so quick on changing its internal state that it can trick us with simulations and graphics.</p>
<p>A CPU is not a brain either but that&#8217;s a different post.</p>
<p>I encourage you to checkout <a href="https://github.com/pluginaweek/state_machine">the State Machine gem</a> to play around with this concept.  It has direct relevance to game development and other areas.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/09/13/a-computer-is-not-a-calculator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Replace Guard with Autotest if using Minitest</title>
		<link>http://squarism.com/2012/09/12/autotest-and-minitest/</link>
		<comments>http://squarism.com/2012/09/12/autotest-and-minitest/#comments</comments>
		<pubDate>Thu, 13 Sep 2012 04:20:52 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1631</guid>
		<description><![CDATA[I love Guard. I&#8217;ve posted about it and used it a lot. But it&#8217;s got some problems right now with all the downstream gems and addons that I like. Of course, a more elegant solution is to not pre-fork and use Gary Bernhardt&#8217;s (and others&#8217;) advice of extracting domain objects from rails and running tests [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2012/09/spork.png" alt="" title="spork" width="110" height="230" class="alignright size-full wp-image-1654" /><br />
I love Guard.  I&#8217;ve posted about it and used it a lot.  But it&#8217;s got some problems right now with all the downstream gems and addons that I like.</p>
<p>Of course, a more elegant solution is to not pre-fork and use Gary Bernhardt&#8217;s (and others&#8217;) advice of extracting domain objects from rails and <a href="https://www.destroyallsoftware.com/screencasts/catalog/extracting-domain-objects">running tests</a> over that.  This is fine within plain old ruby objects but sometimes you need to load rake or factory_girl and that requires rails.  So let&#8217;s assume you can&#8217;t isolate your tests into lib/ or extras/ and you need fast tests while loading your entire Rails environment.  That&#8217;s where Guard and Autotest come in.</p>
<p>The newest Guard installs Listen which doesn&#8217;t work.  So I had to back down a version of listen.  Added gem &#8216;listen&#8217;, &#8217;0.4.7&#8242; to my Gemfile to get rid of polling warning.  0.5.0 is latest but it has a problem right now (bug opened 2 days ago as of today, grr).  All that is unrelated to the real problem.  </p>
<p>Spork-minitest <a href="https://github.com/semaperepelitsa/spork-minitest/issues/2">doesn&#8217;t work with guard</a>.  The issue is that spork-minitest doesn&#8217;t support any options like -r or -e that the guard is passing.</p>
<p>So let&#8217;s switch to autotest.  But first, let&#8217;s look at my current configuration and I&#8217;ll show you what I had to change.  This is what my Guardfile looked like with Guard on a Rails project:</p>
<p></p><pre class="crayon-plain-tag">guard 'spork' do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch(%r{^config/environments/.+\\.rb$})
  watch(%r{^config/initializers/.+\\.rb$})
  watch('Gemfile')
  watch('Gemfile.lock')
  watch('test/test_helper.rb') { :minitest }
  watch(%r{features/support/}) { :cucumber }
end
 
guard 'minitest' do
  # with Minitest::Unit
  watch(%r|^test/(.*)\/(.*)_test\.rb|)
  watch(%r|^lib/(.*)\.rb|)     { |m| &quot;test/unit/lib/#{m[1]}_test.rb&quot; }
  watch(%r|^test/test_helper\.rb|)    { &quot;test&quot; }
 
  # Rails 3.2
  watch(%r|^app/controllers/(.*)\.rb|) { |m| &quot;test/functional/#{m[1]}_test.rb&quot; }
  watch(%r|^app/helpers/(.*)\.rb|)     { |m| &quot;test/unit/helpers/#{m[1]}_test.rb&quot; }
  watch(%r|^app/models/(.*)\.rb|)      { |m| &quot;test/unit/models/#{m[1]}_test.rb&quot; }    
end</pre><p></p>
<p>Delete that whole Guardfile and let&#8217;s switch to autotest with spork and minitest.</p>
<p>This is what my Gemfile looked like with Guard:</p><pre class="crayon-plain-tag">group :develop do
  # unrelated gems here.
  gem 'minitest'
  gem 'spork'
  gem 'rb-inotify' if RUBY_PLATFORM.downcase.include?(&quot;linux&quot;)
  gem 'rb-fsevent', &quot;~&gt; 0.9.0&quot; if RUBY_PLATFORM.downcase.include?(&quot;darwin&quot;)
  gem 'guard'
  gem 'guard-spork'
  gem 'guard-minitest'
  gem 'spork-testunit'
end</pre><p></p>
<p>This is what my Gemfile looks like when switched to Autotest:</p><pre class="crayon-plain-tag">group :test, :develop do
  # unrelated gems here.

  # spork and autotest allow you to run tests when you save a file.
  # run `spork` in one terminal from the project root.
  # run `bundle exec autotest -cf` in one terminal from the project root.
  # Then edit test files or app/* or lib/* and watch tests run automatically on save.
  gem 'spork'   # Spork caches rails so tests run fast.
  gem 'autotest-standalone' # The file '.autotest' makes sure the tests are run via test server (spork).
  gem 'autotest-rails-pure' # -pure gives us autotest without ZenTest gem.
  gem 'autotest-growl'      # growl notifications, complains a little bit if growl isn't installed
  gem 'autotest-fsevent'    # react to filesystem events, save your CPU
  gem 'spork-minitest'
end</pre><p></p>
<p>It works great!  As I said in the Gemfile comments:</p>
<ul>
<li>Start `spork` in one terminal</li>
<li>Run `bundle exec autotest -cf` in another terminal</li>
</ul>
<p><code><br />
-c is for avoiding re-running rake test on red/green<br />
-f is for fast start to avoid running rake test on startup<br />
</code></p>
<p>Save a file like products_controller_test.rb and watch it run.  Save the app/controllers/products_controller.rb and watch products_controller_test.rb run.</p>
<p>The only problem is that it reacts a little bit slow because of a 1 second default sleep in Autotest.  So this is my entire .autotest file which includes a hack to reduce that 1 second to 0 seconds.  No impact to CPU and it reacts as fast as Guard did.</p>
<p></p><pre class="crayon-plain-tag">require 'autotest/fsevent'

class Autotest
  # run tests over drb server (spork)
  def make_test_cmd files_to_test
    if files_to_test.empty?
      &quot;&quot; # no tests to run
    else
      &quot;testdrb #{files_to_test.keys.join(' ')}&quot;
    end
  end
end

# tighten up the time before the test is run
ObjectSpace.each_object(Autotest).first.sleep = 0</pre><p></p>
<p>I plan on doing a pull request to address this problem.  So watch for that.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/09/12/autotest-and-minitest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Documentation is Horse Crap</title>
		<link>http://squarism.com/2012/09/11/documentation-is-horse-crap/</link>
		<comments>http://squarism.com/2012/09/11/documentation-is-horse-crap/#comments</comments>
		<pubDate>Wed, 12 Sep 2012 03:52:39 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1642</guid>
		<description><![CDATA[&#8220;We need to write down how it works, what we are doing and all the little tricks so that if you get hit by a bus someone else knows what&#8217;s going on.&#8221; &#8220;So how do you keep the documentation in sync with what&#8217;s really going on?&#8221; &#8220;You have to do that.&#8221; Documentation gets you a [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2012/09/doc_horse_crap-300x199.png" alt="" title="doc_horse_crap" width="300" height="199" class="alignright size-medium wp-image-1648" /></p>
<blockquote><p>&#8220;We need to write down how it works, what we are doing and all the little tricks so that if you get hit by a bus someone else knows what&#8217;s going on.&#8221;<br />
&#8220;So how do you keep the documentation in sync with what&#8217;s really going on?&#8221;<br />
&#8220;You have to do that.&#8221;</p></blockquote>
<p>Documentation gets you a document.  It doesn&#8217;t get you guarantees.</p>
<p>I&#8217;ve had this conversation a few times and it doesn&#8217;t matter who or where it is.  It&#8217;s the same story.  When someone is surprised, someone asks &#8220;why wasn&#8217;t this documented!?&#8221;.  Documentation is good, I agree.  But only in the general sense.  If you watch DHH&#8217;s keynote talk on <a href="http://www.youtube.com/watch?v=VOFTop3AMZ8">progress</a>, overstating the general case is very similar.  He says progress is good in the general sense.  But when you start asking people to change, they get mad.  They&#8217;ll say things like &#8220;why can&#8217;t we have it the way it used to work?&#8221;.</p>
<p>The same goes for documentation.  Everyone agrees that it&#8217;s good. But if you ask for time to gather the content for it, we can&#8217;t do that right now.  If you ask for a tool that might help you automate &#8220;documentation&#8221; then we can&#8217;t fit that in a schedule.  How many times have people not documented or written an email because they don&#8217;t want a paper trail to bite them in the ass? What about closed door, stealth meetings and initiatives? Do industry secrets get written down? Does McDonalds&#8217;s secret sauce get documented?</p>
<p>If the documentation has content that someone doesn&#8217;t like, maybe we&#8217;ll skip that or edit it. How about this:</p>
<blockquote><p><em>Section 5.41.29</em><br />
Our system is finicky and buggy because no one wants to take risks and we couldn&#8217;t try to solve this problem in the middle of development. So you have to restart the service every 5 minutes. Here&#8217;s how you do that.</p></blockquote>
<p>An important point! We could write down &#8220;restart this every 5 minutes&#8221; but wouldn&#8217;t someone want to know why we are restarting things all the time? What was the reasoning for this kludge? What&#8217;s the history?</p>
<p>Obviously the tone above is bad. Let&#8217;s talk about the tone. When you ask someone to write something down so that it&#8217;s saved for future humanity, what are you really expecting? What style or model did you originally imagine when the desire for a doc hit you: </p>
<ul>
<li>Do you expect a training manual?</li>
<li>A thesis explaining the theory and problem space the solution lives in?</li>
<li>Do you expect an encyclopedia full of facts and truths?</li>
<li>An insider&#8217;s fast-track guide to understanding what&#8217;s going on?</li>
<li>A slick sheet full of capabilities and bragging rights?</li>
<li>A wikipedia full of references, links and related material?</li>
<li>A history-filled story with very few facts but reads cover to cover easily?</li>
</ul>
<p>Each of these things have a style and an audience.  Did you think about these things before you just said documentation? Did you communicate that to anyone?  Does anyone understand your vision?  Are we writing our docs to an audience full of laymans or experts?  Do we even know?  Most projects I&#8217;ve been on write to a really insulting level.  XYZ for Dummies.  That&#8217;s not good!  Dummy books are not good!</p>
<p>You probably already have documentation out there.  What does a wiki not solve for you? What does the README say?  What is on your FAQ page? Do you have a test suite? Do you have an API?  Do you have a demo or help file? Do you have a development and project methodology and does it have paper output like status reports?  Does anyone really care about the content of status reports or are they just checking &#8220;are people working?&#8221; in which case that&#8217;s solving HR and people resources instead of showing what&#8217;s going into &#8220;the product&#8221;.</p>
<p>Every place I&#8217;ve been at values documentation.  And when people leave the project or the company, it&#8217;s still a huge deal.  All the documentation in the world doesn&#8217;t save the team from the shock of hearing that a valued team member is moving on to greener pastures never to talk to us again.  Schedules slip, morale takes a nose-dive and someone is left holding the poop bag.  If you are lucky, there&#8217;s a back-fill plan. For years, people will talk about employees who used to &#8220;be here&#8221;.  And no one really runs to the documentation to find out how, what and why they worked.  You tell the employee who&#8217;s leaving, &#8220;for the next two weeks, train someone and write down what you know&#8221;.  And even then, that plan doesn&#8217;t work 100%.  Loss still happens.</p>
<p>So if documentation is so valuable then why doesn&#8217;t it work?  Are worker-bees revolting against doing it?  Is our documentation even done? How do we know when our docs are done?  Are they close to done now?</p>
<p>Just stop with the doc thing. Write your normal stuff.  Your README or user manual.  Develop a business methodology, keep it simple. Use jargon words and defined concepts to keep it short.  Have hands-on people document USEFUL THINGS IN USEFUL WAYS THAT THEY WILL LIKE AND USE.  If you ask them to open MS Word and start documenting, you have failed.  Documentation is not a document.</p>
<p>Here are some things that hands-on people might like:</p>
<ul>
<li>A .plan file, dev log or equivalent to remind them what they were doing on Friday when they come in on Monday. &#8211; They will like this because Mondays will hurt less.</li>
<li>A Kanban board for status. They will like this because status reports won&#8217;t be the only way to communicate what we are doing.</li>
<li><a href="http://cukes.info/">Executable User Stores</a> as answering the question &#8220;how it&#8217;s supposed to work&#8221;. They will like this because you won&#8217;t have to write a seperate test plan and test steps. Also, it lets devs take risks because they KNOW when everything is working. Also, it&#8217;s executable requirements because it&#8217;s your stories. I&#8217;m talking about Cucumber/Gherkin. </li>
<li>A project blog. They&#8217;ll like this because it&#8217;s outward facing beyond status reports.</li>
</ul>
<p>Ultimately, documentation is not the problem.  Even when suggesting things above, it&#8217;s the stodgy management that is forcing everyone to write docs.  If the customer wants a waterfall doc product then they are going to get one.  Maybe there&#8217;s no choice. But is there? Do they like huge and out of date deliverables?  Does anyone really know for sure?</p>
<p>Documentation is not the problem, it&#8217;s the whole project, it&#8217;s the whole culture.  They don&#8217;t want to change their deliverables but they have never done anything different.  They need to know that the project is going to succeed when in reality waterfall is designed to keep people from taking responsibility for when it doesn&#8217;t work.  &#8220;We passed that gate! We can&#8217;t be blamed! You signed off on it!&#8221;  And that&#8217;s really the point.  Documentation is the tell-tale sign of infinite bureaucracy.  Work for a car dealership and write down a doc on how to ride a horse.  They&#8217;ll think &#8220;I didn&#8217;t know we had horses!&#8221; but no one will fire you for documenting a bunch of horse crap.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/09/11/documentation-is-horse-crap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Let&#8217;s Play with Capistrano</title>
		<link>http://squarism.com/2012/09/10/lets-play-with-capistrano/</link>
		<comments>http://squarism.com/2012/09/10/lets-play-with-capistrano/#comments</comments>
		<pubDate>Tue, 11 Sep 2012 04:05:44 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1623</guid>
		<description><![CDATA[In which I try to learn capistrano for the first time. Pushed a simple Rails 3 app to a mac dev box running rbenv, zsh, nginx and passenger. It&#8217;s LONG and edited only for length. So strap in and observe a completely blind learning session. Final deploy.rb file here: gist.github.com/3410415 Let&#8217;s Play with Capistrano from [...]]]></description>
				<content:encoded><![CDATA[<p>In which I try to learn capistrano for the first time. Pushed a simple Rails 3 app to a mac dev box running rbenv, zsh, nginx and passenger. It&#8217;s <strong>LONG</strong> and edited only for length. So strap in and observe a completely blind learning session.</p>
<p>Final deploy.rb file here:<br />
<a href="http://gist.github.com/3410415">gist.github.com/3410415</a></p>
<p><iframe src="http://player.vimeo.com/video/48042041" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p><a href="http://vimeo.com/48042041">Let&#8217;s Play with Capistrano</a> from <a href="http://vimeo.com/user1702792">Chris Dillon</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/09/10/lets-play-with-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rbenv vs RVM</title>
		<link>http://squarism.com/2012/09/09/rbenv-vs-rvm/</link>
		<comments>http://squarism.com/2012/09/09/rbenv-vs-rvm/#comments</comments>
		<pubDate>Sun, 09 Sep 2012 23:38:43 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1611</guid>
		<description><![CDATA[I used to use RVM with gemsets and loved it. Wayne&#8217;s work is amazing and way beyond any shell-fu I know. I was super impressed as I started and used it for at least a year on my main dev box. Then I upgraded ruby a few times and that was ok. But then I [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2012/09/bundler_px.png" alt="" title="bundler_px" width="243" height="164" class="alignright size-full wp-image-1636" /><br />
I used to use RVM with gemsets and loved it.  Wayne&#8217;s work is amazing and way beyond any shell-fu I know.  I was super impressed as I started and used it for at least a year on my main dev box.</p>
<p>Then I upgraded ruby a few times and that was ok.  But then I sudo&#8217;d to root and got:<br />
<code># ~/.rvm does not exist (or something)</code></p>
<p>Here are some things I didn&#8217;t like:</p>
<ul>
<li>Gemsets are great except when you are managing different global gemsets on different boxes.</li>
<li>Maybe you work on a project that maybe doesn&#8217;t use RVM and you wonder if they really want an .rvm-gemset file in their project root.</li>
<li>I loved upgrading my default ruby using RVM until it failed and I had to recreate all gemsets and reinstall all gems.</li>
<li>Gemset exporting I never really got.</li>
</ul>
<h2>Rbenv is better?</h2>
<p>So I&#8217;ve switched to no gemsets and rbenv.  I just use rbenv and ruby-build.  Rbenv seems to runs a lot lighter and doesn&#8217;t complain on sudo.</p>
<h2>RVM is better?</h2>
<p>RVM beats rbenv in gemsets though.  Rbenv gemsets don&#8217;t have global so you have to create a pre-install rails just to `rails new`.  It&#8217;s a chicken before the egg thing.  There&#8217;s no global gemset so rails doesn&#8217;t exist and you don&#8217;t have a directory to create the .rbenv-gemsets file in.  So you have to create a tmp rails project with like the Rails 3.0 generator.  And then you have to upgrade that project or something.</p>
<p><strong>update:</strong>This might not be true.  If you delete your .rbenv-gemsets file out of your home directory and make sure that each project has it&#8217;s own gems installed then `gem` will be global and you can install/remove gems as normal.  So your global gemset is when `rbenv gemset active` returns nothing.</p>
<p>Upgrading ruby versions with rbenv does not import your gems.  So you have to wait until you need them and install them with `bundle` or pre-cd into each of your projects to install them?</p>
<p>So that&#8217;s why I went with a third option.</p>
<h2>No Gemsets at all!</h2>
<p>Bundler works but with no gemsets, you end up with a lot of dupe versions that don&#8217;t hurt anything.  You can bundle exec foo and the correct version of foo will be loaded.  However, I do miss having clean gemsets.  This list grows and grows without end.<br />
<code><br />
> gem search rails<br />
*** LOCAL GEMS ***<br />
rails (3.2.8, 3.2.2, 3.0.16)<br />
</code></p>
<p>Having dupe versions is kind of annoying after a while, especially if you wanted to create a mobile rails dev env on a usb key.  You don&#8217;t know what your dependencies are.  Or do you?  You can go until a project with Bundler and do:<br />
<code><br />
> bundle list<br />
Gems included by the bundle:<br />
  * abstract (1.0.0)<br />
  * actionmailer (3.0.16)<br />
  * actionpack (3.0.16)<br />
  * activemodel (3.0.16)<br />
  ...<br />
</code></p>
<p>Then I guess I could copy all the gems somewhere.  But it&#8217;s not automatic.  With gemsets, each project was in a directory and I could just grab all the *.gem files.</p>
<h2>tl;dr</h2>
<p>So there&#8217;s pros and cons to each method.  I have no problems without gemsets but I don&#8217;t have cleanliness.  I just don&#8217;t know what the downside to having a messy system is.  Honestly, a patch to `gem` where gem list would just colorize the list from bundle list would be awesome.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/09/09/rbenv-vs-rvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino Mini and Raspberry Pi GPIO wonderment</title>
		<link>http://squarism.com/2012/09/06/arduino-mini-and-raspberry-pi-gpio-wonderment/</link>
		<comments>http://squarism.com/2012/09/06/arduino-mini-and-raspberry-pi-gpio-wonderment/#comments</comments>
		<pubDate>Fri, 07 Sep 2012 04:42:12 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Arduino]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1617</guid>
		<description><![CDATA[A group of us were wondering about this new Arduino Mini I got. How is it powered? This turned into a question about the Raspberry Pi and how it compares. The Pi runs Linux but you have the GPIO pins. Are they /dev devices? Is it something else? How do you write serial to /dev/pin/1? [...]]]></description>
				<content:encoded><![CDATA[<p><img src="http://squarism.com/wp-content/uploads/2012/09/arduino_raspberry_pi-300x168.png" alt="" title="arduino_raspberry_pi" width="300" height="168" class="alignright size-medium wp-image-1619" /><br />
A group of us were wondering about this new Arduino Mini I got.  How is it powered?  This turned into a question about the Raspberry Pi and how it compares.  The Pi runs Linux but you have the GPIO pins.  Are they /dev devices?  Is it something else?  How do you write serial to /dev/pin/1?  We left the questions on the table.</p>
<h2>The Arduino Mini Powered on a Breadboard</h2>
<p>I was curious so last night I got the Arduino Mini up and running.  It was pretty tricky.  I tried powering it over 9v.  I was careful to read up on sparkfun forums and the like to see what it could handle.  I found that it would boot (or at least the power light would come on) on as little as 3.3v off the 9v battery.  Then I measured what was coming out of the 9v and it was only 7v (old battery).  I read that it could handle up to 9v on the 9v input pin.  So I had that working but how do you load code on it?</p>
<p>So I had ordered this FTDI cable from sparkfun.  It&#8217;s a 5v version as my Mini is a 5v too.  An alternative is a breakout board with a regular USB host cable.  So I messed around with the 9v powering my breadboard with a barrel jack and a little rocker switch and left the 5v off USB disconnected.  So I was just trying to use USB for TX/RX information to program the Arduino (as in load code, not burn the bootloader).</p>
<p>First, I had to load FTDI drivers for mac.  On Windows, this would create a COM port.  On mac, it just magically works and there&#8217;s no control panel or sys prefs applet.  That&#8217;s a bit weird that there&#8217;s no interface to change settings but luckily it all worked.  I had read about Windows users having to set &#8220;rts on close&#8221; option to true on older versions of the Arduino IDE but in the end, that was not my problem.</p>
<p>I tried to upload the Examples->Blink sketch.  I was getting a few errors.  Like:<br />
<code>"programmer not responding"</code> and<br />
<code>"avrdude: stk500_getsync(): not in sync: resp=0x00"</code></p>
<p>I had seen this before when I choose the wrong board type but after flipping through all possible combinations, this wasn&#8217;t it.  I eventually ran into a post buried deep in the web that mentioned hitting the reset button on the Arduino right before you load the sketch.  So I did that (with some tricky timing involved) and the not in sync error no longer happened.  So this was great because this was the first success.</p>
<p>Success is so much more useful for progress than failure just because you can start messing with stuff.  And up to this point I was wondering all kinds of things like: is my board bad?  is my cable bad?  are my drivers stupid?  So I was happy that things were working but I didn&#8217;t like having to hit reset manually.  I never had to do this on the regular Arduino.</p>
<p>So I looked at someone&#8217;s wiring and realized that the USB FTDI cable I was using has an RTS on it that can go to a reset pin.  So I plugged that in.  But then it would complain that it couldn&#8217;t find the programmer on the board.  Then I realized that they didn&#8217;t just hook it up straight, they had a 100uf capacitor on it.  So it acts like a little trigger.  If it&#8217;s on constantly the Arduino is constantly resetting so the code upload sort of times out.  When the cap hooked up, I don&#8217;t have to reset it manually just to update code on it.</p>
<p>So then I uploaded the blink sketch again and it &#8220;just works&#8221;.  There&#8217;s no built-in LED on pin 13 so I just hooked one up (with a resistor, don&#8217;t forget an led doesn&#8217;t resist) and it blinked on pin 13.  Pretty cool.  Also it seems to boot really quick.  Like almost instantly.  When you power it up, it just starts blinking.</p>
<p>Also I was powering it off a 9v which worked fine.  Apparently the mini has a regulator.  I double regulated it to 3.3v and it still booted although the light is dim.  I think it is pretty tolerant but I also read that it&#8217;s not as &#8220;tough&#8221; as the regular one.  The regular Arduino is pretty forgiving to electrical errors (within reason&#8230; don&#8217;t plug it into the wall).</p>
<h2>How Do the GPIO Pins on a Raspberry PI work?</h2>
<p>I found a Python and a Ruby project for the Raspberry PI GPIO pins.</p>
<p>Here&#8217;s the python version.  If you had an LED on pin 12, this code (I assume) would turn it on (high).</p><pre class="crayon-plain-tag">import RPi.GPIO as GPIO
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output channel
GPIO.setup(12, GPIO.OUT)
# set RPi board pin 12 high
GPIO.output(12, GPIO.HIGH)</pre><p></p>
<p>The <a href="https://github.com/klappy/gpio">ruby version</a> called gpio by klappy on github is pretty similar. I looked at the ruby code and it looks like <a href="https://github.com/klappy/gpio/blob/master/lib/gpio/devices/raspberry_pi.rb">an abstraction</a> around the raw devices.</p><pre class="crayon-plain-tag">BASE_PATH = '/sys/class/gpio/'</pre><p></p>
<p>So that&#8217;s pretty neat.  You get something really similar to the Arduino but could a higher level language and have networking and video built in.  That for me was what I was wondering.  I don&#8217;t exactly understand how serial over raw devices and pins work but I do understand system and virtual device nodes in /sys.</p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/09/06/arduino-mini-and-raspberry-pi-gpio-wonderment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coffeescript Fat Arrow</title>
		<link>http://squarism.com/2012/08/10/coffeescript-fat-arrow/</link>
		<comments>http://squarism.com/2012/08/10/coffeescript-fat-arrow/#comments</comments>
		<pubDate>Sat, 11 Aug 2012 03:05:48 +0000</pubDate>
		<dc:creator>squarism</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://squarism.com/?p=1601</guid>
		<description><![CDATA[I found myself in a situation where coffeescript was complaining that Object has no method foo when it clearly did. What is going on? Why is it so hard to call a class method from within a class? [crayon-519b52e851532/] What you see in this example is: HON... imma deploying mah airbag! aaaa! timers.js:103 if (!process.listeners('uncaughtException').length) [...]]]></description>
				<content:encoded><![CDATA[<p>I found myself in a situation where coffeescript was complaining that Object has no method foo when it clearly did.  What is going on?  Why is it so hard to call a class method from within a class?</p>
<p></p><pre class="crayon-plain-tag">class Car
  get_in_accident: -&gt;
    @honk_horn(&quot;panic&quot;)
    @airbag()
  
  airbag: -&gt;
    console.log(&quot;imma deploying mah airbag!&quot;)
  
  # just showing here that arguments don't change anything
  honk_horn: (level) -&gt;
    if (level == &quot;pissed&quot;)
      console.log(&quot;HONK HONK&quot;)
    else if (level == &quot;panic&quot;)
      @yell(&quot;aaaa!&quot;, 1000)
      console.log(&quot;HON...&quot;)
  
  # the real issue is callbacks that lose the original scope
  yell: (message, wait_time) -&gt;
    setTimeout -&gt;
      console.log(message)
      @honk_horn(&quot;pissed&quot;)
      console.log(&quot;You jerk!&quot;)
    , wait_time

car = new Car
car.get_in_accident()</pre><p></p>
<p>What you see in this example is:<br />
<code><br />
HON...<br />
imma deploying mah airbag!<br />
aaaa!</p>
<p>timers.js:103<br />
            if (!process.listeners('uncaughtException').length) throw e;<br />
                                                                      ^<br />
TypeError: Object # has no method 'honk_horn'<br />
    at Object._onTimeout (.:29:14)<br />
    at Timer.list.ontimeout (timers.js:101:19)<br />
</code></p>
<p>@honk_horn is supposed to refer to the instance variable when yell is called.  It doesn&#8217;t know about it&#8217;s self?  Well, there&#8217;s a good chapter about this (Chapter 6 of <a href="http://www.amazon.com/gp/product/032182010X/ref=as_li_qf_sp_asin_tl?ie=UTF8&#038;camp=1789&#038;creative=9325&#038;creativeASIN=032182010X&#038;linkCode=as2&#038;tag=squarism-20" title="Programming in Coffeescript">this book</a>) on Binding and the <a href="http://coffeescript.org/#fat_arrow">Fat Arrow</a> in coffeescript.  It&#8217;s a simple fix to a confusing problem.  The method that is called later (the callback method) needs to have a fat arrow => which generates a __bind function in javascript when the coffescript is compiled.  This saves you a lot of time and effort.  All you have to remember is to use the fat arrow when a callback is going to be called out of scope.</p>
<p>So just change the setTimeout line to have a => instead of ->:</p><pre class="crayon-plain-tag">yell: (message, wait_time) -&gt;
    setTimeout =&gt;</pre><p></p>
<p>Now it works right.  Also notice that the &#8220;aaaa!&#8221; yell is happening before the &#8220;HON&#8230;&#8221; log statement in both examples.<br />
<code><br />
HON...<br />
imma deploying mah airbag!<br />
aaaa!<br />
HONK HONK<br />
You jerk!<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://squarism.com/2012/08/10/coffeescript-fat-arrow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.320 seconds -->
<!-- Cached page served by WP-Cache -->
