Skip to content

Instantly share code, notes, and snippets.

#
# Cookbook Name:: delayed_job
# Recipe:: default
#
if ['solo', 'app', 'app_master'].include?(node[:instance_role])
# be sure to replace "app_name" with the name of your application.
run_for_app("maloca") do |app_name, data|
@robdimarco
robdimarco / before_symlink.rb
Created August 6, 2010 01:36
Scripts to set up an EngineYard AppCloud that will use Amazon S3 as its assets host. These scripts will sync your public directory (including any cache files such as cached javascript) up to a bucket on S3 which can then be used as an asset host.
@robdimarco
robdimarco / gist:847622
Created February 28, 2011 17:01
Bootstrapping ActiveRecord from database.yml
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection YAML.load(File.open(File.join(Rails.root, "config", "database.yml")))[Rails.env]
@robdimarco
robdimarco / loads_presenter.rb
Created September 29, 2011 00:58 — forked from r38y/loads_presenter.rb
Custom sorting rules and presenters
class LoadsPresenter
extend ActiveSupport::Memoizable
def loads; raise "Implement #loads in subclass"; end
memoize :loads
def each(&block)
loads.each(&block)
end
@robdimarco
robdimarco / business.rb
Created December 29, 2011 21:41
Simple Business class with a text and a location
class Business < ActiveRecord
searchable do
text :name # Will be stored as a field named name_text in Solr
text :location # Will be stored as a field named location_text in Solr
end
end
# Given data set
# ID Name Location
# 1 Boone Moving Service Raleigh, NC
@robdimarco
robdimarco / business.rb
Created December 30, 2011 18:19
Business class with custom search
class Business < ActiveRecord
searchable do
text :name
text :location
end
def self.custom_search(query)
search do
adjust_solr_params do |p|
# We want to break out all of the terms
terms = query.split(/[^a-zA-Z0-9]+/)
@robdimarco
robdimarco / schema.xml
Created December 30, 2011 19:09
Updated schema.xml with untokenized field
<fieldType name="untokenized" class="solr.TextField">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<fields>
<!-- ... -->
<field name="business_name_untokenized" stored="false" type="text_auto" multiValued="false" indexed="true"/>
</fields>
@robdimarco
robdimarco / business.rb
Created December 30, 2011 19:25
Business class with search method sorting correctly
class Business < ActiveRecord
searchable do
text :name
text :location
end
def self.custom_search(query)
search do
adjust_solr_params do |p|
# We want to break out all of the terms
terms = query.split(/[^a-zA-Z0-9]+/)
class Article < ActiveRecord::Base
default_scope where(:published => true)
end
@robdimarco
robdimarco / erb_to_haml.sh
Created February 12, 2012 18:51
Bash one-liner to move all ERB files to HAML using html haml
for f in `find . -name '*.erb'`; do
new_f=`dirname $f`/`basename $f | sed s/erb/haml/`;
html2haml $f > $new_f;
git rm $f;
done