Slide 1

Slide 1 text

Known unknowns @abelar_s / maitre-du-monde.fr @BBL_FR / @parisrb

Slide 2

Slide 2 text

Elephants in the room

Slide 3

Slide 3 text

Phil Karlton naming, cache invalidation

Slide 4

Slide 4 text

Hate encoding, timezones

Slide 5

Slide 5 text

I18N, L10N names, phone numbers

Slide 6

Slide 6 text

Distributed Computing 1.The network is reliable. 2.Latency is zero. 3.Bandwidth is infinite. 4.The network is secure. 5.Topology doesn't change. 6.There is one administrator. 7.Transport cost is zero. 8.The network is homogeneous.

Slide 7

Slide 7 text

Little needs

Slide 8

Slide 8 text

Big problems

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Advice

Slide 11

Slide 11 text

Gurus

Slide 12

Slide 12 text

YAGNI Gurus

Slide 13

Slide 13 text

YAGNI You Ain’t Gonna Need It So many devs...

Slide 14

Slide 14 text

Suits

Slide 15

Slide 15 text

$ Suits

Slide 16

Slide 16 text

$ Contract So many salesguys...

Slide 17

Slide 17 text

My friend

Slide 18

Slide 18 text

$ My friend

Slide 19

Slide 19 text

$ Free has no value Freelancer

Slide 20

Slide 20 text

? Myself

Slide 21

Slide 21 text

? My own company

Slide 22

Slide 22 text

? Long-term value Software editor

Slide 23

Slide 23 text

Example #1

Slide 24

Slide 24 text

Checkbox

Slide 25

Slide 25 text

‘Just a checkbox’

Slide 26

Slide 26 text

Tri-state

Slide 27

Slide 27 text

Tomorrow?

Slide 28

Slide 28 text

Timestamps?

Slide 29

Slide 29 text

Versioning?

Slide 30

Slide 30 text

State Machine

Slide 31

Slide 31 text

Checkbox + naming

Slide 32

Slide 32 text

Imports + exports

Slide 33

Slide 33 text

Example #2

Slide 34

Slide 34 text

Import a CSV file

Slide 35

Slide 35 text

IO.readlines('test.csv').each{|line| Model.create(attr: line[0]) } 30s: trivial

Slide 36

Slide 36 text

FasterCSV.parse(File.open('test.csv'), 'r').each{ |line| Client.create( attr: line[0], company: Company.find_by_name(line[1]), active: ['1', 'oui', 'X'].include?(line[2]) ) } 5mn: some more data

Slide 37

Slide 37 text

comp_cache = {} FasterCSV.parse(File.open('test.csv'), 'r').each{|line| Client.create( attr: line[0], company: comp_cache[line[1]] || (comp_cache[line[1]] = Company.find_by_name(line[1])), active: ['1', 'oui', 'X'].include?(line[2]) ) } 10mn: perf’s not good

Slide 38

Slide 38 text

comp_cache = {} FasterCSV.parse(File.open('test.csv'), 'r').each{|line| next if line.blank? || line.size != 5 comp = comp_cache[line[1]] || (comp_cache[line[1]] = Company.find_by_name(line[1])) if !comp puts "OMG IDK #{line[1]}" next end Client.create( attr: line[0], company: comp, active: ['1', 'oui', 'X'].include?(line[2]) ) } 20mn: data not good

Slide 39

Slide 39 text

comp_cache = {} FasterCSV.parse(File.open('test.csv'), 'r').each{|line| next if line.blank? || line.size != 5 comp = comp_cache[line[1]] || (comp_cache[line[1]] = Company.find_by_name(line[1])) if !comp puts "OMG IDK #{line[1]}" next end Client.create( attr: line[0], company: comp, active: ['1', 'oui', 'X'].include?(line[2]), first_name: line[3].split.first, last_name: line[3].split.last, comments: "#{line[4]} #{line[5]} (#{line[6]})" ) } 30mn: more info

Slide 40

Slide 40 text

