Ruby/Rails: Parse large XMLs (SAX parsers, Pull parsers) + example of Pull parser

When you have to parse huge XML files (hundreds of MB-like), loading the whole XML in memory is not an option.

Continue reading

Free IATA + ICAO airport codes database

Parsed from: Wikipedia.

Available on YAML or JSON format.

Data example:

- :airport_name: Charles de Gaulle International Airport (Roissy Airport)
  :complete_location: Paris, France
  :city: Paris
  :country: "France"
  :iata_code: CDG
  :icao_code: LFPG

Continue reading

Phone calling codes (aka International Dialing codes) – DB Dump / YML format

Parsed from: with Hpricot:

doc = Hpricot(open(""))
table = (doc/"table")[4]
by_country = {}'/tr').each {|tr| tr0 ='/td')[0] ; tr1 ='/td')[1]; by_country[tr0.inner_html.gsub(/<.*>/,  "")] ='/a').inner_html.gsub(" ", '').split(/\+/).select{|val| !val.empty?}.map(&:to_i) if tr1  } ; nil

Phone calling codes (MySQL dump)

Phone calling codes by country (YML format)

Ruby on Rails Interview questions – update

Most of Google searches that hit my blog are about ‘ruby on rails interview questions‘.

Responding to this popular request 😉 , I will post 3 more questions that are related.

1. What type of data would you use to represent currency?

2. Why is it not a good practice to use float for currency?

3. Explain the following behaviour:

~$ ruby --version
ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
~$ irb
irb(main):003:0> (10.12*100).to_i
=>; 1011

The answer – in my next post .