<?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>databasically // Kansas City Small Business IT &#38;&#38; Ruby on Rails Programming &#187; Programming</title>
	<atom:link href="http://databasically.com/category/blog/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://databasically.com</link>
	<description>Kansas City Small Business IT</description>
	<lastBuildDate>Fri, 03 Feb 2012 05:24:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Configuration for mailjet email delivery with Ruby on Rails</title>
		<link>http://databasically.com/2011/06/07/configuration-for-mailjet-email-delivery-with-ruby-on-rails/</link>
		<comments>http://databasically.com/2011/06/07/configuration-for-mailjet-email-delivery-with-ruby-on-rails/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 10:00:03 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=583</guid>
		<description><![CDATA[Setting up mailjet.com to deliver your mail via Ruby on Rails? Here&#8217;s how, because their Getting Started is nothing but placeholder headers right now. Create an account Go to https://www.mailjet.com and create an account. Note: the word &#8220;Faculatative&#8221; means &#8220;optional&#8221; on the signup form. Add your sending address Add a sending address (Accounts > Sender [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up mailjet.com to deliver your mail via Ruby on Rails?  Here&#8217;s how, because their <a href="https://www.mailjet.com/docs/getting_started">Getting Started</a> is nothing but placeholder headers right now.</p>
<div class="thumbnail"><a href="https://skitch.com/wesg/fdkc8/mailjet-real-time-emailing-mailjet.com"><img src="https://img.skitch.com/20110607-bmbfb3f4pjrcawsya4yab9dcic.preview.jpg" alt="Mailjet : Real-time Emailing - mailjet.com" /></a></div>
</p>
<p><span id="more-583"></span><br />
<h2>Create an account</h2>
<p>Go to <a href="https://www.mailjet.com">https://www.mailjet.com</a> and create an account.</p>
<p>Note: the word &#8220;Faculatative&#8221; means &#8220;optional&#8221; on the signup form.</p>
<h2>Add your sending address</h2>
<ul>
<li>Add a sending address (Accounts > <a href="https://www.mailjet.com/account/sender">Sender Addresses</a>)</li>
<li>Update your Rails ActionMailer configuration
<ul>
<li>Find the settings you need at: <a href="https://www.mailjet.com/account/setup">https://www.mailjet.com/account/setup</a></p>
<pre>
    SMTP server:
    in.mailjet.com

    Username (API Key):
    12345678901234567890

    Password (Secret Key):
    99999999999999999999999999999999

    Port:
    25 or 587 (some providers block port 25)

    Use TLS:
    yes
  </pre>
</li>
<li>Set these settings in config/application.rb (or config/environments/production.rb):
<pre name="code" class="ruby">

    config.action_mailer.raise_delivery_errors = false
    config.action_mailer.perform_deliveries = true

    config.action_mailer.smtp_settings = {
      :address => "in.mailjet.com",
      :enable_starttls_auto => true,
      :port => 587,
      :authentication => 'plain',
      :user_name => "12345678901234567890",
      :password => "99999999999999999999999999999999"
    }
</pre>
</li>
</ul>
</li>
</ul>
<h2>Setup domain authentication (SPF and/or DomainKeys/DKIM)</h2>
<h3>SPF</h3>
<p>
  <img src="https://img.skitch.com/20110607-nmn91j4ukdp8yna3pup3qu1sb8.png" alt="My Account - mailjet.com" /><br />
  Click <b>Domain DNS and SMTP setup</b>.<br />
  Then, under <b>Domain Authentication</b>, click your domain.
</p>
<p>Setting up SPF requires adding a DNS entry. Mailjet will look at your existing one and give you the one to replace it with.<br />
  It&#8217;ll look something like: <br /><code>domainname.com.	IN TXT "v=spf1 include:spf.mailjet.com mx ~all"</code><br />
  In my DNS manager, I created a TXT record, gave it a name of &#8220;domainname.com.&#8221; and set the value to the <br /><code>'v=spf1 include:spf.mailjet.com mx ~all'</code> portion (without the quotes).  The full example they give you is for the DNS zone syntax, which you may or may not have.</p>
<p>  If you need help configuring this, <a href="/contact-us">we would be happy to help you</a>.</p>
<h3>DKIM</h3>
<p>
  This is similar, a TXT record that has a key that identifies your server so mail can be sent.  Same deal.
</p>
<h2>Test</h2>
<p>Deploy your changes and kick off something that sends a mailer.  We have a Notifier model that has a <code>test_email()</code> method that I just called from the console to push a test through.  I just went to the reports and saw it there.</p>
<p>All in all, the service seems a little rough around the edges, mostly due to it being a French company that could use a little work on the translations and some serious love on the support documentations.  Hope this helps you get started with Mailjet configuration!</p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/06/07/configuration-for-mailjet-email-delivery-with-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>git: merge a single commit</title>
		<link>http://databasically.com/2011/06/03/git-merge-a-single-commit/</link>
		<comments>http://databasically.com/2011/06/03/git-merge-a-single-commit/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 10:01:43 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Version Control]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=563</guid>
		<description><![CDATA[Sometimes, you have one commit you want to get into production, but it&#8217;s located after other changes that you&#8217;re not ready to merge in yet. How can you get that single git commit into a different branch? First, you have to know the SHA of the commit you want: git checkout branch-with-commit-on-it git log Highlight [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, you have one commit you want to get into production, but it&#8217;s located after other changes that you&#8217;re not ready to merge in yet.  How can you get that single git commit into a different branch?</p>
<p>First, you have to know the SHA of the commit you want:</p>
<pre class="ruby">  git checkout branch-with-commit-on-it
  git log</pre>
<p>Highlight and copy the SHA of the commit you want to grab.</p>
<pre class="ruby">  git checkout master

  # -n =&gt; don't commit, just merge changes so we can review and commit ourself
  git cherry-pick -n [The commit’s SHA-1 Hash]

  # review
  git diff –cached

  # commit if all is well
  git commit -a -m “merge SHA1 ..."</pre>
<p>If you&#8217;re feeling confident, you can skip the -n and merge the single commit in directly and save a minute.</p>
<p>Note, this isn&#8217;t a merge, so it&#8217;s possible you could have some conflicts down the road when you merge the original commit into this branch.  You&#8217;re creating a brand new commit object.</p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/06/03/git-merge-a-single-commit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby&#8217;s ParseExcel and the Extra Date</title>
		<link>http://databasically.com/2011/04/22/rubys-parseexcel-and-the-extra-date/</link>
		<comments>http://databasically.com/2011/04/22/rubys-parseexcel-and-the-extra-date/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 15:55:15 +0000</pubDate>
		<dc:creator>Samuel Mullen</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=533</guid>
		<description><![CDATA[We have a feature in one of our application which allows the user to upload data from an Excel spreadsheet. One of the columns read in is a date field. Because we&#8217;re dealing with end users, sometimes those dates come in as &#8220;Date&#8221; objects, sometimes they come in as &#8220;String&#8221;s, and sometimes they come in [...]]]></description>
			<content:encoded><![CDATA[<p>We have a feature in one of our application which allows the user to upload data from an Excel spreadsheet. One of the columns read in is a date field. Because we&#8217;re dealing with end users, sometimes those dates come in as &#8220;Date&#8221; objects, sometimes they come in as &#8220;String&#8221;s, and sometimes they come in as a number.</p>
<p>When Excel saves a date as a numeric, it is that value&#8217;s number of days since January 0, 1900 (No, we can&#8217;t say Dec 31, 1899). So a spreadsheet would store &#8220;May 1, 2011&#8243; as 40664 if it was formatted as a number.</p>
<p>That&#8217;s great, peachy even, but if you&#8217;ll notice, 40664 days from Dec 31, 1899 is May 2, 2011, not May 1st. What happened? Compatibility.</p>
<p>When Microsoft introduced Excel way back when, Lotus123 dominated the spreadsheet marking. In order for Microsoft to be able to compete, it had to be compatible with Lotus123. It had to be compatible with all the formulas, all the features, and all the bugs. One of those bugs had to do with an erroneous leap day in 1900. This means that when you read in numbers from a spreadsheet in order to translate them to a date, you have to account for that extra leap day.</p>
<p>The solution? Just subtract one from the numeric. It might look something like this (from the Rails console):</p>
<pre name='code' class="ruby">Date.civil(1899, 12, 31) + 40664.days - 1.day</pre>
<p>We could have did that anyway and just chalked it up to something weird, but now, at least, we know why it&#8217;s weird.</p>
<p><strong>Notes:</strong></p>
<ul>
<li>OpenOffice is also fully compatible with that bug.</li>
<li><a href="http://www.cpearson.com/excel/datetime.htm">Dates and Times in Excel</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/04/22/rubys-parseexcel-and-the-extra-date/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gateway timeout with nginx/passenger standalone</title>
		<link>http://databasically.com/2011/04/18/gateway-timeout-with-nginxpassenger-standalone/</link>
		<comments>http://databasically.com/2011/04/18/gateway-timeout-with-nginxpassenger-standalone/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 15:18:52 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=528</guid>
		<description><![CDATA[I needed to run Rails apps with both ruby 1.8.7 and 1.9.2 on the same server. Passenger Standalone to the rescue! Setting up my 1.9.2 app as a standalone server and setting it up as proxy to it worked great. Until we had to upload and process some files. Turns out, the gateway server would [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to run Rails apps with both ruby 1.8.7 and 1.9.2 on the same server.</p>
<p><a href="http://www.modrails.com/documentation/Users%20guide%20Standalone.html">Passenger Standalone</a> to the rescue!  Setting up my 1.9.2 app as a standalone server and setting it up as proxy to it worked great.</p>
<p><strong>Until</strong> we had to upload and process some files.  Turns out, the gateway server would timeout, even though the process was still processing on the app server.</p>
<p>The proxing nginx server would reply with &#8220;Gateway Timeout 504&#8243;.</p>
<p>The fix from the nginx documentation: <a href="http://wiki.nginx.org/HttpProxyModule#proxy_read_timeout">proxy_read_timeout</a></p>
<p>My proxy config after this:</p>
<pre name="code" class="ruby">
  location / {
    proxy_pass http://127.0.0.1:3010;
    proxy_read_timeout 240s;
  }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/04/18/gateway-timeout-with-nginxpassenger-standalone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git: Commit Early, Commit Often</title>
		<link>http://databasically.com/2011/03/14/git-commit-early-commit-often/</link>
		<comments>http://databasically.com/2011/03/14/git-commit-early-commit-often/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 16:28:36 +0000</pubDate>
		<dc:creator>Jaime Bellmyer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Version Control]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=486</guid>
		<description><![CDATA[Don&#8217;t Be Afraid of Commitment The phrase &#8220;save early, save often&#8221; was a mantra of early computer science. It&#8217;s good advice, but it&#8217;s only half the story. If you&#8217;ve ever sat down for a fast and furious coding session only to realize hours later that you removed something important, you know the frustration of not [...]]]></description>
			<content:encoded><![CDATA[<h2>Don&#8217;t Be Afraid of Commitment</h2>
<p>The phrase &#8220;save early, save often&#8221; was a mantra of early computer science. It&#8217;s good advice, but it&#8217;s only half the story. If you&#8217;ve ever sat down for a fast and furious coding session only to realize hours later that you removed something important, you know the frustration of not being able to get it back. It can mean hours lost.</p>
<p>Getting in the habit of regular commits has a number of benefits. First, you can go back to any previously committed version if your coding goes off-track. You can reference earlier parts of your work even if you don&#8217;t need to revert to them. Best of all, it an actually have a positive impact on your code itself.</p>
<h2>Better Code through Committing</h2>
<p>Just as Test-Driven Development influences us to write a larger number of shorter/simpler methods, frequent committing pushes us to think of atomic changes. Atomic in this context means the smallest possible self-sufficient change. Consider this snippet from <em>git log</em>:</p>
<pre name='code' class="ruby">
commit b0e77532b5a8cf236d95f1b3324aabc194568c60
Author: Wally
Date:   Tue Feb 29 23:58:05 2011 -0600

added comments to blog posts
</pre>
<p>This is an example of a commit done at the end of a feature. Lots of code has probably gone into this, and if you wanted to see any of the steps along the way, you&#8217;re out of luck. It&#8217;s also not very easy to see what was changed in the app.</p>
<h2>An Example of Frequent Commits</h2>
<p>Now look at this version:</p>
<pre name='code' class="ruby">
commit e8bba8ad1a4b5c1353c328b505bfa2a9f4816d07
Author: Alice
Date:   Tue Feb 29 14:58:05 2011 -0600

added edit/delete links to each comment if user has permissions

commit 8bba8ad1a4b5c1353c328b505bfa2a9f4816d07e
Author: Alice
Date:   Tue Feb 29 13:58:05 2011 -0600

allowed admins to edit/update/delete any comments

commit bba8ad1a4b5c1353c328b505bfa2a9f4816d07e8
Author: Alice
Date:   Tue Feb 29 11:58:05 2011 -0600

restricted edit/update/delete actions to user's own comments

commit ba8ad1a4b5c1353c328b505bfa2a9f4816d07e8b
Author: Alice
Date:   Tue Feb 29 11:36:20 2011 -0600

created controller/views

commit a8ad1a4b5c1353c328b505bfa2a9f4816d07e8bb
Author: Alice
Date:   Tue Feb 29 10:03:31 2011 -0600

made comments nestable in the model

commit 8ad1a4b5c1353c328b505bfa2a9f4816d07e8bba
Author: Alice
Date:   Tue Feb 29 9:39:24 2011 -0600

defined activerecord associations among users, posts, and comments

commit ad1a4b5c1353c328b505bfa2a9f4816d07e8bba8
Author: Alice
Date:   Tue Feb 29 08:38:01 2011 -0600

added base comment model and migrations
</pre>
<p>You can clearly see the evolution of this feature, and it makes sense. Not only can you step back (if user permissions were implemented incorrectly, for instance) but Alice was &#8220;forced&#8221; to think about each logical step of her development process, instead of jumping in head first. It&#8217;s engineering 101 &#8211; break a problem in its atomic elements, and attack each of those.</p>
<p>Incidentally, this can also help explain to coworkers, bosses, and clients why a seemingly simple task took longer than expected. As you squirm and attempt to justify what you know is an elegant solution, you might not remember all the steps that got you there.</p>
<p>Git remembers.</p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/03/14/git-commit-early-commit-often/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thebes, profiling spork, backup rubygem</title>
		<link>http://databasically.com/2011/03/14/thebes-profiling-spork-backup-rubygem/</link>
		<comments>http://databasically.com/2011/03/14/thebes-profiling-spork-backup-rubygem/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 15:41:34 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=506</guid>
		<description><![CDATA[Thebes, a new minimal sphinx gem for Rails Link Thebes is a wrapper around Sphinx, the search engine we use on most of our projects. Thebes differs from other solutions by staying as far away from your Rails code as possible. Instead of hiding the Sphinx configuration file behind a domain-specific language, this library assumes [...]]]></description>
			<content:encoded><![CDATA[<h1 id="thebes_a_new_minimal_sphinx_gem_for_rails">Thebes, a new minimal sphinx gem for Rails</h1>
<p><a href="www.getharvest.com/blog/2011/03/thebes-a-new-minimal-sphinx-gem-for-rails/" title="Thebes">Link</a></p>
<blockquote>
<p>Thebes is a wrapper around Sphinx, the search engine we use on most of our projects. Thebes differs from other solutions by staying as far away from your Rails code as possible. Instead of hiding the Sphinx configuration file behind a domain-specific language, this library assumes you will write Sphinx config files by hand. In Thebes, you edit an ERB template of your Sphinx configuration and populate it with variables at generation time. For developers needing the most flexible or fastest solution possible, this is a great way to work with Sphinx.</p>
</blockquote>
<p>We&#8217;ve been doing some interesting things with search and reporting that are going to require faster lookups than directly querying the database. From the article &#8220;the [Thinking Sphinx project] has a lot of complexity and ties to ActiveRecord 2.x code. Consequently, the porting of TS to Rails 3 isn’t turning out to be the smooth road we hoped for.  So, for Rails 3 projects, this looks like a good way to go if you&#8217;re willing to get your hands dirty and build some sphinx files yourself.</p>
<h1 id="profiling_spork_for_faster_start_up_time">Profiling Spork for faster start-up time</h1>
<p><a href="http://opinionated-programmer.com/2011/02/profiling-spork-for-faster-start-up-time/" title="Profiling Spork">Link</a></p>
<p>Spork allows you to preload Rails environment files into a process, then it forks that process and runs your tests against the new process.  In essence, your tests will start faster because they&#8217;re not loading everything.  You can specify files you want to be reloaded each time (for instance, model files).</p>
<p>The code:</p>
<p><script src="https://gist.github.com/869238.js"> </script></p>
<p>This prints out everything being loaded up, so you can move files that don&#8217;t change into the preload block for that extra bit of snappiness.</p>
<h1 id="backup_a_rubygem_for_database_and_file_backups">Backup, a rubygem for database and file backups</h1>
<p><a href="https://github.com/meskyanichi/backup" title="Backup rubygem">Link</a></p>
<blockquote>
<p>Backup is a RubyGem (for UNIX-like operating systems: Linux, Mac OSX) that allows you to configure and perform backups in a simple manner using an elegant Ruby DSL. It supports various databases (MySQL, PostgreSQL, MongoDB and Redis), it supports various storage locations (Amazon S3, Rackspace Cloud Files, Dropbox, any remote server through FTP, SFTP, SCP and RSync), it can archive files and folders, it can cycle backups, it can do incremental backups, it can compress backups, it can encrypt backups (OpenSSL or GPG), it can notify you about successful and/or failed backups (Mail or Twitter). It is very extensible and easy to add new functionality to. It&#8217;s easy to use.</p>
</blockquote>
<p>Check out the <a href="https://github.com/meskyanichi/backup/blob/develop/README.md" title="README">README</a> for all the details, but this allows you to backup your app via command line, pushing to S3 or rsync&#8217;ing to another server.  You can schedule it with the fantastic <a href="https://github.com/javan/whenever" title="Whenever gem">Whenever gem</a> too.</p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/03/14/thebes-profiling-spork-backup-rubygem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A :limit of Rails&#8217; Migrations</title>
		<link>http://databasically.com/2011/03/01/a-limit-of-rails-migrations/</link>
		<comments>http://databasically.com/2011/03/01/a-limit-of-rails-migrations/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 16:35:51 +0000</pubDate>
		<dc:creator>Samuel Mullen</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=472</guid>
		<description><![CDATA[Migrations in Ruby on Rails use the &#8220;:limit&#8221; symbol to set the maximum length of the underlying field&#8217;s data type. Take for example, the following example migration: create_table :things do &#124;t&#124; t.string :name, :limit =&#62; 32 t.string :description t.timestamps end By default, Rails will create :description as data type &#8220;varchar(255)&#8221; and :name as &#8220;varchar(32)&#8221; in [...]]]></description>
			<content:encoded><![CDATA[<p>Migrations in Ruby on Rails use the &#8220;:limit&#8221; symbol to set the maximum length of the underlying field&#8217;s data type. Take for example, the following example migration:</p>
<pre name='code' class="ruby">create_table :things do |t|
  t.string :name, :limit =&gt; 32
  t.string :description
  t.timestamps
end
</pre>
<p>By default, Rails will create :description as data type &#8220;varchar(255)&#8221; and :name as &#8220;varchar(32)&#8221; in a MySQL database. But did you know you can set :limit to be greater than 255?</p>
<p>For whatever reason, many of us have gained the impression that 255 is the longest :string can be, but that just isn&#8217;t the case. If I wanted the :description field in the example above to be greater than 255, I could just define it as follows:</p>
<pre name='code' class="ruby">t.string :description, :limit =&gt; 1024
</pre>
<p>In fact, strings (i.e. varchars) in MySQL can hold up to 65,535 bytes of data.</p>
<p>The opinionated nature of  Ruby on Rails is a great asset in most instances, but we have to be careful not to let its opinions :limit us.</p>
<p><strong>Note:</strong> I&#8217;m pretty sure Rails sets the default limit of strings to be 255 for two reasons: 1) cross database compatability, and 2) MySQL&#8217;s InnoDB (utf-8) engine can&#8217;t index varchar fields exceeding 255 characters.</p>
<h3>Further Reading</h3>
<ul>
<li><a href="http://www.railsinside.com/misc/455-the-perils-of-opinionated-software-like-rails.html">The Perils Of Opinionated Software (like Rails)</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/data-types.html">MySQL Data Types</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-restrictions.html">Restrictions on InnoDB Tables</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/char.html">The CHAR and VARCHAR Data Types</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/03/01/a-limit-of-rails-migrations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git Branching After the Fact</title>
		<link>http://databasically.com/2011/02/14/git-branching-after-the-fact/</link>
		<comments>http://databasically.com/2011/02/14/git-branching-after-the-fact/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 21:26:37 +0000</pubDate>
		<dc:creator>Samuel Mullen</dc:creator>
				<category><![CDATA[Version Control]]></category>
		<category><![CDATA[branching]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[workflows]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=446</guid>
		<description><![CDATA[We have a pretty simple Git work flow here at Databasically: Just work in master. There are a couple reasons for this: we&#8217;re not a large team, and we have a very rapid (i.e. daily) release cycle. I had been used to creating branches for every new feature, so when I found out we primarily [...]]]></description>
			<content:encoded><![CDATA[<p>We have a pretty simple <a href="http://git-scm.com/">Git</a> work flow here at <a href="http://databasically.com">Databasically</a>: Just work in master. There are a couple reasons for this: we&#8217;re not a large team, and we have a very rapid (i.e. daily) release cycle. I had been used to creating branches for every new feature, so when I found out we primarily work on the &#8220;master&#8221; branch, I was a bit shocked.</p>
<p>I know what you&#8217;re thinking, &#8220;But what if you go down a path and realize you need to branch in order to put in a &#8216;hotfix&#8217;, or you find out the story is more involved than initially  thought?&#8221;: you just create a branch after the fact. Here&#8217;s how to do it in just a few easy steps:</p>
<h2>Step 1: Know where you are and where you want to go</h2>
<p>The first thing you need to know is where you are and where you want to go.</p>
<p><a href="http://databasically.com/wp-content/uploads/2011/02/git_head1.png"><img class="alignnone size-full wp-image-450" title="git_head" src="http://databasically.com/wp-content/uploads/2011/02/git_head1.png" alt="" width="589" height="109" /></a></p>
<p>In the case (completely contrived example) above, I need to add a fix to what is in production (SHA: fa87cd9). So I want to roll everything back and start working from that hash point.</p>
<h2>Step 2: Create a new branch</h2>
<p>Now that we know where we want to go, we need to first create a new branch. We create a branch in order to force Git to remember our current line of work. In some ways, you can think of Git branches as inodes in Unix/Linux: as long as a file descriptor [branch] is pointing to an inode, it can&#8217;t be fully deleted [reset]. To do this, we&#8217;re just going to issue the &#8220;git branch &lt;branch name&gt;&#8221; command.</p>
<p>I should note that before you do this, make sure you&#8217;re clean. &#8220;Add&#8221; and &#8220;commit&#8221;, or &#8220;stash&#8221;, what you&#8217;re currently working on.</p>
<p><a href="http://databasically.com/wp-content/uploads/2011/02/gitbranch1.png"><img class="alignnone size-full wp-image-451" title="gitbranch" src="http://databasically.com/wp-content/uploads/2011/02/gitbranch1.png" alt="" width="629" height="168" /></a></p>
<p>So here, I created the branch &#8220;hotfix&#8221; and you can see that HEAD, master, and hotfix are all pointing to the same SHA. You can make sure your branch exists, by issuing the &#8220;git branch&#8221; command. Now, we can make our changes in master and push to production.</p>
<h2>Step 3: There is No &#8230; step 3</h2>
<p>This means you, Bruce.</p>
<h2>Step 4: Reset Master</h2>
<p>Now that we have a branch (created in step 2) we&#8217;ll reset HEAD to our chosen hash. We do that using git&#8217;s &#8220;reset&#8221; command:</p>
<blockquote>
<pre>git reset --hard fa87cd9</pre>
</blockquote>
<p>The log will look something like this:</p>
<p><a href="http://databasically.com/wp-content/uploads/2011/02/git_resetlog.png"><img class="alignnone size-full wp-image-452" title="git_resetlog" src="http://databasically.com/wp-content/uploads/2011/02/git_resetlog.png" alt="" width="526" height="94" /></a></p>
<p>After making our change and committing, our log looks like this:</p>
<p><a href="http://databasically.com/wp-content/uploads/2011/02/git_afterreset.png"><img class="alignnone size-full wp-image-453" title="git_afterreset" src="http://databasically.com/wp-content/uploads/2011/02/git_afterreset.png" alt="" width="550" height="103" /></a></p>
<p>Now we can push that into production and get back to what we were working on.</p>
<h2>Step 5: Rebase and Merge</h2>
<h3>Step 5a: Rebase Master</h3>
<p>In order to get back to what we were working on, we need to first rebase the changes we made in master into production. To do that, first checkout hotfix and run git rebase master</p>
<blockquote>
<pre>git checkout hotfix
git rebase master
</pre>
</blockquote>
<p>By rebasing master, we replay those changes made in master onto our &#8220;hotfix&#8221; branch. Our hotfix branch should now look like this:</p>
<p><a href="http://databasically.com/wp-content/uploads/2011/02/git_rebase.png"><img class="alignnone size-full wp-image-454" title="git_rebase" src="http://databasically.com/wp-content/uploads/2011/02/git_rebase.png" alt="" width="590" height="129" /></a></p>
<p>Notice where HEAD and hotfix are, and notice also where master is. It is now safe to merge everything back to master &#8211; and without leaving those unsightly branch paths.</p>
<h3>Step 5b: Merge</h3>
<p>First things first: check out master. Next: merge hotfix</p>
<blockquote>
<pre>git checkout master
git merge hotfix</pre>
</blockquote>
<p>You output will look something like this:</p>
<p><a href="http://databasically.com/wp-content/uploads/2011/02/git_hotfix.png"><img class="alignnone size-full wp-image-455" title="git_hotfix" src="http://databasically.com/wp-content/uploads/2011/02/git_hotfix.png" alt="" width="470" height="149" /></a></p>
<p>And your log will look like this:</p>
<p><a href="http://databasically.com/wp-content/uploads/2011/02/git_final.png"><img class="alignnone size-full wp-image-456" title="git_final" src="http://databasically.com/wp-content/uploads/2011/02/git_final.png" alt="" width="635" height="120" /></a></p>
<p>And everything is caught up. At this point you can delete the hotfix branch:</p>
<blockquote>
<pre>git branch -d hotfix
</pre>
</blockquote>
<h2>Conclusion</h2>
<p>This model works well for us, but I&#8217;m sure as we grow we&#8217;ll likely have to adopt more involved models such as the <a href="http://nvie.com/posts/a-successful-git-branching-model/">&#8220;A successful Git branching model</a>&#8221; used by <a href="http://nvie.com">nvie.com</a>. As we grow and modify our processes, we&#8217;ll be sure to let you know what we find to work and what we find which doesn&#8217;t.</p>
<h3>Further Reading</h3>
<ul>
<li><a href="http://git-scm.com/">The Git SCM</a></li>
<li><a href="http://nvie.com/posts/a-successful-git-branching-model/">A Successful Git Branching Model</a></li>
<li><a href="http://progit.org/book/">Pro Git Book</a></li>
<li><a href="http://gitimmersion.com/">Git Immersion</a></li>
</ul>
<h3>Notes:</h3>
<p>In this post, I have been calling &#8220;git log&#8221; with my alias &#8220;git lol&#8221; here is the details of the alias:</p>
<blockquote>
<pre>log --graph --decorate --date=local --pretty=format:'%h %cd (%an) %s%d'</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/02/14/git-branching-after-the-fact/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>default_scope: Use Cases, Caveats, and Work Arounds</title>
		<link>http://databasically.com/2011/02/07/default_scope-use-cases-caveats-and-work-arounds/</link>
		<comments>http://databasically.com/2011/02/07/default_scope-use-cases-caveats-and-work-arounds/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 14:57:09 +0000</pubDate>
		<dc:creator>Samuel Mullen</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[default_scope]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=432</guid>
		<description><![CDATA[In Ruby on Rails, named scopes are class methods used to restrict and organize the data searched for. In SQL terms, a named scope adds to the conditional (WHERE) and sorting (ORDER) sections of a query. See Railscast #108 for more information. In Rails 2.3.x, a new type of scoping was added to the API: [...]]]></description>
			<content:encoded><![CDATA[<p>In Ruby on Rails, named scopes are class methods used to restrict and organize the data searched for. In SQL terms, a named scope adds to the conditional (WHERE) and sorting (ORDER) sections of a query. See <a href="http://railscasts.com/episodes/108-named-scope">Railscast #108</a> for more information.</p>
<p>In Rails 2.3.x, a new type of scoping was added to the API: the default_scope. By using &#8220;default_scope&#8221;, one could restrict the data retrieved by every query without the need for extra method calls; it would just happen by &#8220;default&#8221;. If you wanted to have your data sorted in a particular manner, you could add &#8220;default_scope, :order =&gt; &#8216;created_at DESC&#8217;&#8221; to your model. From then on, all data retrieved would be ordered by &#8220;created_at&#8221; in a &#8220;descending&#8221; manner.</p>
<h2>Caveats</h2>
<p>In general, default_scope should be avoided if possible. Here are a few reasons:</p>
<ul>
<li>Out of site, out of mind: Because you don&#8217;t see that you are scoping your data as you query it, it&#8217;s easy to forget that it is in actuality being filtered. This can lead to a lot of head scratching until you remember the default_scope.</li>
<li>default_scope is inherited: All subclasses of the original model will inherit the default scoping. This may not be the behavior you desire.</li>
<li>Extra overhead: It&#8217;s one thing if you need your data sorted every single time, it&#8217;s quite another if you don&#8217;t. By using default_scope, you may be unnecessarily burdening your database.</li>
</ul>
<h2>Use Cases</h2>
<p>Like curry, default_scope is not inherently evil (obscure Phineas and Ferb reference), and there are instances where using it makes good sense. As an example, here at Databasically, we use default_scope to limit data retrieved by one application to a subset of what is available in a table. There will never be an instance where all the available data will be required, and so we limit it by default.</p>
<p>Here are the two use cases:</p>
<ul>
<li>When <strong>only</strong> a subset of the data is ever required</li>
<li>When the data must be returned in a specific order <strong>every</strong> time</li>
</ul>
<h2>Work Arounds</h2>
<p>I highlighted the words &#8220;only&#8221; and &#8220;every&#8221; in the section on use cases to make a point: default_scope should be used with caution. The fact is, however, that it&#8217;s not an &#8220;only&#8221; and &#8220;every&#8221; world, and as such, we need work arounds. In our case, it&#8217;s by using &#8220;with_exclusive_scope&#8221; and the undocumented &#8220;unscoped&#8221; (Rails 3.x only)</p>
<p>with_exclusive_scope example:</p>
<pre name='code' class="ruby">Article.with_exclusive_scope { find(:all) }
</pre>
<p>unscoped example (Rails 3.x only):</p>
<pre name='code' class="ruby">Article.unscoped
</pre>
<h2>Conclusion</h2>
<p>In general, we like to keep our code as DRY as possible, but in cases like default_scope, we prefer to be more explicit. We recognize the value of default_scope, but only use it when we absolutely need to, and even then we try to think of alternative methods.</p>
<p>How about you? We would really like to hear from you about your experiences with default scopings. What considerations do you take into account when choosing whether or not to use default_scope?</p>
<h2>Further Reading</h2>
<ul>
<li><a href="http://ryandaigle.com/articles/2008/11/18/what-s-new-in-edge-rails-default-scoping">What&#8217;s New in Edge Rails: Default Scoping</a></li>
<li><a href="http://stackoverflow.com/questions/2073419/overriding-default-scope-in-rails">Overriding default_scope in Rails</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/02/07/default_scope-use-cases-caveats-and-work-arounds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What time is it? Or, handling timezones in Rails.</title>
		<link>http://databasically.com/2010/10/22/what-time-is-it-or-handling-timezones-in-rails/</link>
		<comments>http://databasically.com/2010/10/22/what-time-is-it-or-handling-timezones-in-rails/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 03:46:59 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=406</guid>
		<description><![CDATA[As a followup to a stack overflow answer, I thought I would give some examples of working with time zones in rails. What does Rails timezone support do for me? Stores everything in UTC in the database Allows you to set an application default timezone and/or timezones for your users Automatically converts UTC in the [...]]]></description>
			<content:encoded><![CDATA[<p>As a followup to a <a href="http://stackoverflow.com/questions/3993619/time-select-with-12-hour-time-and-time-zone-in-ruby-on-rails">stack overflow answer</a>, I thought I would give some examples of working with time zones in rails.</p>
<h3>What does Rails timezone support do for me?</h3>
<ul>
<li>Stores everything in UTC in the database</li>
<li>Allows you to set an application default timezone and/or timezones for your users</li>
<li>Automatically converts UTC in the database to the correct zone and back</li>
</ul>
<h3>What zones are available?</h3>
<p>You can get a list of timezones with rake tasks:</p>
<pre name="code" class="ruby"># Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset.
rake time:zones:all

# Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time
rake time:zones:local

# Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset.
rake time:zones:us</pre>
<h3>Setting the default time zone</h3>
<p>In your environment.rb (Rails 2) or application.rb (Rails 3) file, you can set the default timezone:</p>
<pre name="code" class="ruby">config.time_zone = 'Central Time (US &amp; Canada)'</pre>
<p>What does this do?  By setting an application-wide timezone, any datetime will be stored in UTC in the database, but will be translated when we access it.</p>
<h3>Set a timezone for a user</h3>
<p>You can use <a href="http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/time_zone_select">time_zone_select</a> to get a list of timezones for a user to pick from. The third argument is a list of &#8220;priority&#8221; zones that will appear first.</p>
<pre name="code" class="ruby"> time_zone_select( "user", 'time_zone', TimeZone.us_zones, :default =&gt; "Pacific Time (US &amp; Canada)")</pre>
<p>Once the value is saved in the database, you&#8217;ll want to set it for each request, per user:</p>
<pre name="code" class="ruby">  before_filter :set_timezone

  def set_timezone
    # current_user.time_zone #=&gt; 'Central Time (US &amp; Canada)'
    Time.zone = current_user.time_zone || 'Central Time (US &amp; Canada)'
  end</pre>
<p>[<strong>UPDATE</strong>: You'll need a field 'time_zone' in your user table!]</p>
<p>[<strong>UPDATE</strong>: You probably want to stay DRY and refer to the configured value instead of specifying the timezone value in both places: <br />Time.zone = current_user.time_zone || MyAppName::Application.config.time_zone]</p>
<p>Let me know if you have questions or improvements and I&#8217;ll integrate them into the article.  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2010/10/22/what-time-is-it-or-handling-timezones-in-rails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

