Skip to content

Instantly share code, notes, and snippets.

View tenderlove's full-sized avatar
©️
 ​[object Object] :trollface:

Aaron Patterson tenderlove

©️
 ​[object Object] :trollface:
View GitHub Profile
require 'nokogiri'
require 'test/unit'
class TestFoo < Test::Unit::TestCase
def setup
@doc = Nokogiri::XML(<<-eoxml)
<SIF_Message>
<SIF_Ack>
<SIF_Header>
<SIF_SourceId>Default Server</SIF_SourceId>
module Nokogiri
module XML
class Builder
def insert_html(html)
Nokogiri::HTML.fragment(html).each do |child|
insert child
end
end
class Net::BufferedIO #:nodoc:
alias :old_rbuf_fill :rbuf_fill
def rbuf_fill
if @io.respond_to?(:read_nonblock)
begin
@rbuf << @io.read_nonblock(65536)
rescue Errno::EWOULDBLOCK
if IO.select([@io], nil, nil, @read_timeout)
@rbuf << @io.read_nonblock(65536)
else
x.report('nokogiri:entity-extract') do
N.times do
doc = Nokogiri::XML(xml_content)
entity = doc.at('//evriThing/entity')
name = facets = properties = nil
href = entity['name']
score = entity['score'].to_f
id = entity['id'].to_i
QRTools::Camera.new(0) do |cam|
loop do
decoder = QRTools::Decoder.decode(cam.capture)
next unless decoder.body
puts decoder.body
end
end
require 'nokogiri'
doc = Nokogiri::XML(<<-eoxml)
<stores>
<store name="store a">
<book>awesome</book>
<book>examples</book>
<book>are</book>
<book>awesome</book>
</store>
require 'nokogiri'
doc = Nokogiri::HTML('<span>浦嶌啓太</span>')
doc.css('span').inner_html # => &#28006;&#23948;&#21843;&#22826;
doc = Nokogiri::HTML('<span>浦嶌啓太</span>', nil, 'UTF-8')
doc.css('span').inner_html # => 浦嶌啓太
require 'nokogiri'
class MyDSL
def initialize &block
@doc = Nokogiri::HTML(<<-eohtml)
<html>
<body>
<a href="whatever">whatevs</a>
<a id='one' href="http://tenderlovemaking.com/">tlm.com</a>
</body>
require 'nokogiri'
doc = Nokogiri::XML(<<-eoxml)
<root>
<car xmlns="http://gm.com/">
<tire>Michelin Model XGV</tire>
</car>
<bicycle xmlns="http://schwinn.com/">
<tire>I'm a bicycle tire!</tire>
</bicycle>
doc = Nokogiri::parse(open(ARGV[0], "r:utf-8").read, nil, 'UTF-8')
doc.search('a').each do |el|
p el
if el['href'] =~ /blah.com/
puts "HERE"
end
end