Skip to content

Instantly share code, notes, and snippets.

View demimismo's full-sized avatar

David Arango demimismo

View GitHub Profile
# I use this method to parse large csv files, clean the data and insert
# it in a database after some cleaning, it's pretty fast
# you can use it like this:
load_csv_data(PRELOAD_DIR+'socios.csv', 'users') do |csv, thing_id, row|
csv << [thing_id,
row['NOMBRE'].to_s.to_permalink+'.'+row['APELLIDOS'].to_s.to_permalink, # login
row['E_MAIL'], # email
row['SEXO'], # gender
# convert multibyte strings to an url-safe encoding
class String
def to_permalink
(Iconv.new('US-ASCII//TRANSLIT', 'utf-8').iconv self).gsub(/[^\w\s\-\—]/,'').gsub(/[^\w]|[\_]/,' ').split.join('-').downcase
end
end