Skip to content

Instantly share code, notes, and snippets.

# Basic tagging system for mongoid documents.
# jpemberthy 2010
#
# class User
# include Mongoid::Document
# include Mongoid::Document::Taggable
# end
#
# @user = User.new(:name => "Bobby")
# @user.tag_list = "awesome, slick, hefty"
@ilpoldo
ilpoldo / templator.rb
Created September 2, 2010 14:30
My rails 3 app template
# Cleaning up and extending the Gemfile
remove_file 'Gemfile'
create_file 'Gemfile', <<-GEMFILE
source 'http://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
@alg
alg / mongoid.rb
Created December 21, 2010 08:08
No underscore/dash escaping in Mongoid
# Instead of the standard composition, convert everything
# non-alpha and non-digit to dash and squeeze
class String
def identify
if Mongoid.parameterize_keys
gsub(/[^a-z0-9]+/, ' ').strip.gsub(' ', '-')
else
self
end
end
@mrrooijen
mrrooijen / gist:801418
Created January 29, 2011 01:59
Inherited Resources - Mongoid collection hack
##
# Option 1 (Probably best)
module MongoidActions
def collection
get_collection_ivar || set_collection_ivar(end_of_association_chain.all)
end
end
InheritedResources::Base.send :include, MongoidActions
@terrbear
terrbear / write_deploy_log.rb
Created February 23, 2011 17:56
saves the deploy output up to the deployed location
alias :pputs :puts
def puts(str = "")
pputs(str)
$out << "#{str}"
end
STDOUT.instance_eval do
alias :pputs :puts
def puts(str = "")
pputs(str)
require 'sinatra/base'
class MyApp < Sinatra::Base
@@my_app = {}
def self.new(*) self < MyApp ? super : Rack::URLMap.new(@@my_app) end
def self.map(url) @@my_app[url] = self end
class FooController < MyApp
map '/foo'
@ryanb
ryanb / spec_helper.rb
Created September 12, 2011 21:37
Use RSpec tags to add behavior around specs.
# Add this to your spec_helper.rb
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.around(:each, :vcr) do |example|
name = example.metadata[:full_description].downcase.gsub(/\W+/, "_").split("_", 2).join("/")
VCR.use_cassette(name, :record => :new_episodes) do
example.call
end
end
end
@durran
durran / simple_form.rb
Created September 16, 2011 11:25
Mongoid with simple form.
module SimpleForm
class FormBuilder
alias _find_association_reflectio find_association_reflection
def find_association_reflection(association) #:nodoc:
if reflection = _find_association_reflectio(association)
ActiveModelMetadataProxy.new reflection
end
end
@sr
sr / Gemfile
Created December 19, 2011 13:55
Janky on Heroku
source "http://rubygems.org"
gem "janky", "~>0.9"
gem "pg"
gem "thin"
@geuis
geuis / remote-typeahead.js
Created February 16, 2012 22:58
Remote data querying for Twitter Bootstrap 2.0 Typeahead without modifications
<script>
// Charles Lawrence - Feb 16, 2012. Free to use and modify. Please attribute back to @geuis if you find this useful
// Twitter Bootstrap Typeahead doesn't support remote data querying. This is an expected feature in the future. In the meantime, others have submitted patches to the core bootstrap component that allow it.
// The following will allow remote autocompletes *without* modifying any officially released core code.
// If others find ways to improve this, please share.
var autocomplete = $('#searchinput').typeahead()
.on('keyup', function(ev){
ev.stopPropagation();