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 "presentation" | |
| p_file = ARGV[0] || "presentations.txt" | |
| v_file = ARGV[1] || "votes.txt" | |
| def load_presentations(filename) | |
| result = {} | |
| open(filename) { |file| | |
| while entry = file.gets | |
| m_obj = /^(\d+):([^:]+):([^:]+)/.match(entry) |
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 ReadOnlyProxy(object): | |
| def __init__(self, target): | |
| self._target = target | |
| def __getattribute__(self, name): | |
| target = object.__getattribute__(self, '_target') | |
| return getattr(target, 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
| require 'open-uri' | |
| class UrlFetcher | |
| def fetch(url) | |
| begin | |
| open(url) { |stream| stream.read } | |
| rescue SocketError, OpenURI::HTTPError, URI::InvalidURIError, Errno::ENOENT | |
| nil | |
| end | |
| 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 "nokogiri" | |
| require "uri" | |
| class HtmlParser | |
| def parse(source, html_string) | |
| uri = URI.parse(source) | |
| html_doc = Nokogiri::HTML(html_string) | |
| anchors = html_doc.xpath('//a[@href!="" and not(starts-with(@href, "#"))]') | |
| links = anchors.map { |elem| | |
| elem.attribute('href').value |