# creates random pronouncable passwords
def self.random_password
c = %w( b c d f g h j k l m n p qu r s t v w x z ) +
%w( ch cr fr nd ng nk nt ph pr rd sh sl sp st th tr )
v = %w( a e i o u y )
f, r = true, ''
6.times do
r << ( f ? c[ rand * c.size ] : v[ rand * v.size ] )
f = !f
end
2.times do
r << ( rand( 9 ) + 1 ).to_s
end
r
end
def break_up_long_line(str, max)
counter = 0
new_text = ''
for i in 0...str.length
if str[i,1] =~ /\n/
counter = 0
else
counter = counter + 1
end
new_text << str[i,1]
if counter >= max && str[i,1] =~ /\s/
new_text << "\n"
counter = 0
end
end
new_text
end
desc "Drop then recreate the dev database, migrate up, and load fixtures" task :remigrate => :environment do return unless %w[development test staging].include? RAILS_ENV ActiveRecord::Base.connection.tables.each { |t| ActiveRecord::Base.connection.drop_table t } Rake::Task[:migrate].invoke Rake::Task["db:fixtures:load"].invoke end
#!/usr/bin/env ruby `svn diff #{ARGV.join(' ')}`.each do |line| puts( if line =~ /^\+(.*)$/ "\e[32m#{$&}\e[0m" elsif line =~ /^-(.*)$/ "\e[31m#{$&}\e[0m" else line end ) end
# Return true if the difference between two colors # matches the W3C recommendations for readability # See http://www.wat-c.org/tools/CCA/1.1/ def colors_diff_ok? c1, c2 cont, bright = find_color_diff c1, c2 (cont > 500) && (bright > 125) # Acceptable diff according to w3c end # Return the contranst and brightness difference between two RGB values def find_color_diff c1, c2 r1, g1, b1 = break_color c1 r2, g2, b2 = break_color c2 cont_diff = (r1-r2).abs+(g1-g2).abs+(b1-b2).abs # Color contrast bright1 = (r1 * 299 + g1 * 587 + b1 * 114) / 1000 bright2 = (r2 * 299 + g2 * 587 + b2 * 114) / 1000 brt_diff = (bright1 - bright2).abs # Color brightness diff [cont_diff, brt_diff] end # Break a color into the R, G and B components def break_color rgb r = (rgb & 0xff0000) >> 16 g = (rgb & 0x00ff00) >> 8 b = rgb & 0x0000ff [r,g,b] end
possible_colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0x00ffff, 0xffffff]
good_color = 0 # We can default to black...
possible_colors.each do |c|
if colors_diff_ok? c, my_color
good_color = c
break
end
end
# e.g. Copy existing data from users table to newly created members table
userMove = User.find(:all)
userMove.each do |t|
Member.create :first_name => t.forename,
:last_name => t.surname,
:email => t.email,
:password => t.password
end