This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bar | |
include MongoMapper::Document | |
normalize_attributes :name | |
key :name, String | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# bash completion support for core Git. | |
# | |
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]> | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
truncated = sentences.inject(sentences.first) do |memo, sentence| | |
if memo.split.size < limit | |
memo.concat(" ").concat(sentence) | |
else | |
memo | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |