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
require 'nokogiri' | |
html = %q{ | |
<table> | |
<tr class="even_class"> | |
<td></td> | |
</tr> | |
<tr class="odd_class"> | |
<td></td> | |
</tr> |
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 = " | |
<levels> | |
<lvl attr = 'x'> | |
<lvl2> | |
<lvl3 n = 'unique_value 1A'>'</lvl3> | |
</lvl2> | |
</lvl1> | |
<lvl attr = 'y' another_attr = 'z'> | |
<lvl2> |
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 = '<?xml version="1.0" encoding="UTF-8"?> | |
<bookstore> | |
<book id = "1"> | |
<title lang="en">Harry Potter</title> | |
<price>29.99</price> | |
Harry Potter is great! | |
</book> | |
<book id = "2"> | |
<title lang="en">Learning XML</title> |
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
# Courtesy of http://www.rubyinside.com/how-to/ruby-sort-hash | |
# I added the reverse (descending) sort part at the bottom. | |
# Sample Data | |
people = { | |
:fred => { :name => "Fred", :age => 23 }, | |
:joan => { :name => "Joan", :age => 18 }, | |
:pete => { :name => "Pete", :age => 54 } | |
} |
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
require 'rubygems' | |
require 'nokogiri' | |
xml = <<EOF | |
<Guide> | |
<Master> | |
<Part>12345</Part> | |
<Sub> | |
<Name>A</Name> | |
</Sub> |
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
RE = /[\w.!#\$%+-]+@[\w-]+(?:\.[\w-]+)+/ | |
def simple_whois_email_extractor(domain = 'DISNEY.COM') | |
puts "Getting whois info for #{domain.downcase}" | |
emails = Array.new | |
IO.popen("whois #{domain.downcase}") do |io| | |
string = '' | |
while (line = io.gets) do | |
string += line | |
end |
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
require 'whois' | |
def check_whois_for_emails_and_domain_expiry(domain = 'microsoft.com') | |
puts "Getting whois info for #{domain}" | |
emails = Hash.new | |
registration_details = Hash.new | |
r = Whois.whois(domain) | |
if r.technical_contact.nil? then emails[:technical_contact] = '' else emails[:technical_contact] = r.technical_contact['email'].downcase end |
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
@string = '<p><a href="http://plop.com">plop</a><br /><a mailto:[email protected]>[email protected]</a><br />[email protected]</p>' | |
RE = /[\w.!#\$%+-]+@[\w-]+(?:\.[\w-]+)+/ | |
def email_extract(doc = @string) | |
puts "Attempting to extract emails from a string" | |
emails = Array.new | |
doc.downcase.scan(RE).each do | email | emails.push email end | |
emails.uniq! | |
return emails | |
end | |
emails = email_extract #'<p><a href="http://notplop.com">not plop</a><br /><a mailto:[email protected]>[email protected]</a><br />[email protected]</p>' |