Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Chris Anderson http://jchris.mfdz.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Speeding up your acts_as_tokenized inserts

You might want to apply this diff to your token_generator plugin. Otherwise for saving identical models the minimum time taken is one per second. Not fun!


Index: vendor/plugins/token_generator/lib/token_generator.rb
===================================================================
--- vendor/plugins/token_generator/lib/token_generator.rb       (revision 1233)
+++ vendor/plugins/token_generator/lib/token_generator.rb       (working copy)
@@ -1,7 +1,7 @@
 module TokenGenerator
   def generate_token(size = 12, &validity)
     begin
-      token = Digest::MD5.hexdigest("#{inspect}#{Time.now}").first(size)
+      token = Digest::MD5.hexdigest("#{inspect}#{Time.now}#{rand}").first(size)
     end while !validity.call(token) if block_given?
     

Mongrel Spinner and Restart tasks for Capistrano

These tasks should work with the default deploy.rb file. I assume you've at least read the Capistrano manual at rubyonrails.com, also, you should get your app running on mongrel first with manual booting and restarting before you try to automate.

h2. Spinner

desc <<-DESC
Spinner is run by the default cold_deploy task. Instead of using script/spinner, we're just gonna rely on Mongrel to keep itself up.
DESC
task :spinner, :roles => :app do
  application_port = xxxx #get this from your friendly sysadmin
  run "mongrel_rails start -e production -p #{application_port} -d -c #{current_path}"
end


h2. Restart

desc "Restart the web server"
task :restart, :roles => :app do
  begin
    run "cd #{current_path} && mongrel_rails restart"
  rescue RuntimeError => e
    puts e
    puts "Probably not a big deal, so I'll just keep trucking..."
  end
end


There's a more complete article on my blog.
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS