Skip to content

Instantly share code, notes, and snippets.

View sporsh's full-sized avatar

Geir Sporsheim sporsh

View GitHub Profile
@sporsh
sporsh / html_parser.rb
Created February 9, 2012 12:54 — forked from jimweirich/html_parser.rb
Vital Ruby Advance Lab 2
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
@sporsh
sporsh / url_fetcher.rb
Created February 9, 2012 10:27 — forked from jimweirich/url_fetcher.rb
Vital Ruby Advanced Lab 1
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
@sporsh
sporsh / read_only_proxy.py
Created February 8, 2012 08:44 — forked from jimweirich/read_only_proxy.rb
Vital Ruby Lab 5
class ReadOnlyProxy(object):
def __init__(self, target):
self._target = target
def __getattribute__(self, name):
target = object.__getattribute__(self, '_target')
return getattr(target, name)
@sporsh
sporsh / tally.rb
Created February 7, 2012 13:55 — forked from jimweirich/presentation.rb
Vital Ruby Lab 4
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)