Posts Tagged ‘ruby’

Ruby make list minimum length

Sunday, December 13th, 2015 by Jesper Rønn-Jensen

In a Ruby on Rails app, I wanted a list to be at least of two items. This could be done in several ways. Here is a first naïve impementation: # Naïve implementation, just return whatever number I need def sum_up_a(existing) return 2 if existing == 0 return 1 if existing == 1 return 0 end […]

Seeding Rails App With RESTful Address Data

Wednesday, April 28th, 2010 by Jesper Rønn-Jensen

Grabbing data from Restful webservices has never been easier. I use this code in the Rails /db/seeds.rb file to grab data from the Danish webservice with addresses, municipalities, regions, etc. I decided to import the data into a local database to ensure it could work offline. Code from /db/seeds.rb file: Now I can access municipalities […]

Extract HTML Structure From Page With Simple Script

Monday, October 5th, 2009 by Jesper Rønn-Jensen

I often want to extract parts of HTML page. Often I find myself parsing a doc with Nokogiri and extracting it with a CSS selector. It’s pretty straight-forward from scratch. To follow the Don’t Repeat Yourself principle, I created a script to make it a one-liner. Just run ruby parsepage.rb [url] [css_selector] Feel free to […]