Skip to content

Instantly share code, notes, and snippets.

@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
@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?)
class LibraryController > ApplicationController
...
def index
@file_tree = AudioLib.build_tree
end
...
end
$ cap deploy:cold
* executing `deploy:cold'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote [email protected]:/home/git/myapp.git HEAD"
* executing "git clone -q [email protected]:/home/git/myapp.git /var/www/myapp/releases/20100204223421 && cd /var/www/myapp/releases/20100204223421 && git checkout -q -b deploy 14dd2843341cd0984afb147050a02228ee7eae02 && (echo 14dd2843341cd0984afb147050a02228ee7eae02 > /var/www/myapp/releases/20100204223421/REVISION)"
servers: ["mydomain.com"]
[mydomain.com] executing command
command finished
@localshred
localshred / deploy.rb
Created February 4, 2010 23:03 — forked from richievos/bundler_cap.rb
Using Bundler 0.9.1 with Capistrano
# ...
namespace :bundler do
task :create_symlink, :roles => :app do
shared_dir = File.join(shared_path, 'bundle')
release_dir = File.join(current_release, '.bundle')
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
end
task :bundle_new_release, :roles => :app do
$ cap shell
* executing `shell'
====================================================================
Welcome to the interactive Capistrano shell! This is an experimental
feature, and is liable to change in future releases. Type 'help' for
a summary of how to use the shell.
--------------------------------------------------------------------
cap> which bundle
[establishing connection(s) to mydomain.com]
error: failed: "sh -c 'which bundle'" on mydomain.com
$ thor spec:integration ad_events
Running integration specs matching filter 'ad_events_spec.rb'
/usr/local/lib/ruby19/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant VERSION
/usr/local/lib/ruby19/site_ruby/1.9.1/rubygems.rb:14: warning: already initialized constant RubyGemsVersion
/usr/local/lib/ruby19/site_ruby/1.9.1/rubygems.rb:194: warning: already initialized constant MUTEX
/usr/local/lib/ruby19/site_ruby/1.9.1/rubygems.rb:196: warning: already initialized constant RubyGemsPackageVersion
/usr/local/lib/ruby19/site_ruby/1.9.1/rubygems.rb:202: warning: already initialized constant WIN_PATTERNS
/usr/local/lib/ruby19/site_ruby/1.9.1/rubygems.rb:1079: warning: already initialized constant MARSHAL_SPEC_DIR
/usr/local/lib/ruby19/site_ruby/1.9.1/rubygems.rb:1084: warning: already initialized constant YAML_SPEC_DIR
/usr/local/lib/ruby19/site_ruby/1.9.1/rubygems/version.rb:72: warning: already initialized constant VERSION_PATTERN
book_names.each do |book_title|
chapters = agent.page.links_with(:href => book_title)
chapter_id = 0
chapters.each do |ch|
chapter_id += 1
ch.click
content = agent.page.search(".result-text-style-normal").map(&:text).map(&:strip).to_s
passage_text = Passager.new(content, 0)
passage_text.passages.each do |p|
Verse.create!(:body => p, :chapter_id => chapter_id)
# find all the books in the db
books = Book.all
book_names.each do |book_title|
# gets the proper book from the books array
book_record = books.detect{|book| book.name =~ book_title }
# ...
end
@localshred
localshred / style_guide.md
Created July 26, 2010 19:27
A general collection of ruby style guidelines that I tend to follow

My Ruby Style Guide

General Syntax rules

Class names should be full camel-case:

class AtlasGuide
end

Method names should be underscored: