Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Learning JS
Type Safety
Euler Problem 2 solution
Popular
Parsing of XML data has high CPU usage
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Learning JS
Too many if statements
clean the code
Pastable version of
Rails migration conflict repair
<pre class='prettyprint' language='ruby'>namespace :migrations do desc 'reverts, renames and re-executes uncommitted migrations that conflict with already committed migrations' task :repair => :environment do uncommitted = `svn status`.select {|line| line =~ /db\/migrate\//}.collect {|line| line.match(/ db\/migrate\/(.*rb)/)[1]} committed = Dir.glob('db/migrate/*').collect {|line| line.match(/db\/migrate\/(.*rb)/)[1]} - uncommitted highest_committed = committed.collect(&:to_i).max lowest_uncommitted = uncommitted.collect(&:to_i).min schema_version = ActiveRecord::Base.connection.select_one("select version from schema_info")["version"].to_i # revert uncommitted migrations uncommitted.sort_by(&:to_i).reverse.each do |migration| version = migration.to_i if version <= schema_version name = migration.match(/(\d*_.*).rb/)[1] class_name = (require 'db/migrate/' + name)[0] puts class_name.constantize.down end end #set it back to the version prior to all the uncommitted migrations - this doesn't get done automatically by calling down ActiveRecord::Base.connection.execute("update schema_info set version=#{schema_version-1}") version_offset = (highest_committed - lowest_uncommitted) + 1 uncommitted.each do |old_name| version = old_name.to_i + version_offset new_name = version.to_s.rjust(3,'0') + old_name.gsub(/\d/, '') `mv db/migrate/#{old_name} db/migrate/#{new_name}` end puts "Uncommited migrations have been reversed and renamed. You can now migrate." end end</pre> <a href="http://www.refactormycode.com/codes/112-rails-migration-conflict-repair" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>