comp_cache = {} FasterCSV.parse(File.open('test.csv'), 'r').each{|line| next if line.blank? || line.size != 5 comp = comp_cache[line[1]] || (comp_cache[line[1]] = Company.find_by_name(line[1])) if !comp puts "OMG IDK #{line[1]}" next end c = Client.find_or_create_by_attr(line[0]) c.update_columns( company: comp, active: ['1', 'oui', 'X'].include?(line[2]), first_name: line[3].split.first, last_name: line[3].split.last, comments: "#{line[4]} #{line[5]} (#{line[6]})" ) ok = c.save puts c.errors.full_messages.inspect unless ok ok }.partition{|x| x}.map{|a| "#{a.size} #{a.first}" } 45mn: some logs

Slide 41

Slide 41 text

def to_date(date) months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"] tmp = date.scan(/([0-9]{2})([A-Z]{3})([0-9]{4})/).flatten tmp[0] = tmp[0].to_i tmp[1] = months.index(tmp[1]) + 1 tmp[2] = tmp[2].to_i Date.new(tmp[2], tmp[1], tmp[0]) end def to_float(var) (var.blank? || var == '.' ? nil : var.to_s.tr(' ,', '_.').to_f) end def transcode_file(filepath) input = File.open(filepath) File.open(Rails.root.join("tmp", "import_utf8.csv"), "wb") do |f| until input.eof? content = input.read(2**16) detection = CharlockHolmes::EncodingDetector.detect(content) content = CharlockHolmes::Converter.convert(content, detection[:encoding], "UTF-8") f.write(content) end end end 1h: some ‘utils’

Slide 42

Slide 42 text

Solutions?

Slide 43

Slide 43 text

... automating...

Slide 44

Slide 44 text

# gem install upsert # gem install smartercsv SmarterCSV.process( Rails.root.join("tmp", "test.csv"), :col_sep => ';', :chunk_size => 10000) do |chunk| # ... Upsert.batch(connection, 'infos') do |upsert_infos| upsert.row({code: row[:code]}, name: row[:nom]) # ... end end Tools to the rescue

Slide 45

Slide 45 text

Freedom!

Slide 46

Slide 46 text

Independence day!

Slide 47

Slide 47 text

Bad data: purge

Slide 48

Slide 48 text

Where am I?

Slide 49

Slide 49 text

Bad files

Slide 50

Slide 50 text

OK, KO, warnings...

Slide 51

Slide 51 text

And much more... - source - field separator - encoding - XLS tab - behaviour - numbers - offset - errors - create / update - column match - update on... ?

Slide 52

Slide 52 text

What else?

Slide 53

Slide 53 text

Check my data

Slide 54

Slide 54 text

Duplicates Duplicates

Slide 55

Slide 55 text

Err0r Corektion

Slide 56

Slide 56 text

Errors;As;CSV Export ;to ; report Import ;to ; merge

Slide 57

Slide 57 text

Another source

Slide 58

Slide 58 text

Refactoring

Slide 59

Slide 59 text

Performance

Slide 60

Slide 60 text

Audit trail File, format, person, timestamp, source, transforms + origins

Slide 61

Slide 61 text

Blame all the things!

Slide 62

Slide 62 text

Example #3

Slide 63

Slide 63 text

Reporting

Slide 64

Slide 64 text

‘Just some sums’

Slide 65

Slide 65 text

... and filters

Slide 66

Slide 66 text

and exports

Slide 67

Slide 67 text

and graphs

Slide 68

Slide 68 text

Programmer Time Translation Table est real coder thinks manager knows 30s 1h trivial! do, build, test, deploy... 5mn 2h easy! unexpected problem 1h 2h code... not on the 1st try 4h 4h check docs realistic 8h 12~16d minor refactor many dependencies 2d 5d OK, real code same as before 1wk 2~20d wow, er... let’s see with the team http://coding.abel.nu/2012/06/programmer-time-translation-table/

Slide 69

Slide 69 text

Thanks! @abelar_s / maitre-du-monde.fr HumanTalks 2013-11-12

Slide 70

Slide 70 text

Questions? @abelar_s / maitre-du-monde.fr HumanTalks 2013-11-12

Slide 71

Slide 71 text

Questions? @abelar_s / maitre-du-monde.fr HumanTalks 2013-11-12 Little needs : regardez ce qu'ont fait les projets open source, vos concurrents Le Code de Retour - le batch et le cache