Skip to content

Instantly share code, notes, and snippets.

@kmamykin
kmamykin / Gemfile
Created August 3, 2011 13:51
heroku run rake assets:precompile
gem 'rails', '3.1.0.rc5'
gem 'thin'
gem 'foreman'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', "~> 3.1.0.rc"
gem 'coffee-rails', "~> 3.1.0.rc"
@kmamykin
kmamykin / gist:1117047
Created July 31, 2011 18:27
foreman not terminating process
$ cat Procfile
web: rails server thin -p $PORT
$ gem list | grep foreman
foreman (0.19.0)
$ ps aux | grep thin
kmamykin 13773 0.0 0.0 4156 864 pts/2 S+ 14:22 0:00 grep thin
$ foreman start
14:22:36 web.1 | started with pid 13897
14:22:50 web.1 | => Booting Thin
14:22:50 web.1 | => Rails 3.1.0.rc4 application starting in development on http://0.0.0.0:5000
@kmamykin
kmamykin / tasks.rake
Created June 28, 2011 08:26
How to render Rails 3 view in a rake task
task :renderview => :environment do
app = YourApp::Application
app.routes.default_url_options = { :host => 'xxx.com' }
controller = YourController.new
view = ActionView::Base.new(app.config.paths.app.views.first, {}, controller)
view.class_eval do
include ApplicationHelper
include app.routes.url_helpers
end
puts view.render(:template => 'your/action')
@kmamykin
kmamykin / mondodb_autoincrement_id.rb
Created January 12, 2011 08:29
How to generate autoincremented int id in MongoDB
# loosely based on:
# http://shiflett.org/blog/2010/jul/auto-increment-with-mongodb
new_id = Mongoid.master["sequences"].find_and_modify
:query =>{"_id"=>"<name of your business entity>"},
:update=>{"$inc"=>{"seq"=>1}},
:upsert=>true,
:new =>true #<-- this causes the new incremented id to be returned