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
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
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
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
Making email addresses out of common names
<pre class='prettyprint' language='ruby'>original_file = File.open('content1.txt', 'r') new_file = File.open('master1.txt', 'w') master_list = [] counter = 0 counter_written = 0 original_file.each_line do |line| counter += 1 name = line.split(' ') # Handle multi-worded surnames ('Von Bluth') if name.length > 2 name[1] = name[1] + name[2] name.pop end # Handle hyphenated names (Bluth-Funke) if name[1] =~ /-/ name[1] = name[1].split('-').pop end username = "#{name[0][0].chr}#{name[1]}".downcase master_list << username counter_written += 1 if new_file.puts("#{username}@somedomain.com").nil? end original_file.close new_file.close duplicates = master_list.inject({}){|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys master_list.sort.each {|username| puts username + '@somedomain.com'} puts "\n\n" puts "- - - - - - - - - - - - - - - - - - - -" puts "Processed: #{counter}" puts "Written: #{counter_written}" puts "Master List: #{master_list.size}" puts "- - - - - - - - - - - - - - - - - - - -" puts "Duplicates: #{duplicates.size}" puts "#{duplicates.join(', ')}" puts "\n\n"</pre> <a href="http://www.refactormycode.com/codes/1146-making-email-addresses-out-of-common-names" 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>