Skip to content

Instantly share code, notes, and snippets.

some_random_id = SecureRandom.hex
content = <<-EOS
<div id="#{some_random_id}">
#{actual_html_to_parse}
</div>
EOS
html = Nokogiri.HTML(content)
± % 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]
@scudco
scudco / blob.rb
Created September 20, 2012 20:05 — forked from gjtorikian/blob.rb
ruby blob of jsduck
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"])

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.

@scudco
scudco / email_validator.rb
Created February 16, 2011 22:02
Rails 3 Email Validator
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")
# 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 "$@"
$@
@scudco
scudco / gandalf.txt
Created January 5, 2011 03:48
Gandalf the Grey in Lord of the Rings: Return of the King The Last Debate
‘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.’
@scudco
scudco / Samwise Gamgee on War.md
Created December 4, 2010 20:14
Amazing excerpt from Chapter IV of Book IV of The Lord of the Rings

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.

@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>
$().ajaxError(function(event, xhr, settings, error) {
switch(xhr.status) {
case 401:
MyApp.renderLoginForm();
break;
case 406:
...
break;
}
});