Skip to content

Instantly share code, notes, and snippets.

View jacqui's full-sized avatar

Jacqui Lough jacqui

View GitHub Profile
@jacqui
jacqui / Rails MongoMapper Template.rb
Created December 10, 2009 02:35 — forked from banker/Rails MongoMapper Template.rb
Removed the application layout file as it kept barfing on it
# mongo_template.rb
# fork of Ben Scofield's Rails MongoMapper Template (http://gist.github.com/181842)
#
# To use:
# rails project_name -m http://gist.github.com/253067.txt
# remove unneeded defaults
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/controls.js"
class Bar
include MongoMapper::Document
normalize_attributes :name
key :name, String
end
>> project.forms.size
# => 1
>> f = project.forms.build(:name => "foo", :headline => "bar")
# => #<Form name: "foo", slug: nil, thanks: nil, section: nil, nyt_wrapper: true, intro: nil, custom_css: nil, created_at: nil, submission_email: nil, image_count: 0, project_id: 4b05c1cb3fe2266174000001, updated_at: nil, _id: nil, headline: "bar", subject_filter: nil, notification_emails: [], header: nil, custom_js: nil, version: nil, image_upload: true, text_count: 0, status: "pending", keywords: nil, submission_count: 0>
>> f.save
# => true
>> project.forms.size
@jacqui
jacqui / .git-completion.bash
Created December 11, 2009 15:31
git tab completion and displaying branch in prompt - yay!
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names
root@int-shared-stg:~# gem install bcrypt-ruby
Building native extensions. This could take a while...
Successfully installed bcrypt-ruby-2.1.2
1 gem installed
Installing ri documentation for bcrypt-ruby-2.1.2...
Installing RDoc documentation for bcrypt-ruby-2.1.2...
require 'rubygems'
require 'pp'
unless self.class.const_defined? "IRB_RC_HAS_LOADED"
# Log to STDOUT if in Rails
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
require 'logger'
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
end
The Autonomous Komi Republic,
which is part of the Russian
Federation, is situated in the
far northwest of Europe, and
spreads up to
the Arctic part of the Ural Mountains.
It's crossed by 9 northern
parallels. Ten fair-sized European
states could be placed on its
territory. Besides indigenous
truncated = sentences.inject(sentences.first) do |memo, sentence|
if memo.split.size < limit
memo.concat(" ").concat(sentence)
else
memo
end
end
def truncate_text(input = "", limit = 15)
words = input.split
return input if words.size <= limit
truncated_words = words[0..limit-1]
i = nil
last_punctuated_word = truncated_words.reverse.detect.with_index{|p,i| p.match(/[\.\!\?]/) }
last_word_index = truncated_words.index(i)
words[0..last_word_index].join(' ')
end
rescue_from ActiveResource::BadRequest, :with => :ar_bad_request
def ar_bad_request(e)
@message = e.message
respond_to do |format|
format.html { render :template => "#{RAILS_ROOT}/public/something.html", :layout => false, :status => 400}
format.xml { render :template => "api/something.xml", :status => 400, :content_type => 'application/xml' }
format.json { render :template => "api/something.json", :status => 400, :content_type => 'application/json' }
end
end