This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
desc 'Move data from the carmen gem into the database' | |
task load_geo_data: :environment do | |
puts '-----------About to load geo-data from Carmen gem into the database----------------' | |
Carmen::Country.all.each do |country| | |
new_country = Country.create(name: country.name) | |
country.subregions.each do |subregion| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class City < ActiveRecord::Base | |
self.primary_keys = :country_name, :subregion_name, :name | |
belongs_to :subregion, foreign_key: [:country_name, :subregion_name] | |
default_scope { order('name') } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Passenger 1 is 1/100 likely to randomly pick passenger two's seat. | |
// Passenger 2 is 1/100 likely to have been displaced by passenger 1. | |
// Passenger 3 is 1/100 likely to have been displaced by passenger 1. | |
// Passenger 3 is (1/100 * 1/99) likely to have been displaced by passenger 2. Because Passenger 2 was 1/100 likely to have been displaced by passenger 1, and if displaced 1/99 likely to have randomly chosen passenger 3's seat. | |
// All in all, Passenger 3 is (1/100 + (1/100 * 1/99)) likely to have been displaced. | |
// Passenger 4 is (1/100 + (1/100 * 1/99) + (1/100 * 1/99 * 1/98)) likely to have been displaced |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo "Total number of words:" | |
cat /usr/share/dict/american-english | wc -w | |
echo "" | |
# To fix this, you need to filter the dictionary words | |
echo "Number of words containing the string 'auto':" | |
cat /usr/share/dict/american-english | FILL_ME_IN | wc -w | |
echo "" |