On Hiring: How To Be a Non-Technical Co-Founder

If you are looking at hiring developers, check out my article on this subject.

The goal or the dream of working on your own startup is always full of excitement. And apart from some rare cases such as Dropbox, you probably need one or more co-founders to work with you on The Next Big Thing ™.

Problem is, how do you (as a non-technical co-founder) find us? Or more specifically, how do you talk us into working with you instead of some other billion-dollar ideas?

To answer this question, we need to first ask, is there a billion-dollar idea? The short answer is: NO.

Read more ...

On Hiring: How Not to Annoy Developers

If you are looking at finding technical co-founders, check out my article on this subject.

In recent years developers become hotter and hotter - especially the good ones - they are hard to find, and they have plenty of employment options to choose from.

Some companies (or individuals who are seeking freelancers) go the extra miles to impress developers with attractive salary/rate and perks, which is nice. But surprisingly, many companies and individuals seem to have a habit of keep doing things that will annoy developers.

Over the years, I have personally encountered many situations that annoyed me as a developer. If you are looking for developers, here are a few things that I think you should be aware of.

Read more ...

[Rails Tip] Model Attributes Not Updating? `reset_column_information` To the Rescue!

So you were wondering why some of your model attributes weren’t updating properly? Well, it is perhaps because the db schema has changed but the changed schema has not been passed onto ActiveRecord, as is often the case in DB migration.

Taken from the ActiveRecord documentation:

Resets all the cached information about columns, which will cause them to be reloaded on the next request.

The most common usage pattern for this method is probably in a migration, when just after creating a table you want to populate it with some default values, eg:

  class CreateJobLevels < ActiveRecord::Migration
    def self.up
      create_table :job_levels do |t|
        t.integer :id
        t.string :name

        t.timestamps
      end

      JobLevel.reset_column_information
      %w{assistant executive manager director}.each do |type|
        JobLevel.create(:name => type)
      end
    end

    def self.down
      drop_table :job_levels
    end
  end

[jQuery Tip] Traverse/Parse HTML String

When you are getting an HTML string from an external source (e.g. from an AJAX get result) and you want to rip out a certain part of the HTML source, you need to make sure that the ‘certain part’ is not at the top level of the HTML source.

For example, we have the following HTML string:

Hello

World

If we want to get the first paragraph element by using:

// data is the HTML source
$("p#first", data);

The above code won’t work, because the p tags are at the top level. Instead, we can simply wrap the HTML source with a div tag and that’ll do it. :)

[Rails Tip] DataMapper M:M Association Bug and Workaround

It was confirmed that DataMapper is incorrectly setting table names in SQL JOINs.

So for instance, the following code would generate an SQL error:

type.jobs.all(:"country.name".like => "%#{params[:location]}%")

There is a workaround, however the workaround requires manual looping of the dataset thus produces N+1 queries.

type.jobs.all.reject do |job|
  ! job.country.name.downcase.include?(params[:location].downcase)
end

But at least it works. ;)

[Rails Tip] Run Specs Faster!

If you are using rake spec to run the specs. Try using spec spec instead! It avoids doing some preliminary tasks and therefore is quicker to execute.

You can verify the difference using Unix’s time command, i.e. time spec spec and time rake spec.

Advanced Search Query on GitHub

Did you know, you can perform advanced search queries on GitHub?

For example:

ruby AND (textmate OR tmbundle)

The above query will search everything containing ruby, as well as either textmate or tmbundle.

Unfortunately at this stage the GitHub API does not support it. I’ve opened a ticket here.

[Rails Tip] Making i18n Forms, the Easy Way

Web applications normally have many forms. Building forms is always a mind-boggling task because it involves repetition and chaos.

A shortcut is to use a form builder / DSL, such as Formtastic.

As I am using Rails 3, and the Rails 3 port of Formtastic isn’t complete yet, I thought I’d just use the plain vanilla Rails built-in form helper.

First of all, I am using Haml instead of ERb. Already, I got the out-of-box clean looking Haml markup.

Some of you might not be aware of the fact that Rails’ built-in form helper already does i18n support.

If you have the following form:

  -form_for(@post) do |f|
    =f.label :title
    =f.text_field :title
    =f.label :body
    =f.text_area :body
    =f.submit

You can simply translate the labels as such in config/locales/en.yml.

  helpers:
    label:
      post:
        title: "Post Title"
        body: "Post Content"

Better yet, I am using r18n instead of i18n, so I can instead translate them in app/i18n/en.yml.

  helpers:
    label:
      post:
        title: Post Title
        body: Post Content

Alternatively, instead of placing the translation strings under helpers.label, you may place them directly under your models, i.e. activemodel.attribute.

If you’re using the Rails 2.3 stable branch from Github, you can also use the built-in i18n support. Although instead of helpers.label, you use views.labels, as seen in this commit.

[Rails Tip] “String”.constantize

So we want to dynamically instantiate an object (i.e. convert a string to a class constant).

Instead of doing this:

    @dynamic_var = "User"
    eval(@dynamic_var)

You can do this:

    @dynamic_var = "User"
    @dynamic_var.constantize

See more about the constantize method in Rails’s API.