Created
April 27, 2009 04:57
-
-
Save julien51/102339 to your computer and use it in GitHub Desktop.
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 "eventmachine" | |
require "lib/babylon.rb" | |
class AtomEntry | |
# <iq type='set' | |
# from='[email protected]/blogbot' | |
# to='pubsub.shakespeare.lit' | |
# id='publish1'> | |
# <pubsub xmlns='http://jabber.org/protocol/pubsub'> | |
# <publish node='princely_musings'> | |
# <item> | |
# <entry xmlns='http://www.w3.org/2005/Atom'> | |
# <title>Soliloquy</title> | |
# <summary>To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them?</summary> | |
# <link rel='alternate' type='text/html' | |
# href='http://denmark.lit/2003/12/13/atom03'/> | |
# <id>tag:denmark.lit,2003:entry-32397</id> | |
# <published>2003-12-13T18:30:02Z</published> | |
# <updated>2003-12-13T18:30:02Z</updated> | |
# </entry> | |
# </item> | |
# <item> | |
# <entry xmlns='http://www.w3.org/2005/Atom'> | |
# <title>Serendipity</title> | |
# <summary>What can I do after that?</summary> | |
# <link rel='alternate' type='text/html' | |
# href='http://denmark.lit/2003/12/13/atom04'/> | |
# <id>tag:denmark.lit,2003:entry-32398</id> | |
# <published>2003-12-13T19:32:02Z</published> | |
# <updated>2008-11-11T12:04:34Z</updated> | |
# </entry> | |
# </item> | |
# </publish> | |
# </pubsub> | |
# </iq> | |
include SAXMachine | |
element :title | |
element :summary | |
element :published | |
element :id, :as => :unique_id | |
element :link, :value => :href | |
end | |
class Publish < Babylon::Base::Stanza | |
element :iq, :as => :to, :value => :to | |
element :iq, :as => :from, :value => :from | |
element :iq, :as => :iq_id, :value => :id | |
element :publish, :as => :node, :value => :node | |
elements :entry, :as => :entries, :class => AtomEntry | |
end | |
proc = Proc.new { |stanza| | |
p = Publish.new(stanza) | |
} | |
@parser = Babylon::XmppParser.new(proc) | |
@parser.push("<stream:stream>") | |
string = <<-EOXML | |
<iq from="[email protected]/babylon_client_4316" to="firehoser.superfeedr.com" type="set" id="pub-78907528"> | |
<pubsub xmlns="http://jabber.org/protocol/pubsub"> | |
<publish node="http://friendfeed.com/api/feed/user/techcrunch?format=rss"> | |
<item> | |
<entry xmlns="http://www.w3.org/2005/Atom"> | |
<title>Core MySpace Executive Team “Definitely Out.” Expect Announcement Soon.</title> | |
<summary>Core MySpace Executive Team “Definitely Out.” Expect Announcement Soon.</summary> | |
<link rel="alternate" type="text/html" href="http://www.techcrunch.com/2009/04/21/core-myspace-exececutive-team-definitely-out-expect-announcement-soon/"/> | |
<published>2009-04-22T05:29:47Z</published> | |
<id>13036091-3440-aac8-cb63-6658738c63fb</id> | |
</entry> | |
</item> | |
<item> | |
<entry xmlns="http://www.w3.org/2005/Atom"> | |
<title>ClusterShot Aims To Become Another iStockPhoto Rival</title> | |
<summary>ClusterShot Aims To Become Another iStockPhoto Rival</summary> | |
<link rel="alternate" type="text/html" href="http://www.techcrunch.com/2009/04/22/clustershot-aims-to-become-another-istockphoto-rival/"/> | |
<published>2009-04-22T10:45:09Z</published> | |
<id>9d391529-77dc-4f51-d575-7e8d3c0f170c</id> | |
</entry> | |
</item> | |
</publish> | |
</pubsub> | |
</iq> | |
EOXML | |
loop do | |
Babylon.logger.info "MEMORY: #{Integer(`ps -o rss= -p #{Process.pid}`)}" | |
pieces = rand(string.size/30) | |
# So we have to pick 'pieces' number between 0 and string.size | |
indices = [] | |
pieces.times do |i| | |
indices[i] = rand(string.size) | |
end | |
# Now let's sort indices | |
indices.sort! | |
substrings = [] | |
prev_index = 0 | |
indices.each do |index| | |
substrings << string[prev_index, (index-prev_index)] | |
prev_index = index | |
end | |
substrings << string[prev_index, string.size] | |
substrings.each do |sub| | |
@parser.push(sub) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment