ficate [fi•cate]

verb

To make, build, do.

Time to Donate: My Experience With Rails Girls

Dumplings

During a lunch discussion over some dumplings, Shufen mentioned that she was going to start a Rails Girls in Dallas. Several of us immediately volunteered. I have an affinity for teaching so this struck me as a great opportunity to do something I love. Additionally, an event like this might help a teenager pick a future. It could motivate a mother to reenter the work force after years of staying home with her children. It might help a small business launch or provide an existing one with a much needed boost. The decision to help was quick and easy.

Battery Life in the Land of Tmux

UPDATE: The code for this can be found on github.

From time to time I find myself immersed in my terminal. Bouncing around in Tmux(1.7) between vim, console and whatever else I’m doing. With my terminal in fullscreen mode I don’t notice the power draining from my battery.

OSX Battery Warning

This is a fixable problem.

Tooling Around: MySQL’s Client Config File

There are several good GUI options out there for working with MySQL. For the CLI fans or those forced to use a machine with no GUI it’s possible to have a good experience using the default MySQL(5.5.25a) client.

The mysql command accepts a variety of options. They can be passed in the initial call, set on the mysql terminal or permanently added in a ~/.my.cnf file. There are two in particular that are extremely useful.

Faster ActiveRecord Migrations Using change_table :bulk

A migration:

def up
  add_column :table, :useful_foreign_key, :integer
  add_index :table, :useful_foreign_key
  add_column :table, :summary, :string
end

Executed on a large table:

==  Table: migrating ===============================
-- add_column(:table, :useful_foreign_key, :integer)
  -> 2731.1005s
-- add_index(:table, :useful_foreign_key)
  -> 2704.8428s
-- add_column(:table, :summary, :string)
  -> 2819.9803s
==  Table: migrated (8255.9236s) ======================

According to my made up but based on having done this a bunch of times numbers that’s almost 2.5 hours! Production is going to have to go down for hours to run this. Co-workers will unsuspectingly migrate and you’ll be blamed for a massive loss of productivity.

Have you lost a second of data?

UPDATE: Based on some good Reddit discussions I’ve revised the “Only use ranges.” section to use a range with an exclusive end.

One of the gems I’m working on limits a range of data based on a datetime field. I use a SQLite database (version 3.7.7) in my automated testing, but ultimately it’s going to run on MySQL (version 5.5.19) and possibly others. The ease of SQLite makes this a fairly common setup. ActiveRecord (version 3.2.1) helps alleviate cross database issues but it doesn’t cover all cases. You see MySQL stores datetimes to a resolution of one second. Databases like SQLite and PostgreSQL store down to the microsecond (.999999). This leads to a problem.

Explaining Include and Extend

Featured in issue #77 of Ruby Weekly.

All Rubyists should be familiar with the common definitions for include and extend. You include a module to add instance methods to a class and extend to add class methods. Unfortunately, this common definition isn’t entirely accurate. It fails to explain why we use instance.extend(Module) to add methods to an instance. Shouldn’t it be instance.include(Module)? To figure this out we’re going to start by discussing where methods are stored.

tableficate 0.3.0 released

The 0.3.0 release adds support for table captions and for default text in tables without data. Styling options were greatly increased especially in relation to columns. You can now add attributes to the header, column (via the col tag) and individual cells. Cell attributes can be either strings or procs. If you pass a proc it will evaluate for each cell.

<% t.column(:total,
  cell_attrs: {style: ->(row){
    "color: #{row.total >= 0 ? 'black' : 'red'};"
  }}
) %>;

Filters automatically detect the input type based on the database column type and field name. For example, booleans will produce a check box filter and string columns with “email” in the name will produce an input field with the type set to “email”.

tableficate 0.2.0 released

The new version includes a complete rewrite of filters. I’ve made it a lot more like simple_form and I’m really happy with the result. You can get the latest code on github or take a look at the new wiki docs for more info.