Skip to content

Instantly share code, notes, and snippets.

@localshred
localshred / sql_like.rb
Created October 29, 2009 03:55
It always bugged me that there isn't really a "rails-style" way to do like syntaxes with active record. So, one day while building a keyword search on the users table, I decided to roll my own. I've thought about making this more ActiveRecord friendly, bu
# Build a condition array from the provided keywords and a specific set of fields to search on
# Take out any keywords that are 2 chars or less
def self.find_by_keywords(keywords)
# Columns to do keyword searching on
fields = %w{ user_name email }
# Strip all words 2 chars or less, then split into an array
keywords = keywords.gsub(/\b\S{1,2}\b/, "").strip.downcase.split(/\s+/)
unless (keywords.nil? || keywords.empty?)
@localshred
localshred / git-workflow.sh
Created October 16, 2009 05:34
My simple git workflow for using topic branches
# This is a simple descriptor on how I do topic development using git
# Some of the commands are java flavored (like ant),
# but that doesn't mean you can't use this with other languages.
# Step 1 - Synchronize master.
# 1.1 - Checkout master branch
# 1.2 - Get changes from origin
git checkout master
git pull