War is the most destructive act man can undertake. It robs innocents of life. It divides those that might otherwise be friends. It decimates land and property. It extinguishes the fires of culture and tradition. It makes widows of wives and turns pride into sorrow. It transforms its survivors into amputees, suicides, and vengeance seekers.
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
some_random_id = SecureRandom.hex | |
content = <<-EOS | |
<div id="#{some_random_id}"> | |
#{actual_html_to_parse} | |
</div> | |
EOS | |
html = Nokogiri.HTML(content) |
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
± % wget https://rubygems.org/downloads/rails-3.2.9.gem !10592 | |
--2012-11-24 16:01:47-- https://rubygems.org/downloads/rails-3.2.9.gem | |
Resolving rubygems.org... 204.232.149.26, 204.232.149.25 | |
Connecting to rubygems.org|204.232.149.26|:443... connected. | |
HTTP request sent, awaiting response... 302 Moved Temporarily | |
Location: https://rubygems.org/gems/rails-3.2.9.gem [following] | |
--2012-11-24 16:01:48-- https://rubygems.org/gems/rails-3.2.9.gem | |
Reusing existing connection to rubygems.org:443. | |
HTTP request sent, awaiting response... 302 Moved Temporarily | |
Location: https://s3.amazonaws.com/production.s3.rubygems.org/gems/rails-3.2.9.gem [following] |
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
some_variable = if exp && ext_define?(exp) | |
make_class(to_value(exp["arguments"][0]), exp) | |
# foo = Ext.extend("Parent", {}) | |
elsif exp && assignment?(exp) && ext_extend?(exp["right"]) | |
make_class(to_s(exp["left"]), exp["right"]) | |
# Foo = ... | |
elsif exp && assignment?(exp) && class_name?(to_s(exp["left"])) | |
make_class(to_s(exp["left"]), exp["right"]) |
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
class EmailValidator < ActiveModel::EachValidator | |
# http://fightingforalostcause.net/misc/2006/compare-email-regex.php | |
# Thanks to James Watts and Francisco Jose Martin Moreno | |
EMAIL_REGEX = /^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i | |
def validate_each(object,attribute,value) | |
if value.blank? | |
object.errors[attribute] << (options[:message] || "can't be blank") unless options[:allow_blank] | |
elsif !(value =~ EMAIL_REGEX) | |
object.errors[attribute] << (options[:message] || "is not a valid email address") |
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
# Thank you http://twistedmind.com/bundle-exec-bash-shortcut | |
bundle_commands=( spec rspec cucumber cap watchr rails rackup autotest heroku rdebug ) | |
function run_bundler_cmd () { | |
if [ -e ./Gemfile ]; then | |
echo "bundle exec $@" | |
bundle exec $@ | |
else | |
echo "$@" | |
$@ |
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
‘Other evils there are that may come; for Sauron is himself but a | |
servant or emissary. Yet it is not our part to master all the tides | |
of the world, but to do what is in us for the succour of those years | |
wherein we are set, uprooting the evil in the fields that we know, so | |
that those who live after may have clean earth to till. What weather | |
they shall have is not ours to rule.’ |
It was Sam's first view of a battle of Men against Men, and he did not like it much. He was glad that he could not see the dead face. He wondered what the man's name was and where he came from; and if he was really evil of heart, or what lies or threats had led him on the long march from his home; and if he would not really rather have stayed there in peace—all in a flash of thought which was quickly driven from his mind.
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
@doc = Nokogiri::HTML::Document.parse <<-EOHTML | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
</head> | |
<body> | |
<h1>Three's Company</h1> | |
<article class="foo bar baz">A love triangle.</article> | |
</body> |
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
$().ajaxError(function(event, xhr, settings, error) { | |
switch(xhr.status) { | |
case 401: | |
MyApp.renderLoginForm(); | |
break; | |
case 406: | |
... | |
break; | |
} | |
}); |