<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Bjhess's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 01:09:08 GMT</pubDate>
    <description>DZone Snippets: Bjhess's Code Snippets</description>
    <item>
      <title>Rails-like number_to_currency currency formatting</title>
      <link>http://snippets.dzone.com/posts/show/4646</link>
      <description>This is pretty much a port of the Ruby on Rails number_to_currency method, right down to the hashed options.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;number_to_currency: function (number, options) {&lt;br /&gt;  try {&lt;br /&gt;    var options   = options || {};&lt;br /&gt;    var precision = options["precision"] || 2;&lt;br /&gt;    var unit      = options["unit"] || "$";&lt;br /&gt;    var separator = precision &gt; 0 ? options["separator"] || "." : "";&lt;br /&gt;    var delimiter = options["delimiter"] || ",";&lt;br /&gt;  &lt;br /&gt;    var parts = parseFloat(number).toFixed(precision).split('.');&lt;br /&gt;    return unit + reports.number_with_delimiter(parts[0], delimiter) + separator + parts[1].toString();&lt;br /&gt;  } catch(e) {&lt;br /&gt;    return number&lt;br /&gt;  }&lt;br /&gt;},&lt;br /&gt;&lt;br /&gt;number_with_delimiter: function (number, delimiter, separator) {&lt;br /&gt;  try {&lt;br /&gt;    var delimiter = delimiter || ",";&lt;br /&gt;    var separator = separator || ".";&lt;br /&gt;    &lt;br /&gt;    var parts = number.toString().split('.');&lt;br /&gt;    parts[0] = parts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + delimiter);&lt;br /&gt;    return parts.join(separator);&lt;br /&gt;  } catch(e) {&lt;br /&gt;    return number&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 12 Oct 2007 20:15:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4646</guid>
      <author>bjhess (Barry Hess)</author>
    </item>
    <item>
      <title>Migration to change all MySQL table engines to InnoDB</title>
      <link>http://snippets.dzone.com/posts/show/4601</link>
      <description>I have a database with an eclectic mix of table types/engines - almost random between MyISAM and InnoDB.  I wanted to get transactional, so I wrote this migration to bring everything in line.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class ChangeTableTypes &lt; ActiveRecord::Migration&lt;br /&gt;  &lt;br /&gt;  def self.up&lt;br /&gt;    ActiveRecord::Migration::say 'Setting all tables to InnoDB engine (excluding schema_info table)...'&lt;br /&gt;    result = ActiveRecord::Migration::execute 'show tables'&lt;br /&gt;    while table = result.fetch_row&lt;br /&gt;      execute("ALTER TABLE #{table.to_s} TYPE = InnoDB") unless table.to_s == 'schema_info'&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def self.down&lt;br /&gt;    raise ActiveRecord::IrreversibleMigration&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blog.bjhess.com"&gt;Barry Hess&lt;/a&gt;</description>
      <pubDate>Mon, 01 Oct 2007 18:52:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4601</guid>
      <author>bjhess (Barry Hess)</author>
    </item>
    <item>
      <title>Rails auto select text field</title>
      <link>http://snippets.dzone.com/posts/show/4561</link>
      <description>A simple helper to create those snazzy on-click-auto-select text fields you see on all the video-sharing sites.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def auto_select_text_field_tag(name, value = nil, options = {})&lt;br /&gt;  text_field_tag(name,&lt;br /&gt;                 value,&lt;br /&gt;                 { :onclick =&gt; "$(&#8217;#{name}&#8217;).select()",&lt;br /&gt;                   :readonly =&gt; "true" }.merge(options))&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A _little_ more info &lt;a href="http://bjhess.com/bjhessblog/2007/09/12/rails-auto-select-text-field-tag/"&gt;on my blog&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;~Barry Hess</description>
      <pubDate>Thu, 20 Sep 2007 20:10:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4561</guid>
      <author>bjhess (Barry Hess)</author>
    </item>
  </channel>
</rss>
