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
%w(a b c).each do |var| | |
define_method var do | |
ivar = "@#{var}" | |
if instance_variable_defined?(ivar) | |
instance_variable_get(ivar) | |
else | |
instance_variable_set(ivar, Expensive.request) | |
end | |
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
// Some basic styles | |
.modal { | |
width: 660px; | |
.modal-header { | |
.close { | |
margin: 0; | |
padding: 0; | |
&:hover { opacity: 1; } |
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
<!-- 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 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 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 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
# spec/support/matchers/have_constant.rb | |
RSpec::Matchers.define :have_constant do |constant| | |
match do |owner| | |
([Class, Module].include?(owner.class) ? owner : owner.class).const_defined?(constant) | |
end | |
failure_message_for_should do |klass| | |
"expected #{klass} to have constant #{constant}" | |
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
module FeatureHelpers | |
# Finds a file field on the page and attach a file given its path | |
def enhanced_attach_file(path) | |
field = find('input[type=file]', visible: false) | |
page.execute_script %($("##{field[:id]}").show()) | |
attach_file field[:id], path.to_s | |
end | |
# Finds a file field on the page and attach a file given its path | |
def enhanced_attach_file(path) |
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
# 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 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
# Each subdivision can go down to 127 levels deep, and each DNS label can contain up to 63 characters, | |
# as long as the whole domain name does not exceed a total length of 255 characters. | |
class SubdomainValidator < ActiveModel::EachValidator | |
def validate_each(object, attribute, value) | |
return unless value | |
reserved_names = %w[admin beta blog ftp imap mail pop pop3 sftp smtp ssl www] | |
reserved_names += options[:reserved] if options[:reserved] | |
object.errors[attribute] << 'cannot be a reserved name' if reserved_names.include?(value.downcase) |
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
<?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)> |
OlderNewer