This file contains hidden or 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
# Be sure to restart your server when you modify this file. | |
# Add new inflection rules using the following format | |
# (all these examples are active by default): | |
ActiveSupport::Inflector.inflections do |inflect| | |
# inflect.plural /^(ox)$/i, '\1en' | |
# inflect.singular /^(ox)en/i, '\1' | |
# inflect.irregular 'person', 'people' | |
# inflect.uncountable %w( fish sheep ) | |
inflect.plural /(or)$/i, '\1es' |
This file contains hidden or 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
# Adapted from http://blog.sidu.in/2008/01/ruby-blocks-redux-ruby-190-ruby-186-and.html | |
require 'benchmark' | |
def implicit(*args) | |
yield args.join(' ') | |
end | |
def explicit(*args, &block) | |
block.call args.join(' ') |
This file contains hidden or 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
<!-- 1. Return all countries with population between 9 and 10 million. Retain the structure of country elements from the original data. --> | |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:template match="country[@population > 9000000][@population < 10000000]"> | |
<xsl:copy-of select="." /> | |
</xsl:template> | |
<xsl:template match="text()" /> | |
</xsl:stylesheet> |
This file contains hidden or 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
<!-- 1. Return the area of Mongolia. --> | |
<!-- Reminder: To return the value of an attribute attr, you must use data(@attr), although just @attr may be used in comparisons. You will need to remember this for some later questions as well. --> | |
//country[@name = "Mongolia"]/data(@area) | |
<!-- 2. Return the names of all cities that have the same name as the country in which they are located. --> | |
//city[name = parent::country/data(@name)]/name |
This file contains hidden or 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
<!-- 1. Return a list of department titles. --> | |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:template match="Department"> | |
<Title><xsl:value-of select="Title" /></Title> | |
</xsl:template> | |
</xsl:stylesheet> | |
This file contains hidden or 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
<!-- 1. Return all Title elements (of both departments and courses). --> | |
//Title | |
<!-- 2. Return last names of all department chairs. --> | |
//Chair//Last_Name | |
//Chair/*/Last_Name |
This file contains hidden or 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
# Usage: | |
# | |
# class MyClass < ActiveRecord::Base | |
# ... | |
# validate :postal_code, spanish_postal_code: true # default message | |
# validate :postal_code, spanish_postal_code: { message: '<Your message>' } # custom message | |
# ... | |
# end | |
# | |
class SpanishPostalCodeValidator < ActiveModel::EachValidator |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE countries [ | |
<!ELEMENT countries (country*)> | |
<!ELEMENT country ((language|city)*)> | |
<!ATTLIST country name CDATA #REQUIRED population CDATA #REQUIRED area CDATA #REQUIRED> | |
<!ELEMENT language (#PCDATA)> | |
<!ATTLIST language percentage CDATA #REQUIRED> | |
<!ELEMENT city (name, population)> | |
<!ELEMENT name (#PCDATA)> |
This file contains hidden or 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
-- 1. Find the names of all students who are friends with someone named Gabriel. | |
SELECT H1.name | |
FROM Highschooler H1 | |
INNER JOIN Friend ON H1.ID = Friend.ID1 | |
INNER JOIN Highschooler H2 ON H2.ID = Friend.ID2 | |
WHERE H2.name = "Gabriel"; | |
-- 2. For every student who likes someone 2 or more grades younger than themselves, return that student's name and grade, and the name and grade of the student they like. |
This file contains hidden or 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
-- 1. Find the titles of all movies directed by Steven Spielberg. | |
SELECT title | |
FROM Movie | |
WHERE director = 'Steven Spielberg'; | |
-- 2. Find all years that have a movie that received a rating of 4 or 5, and sort them in increasing order. | |
SELECT DISTINCT year |