Skip to content

Instantly share code, notes, and snippets.

@julien51
Created April 24, 2009 21:47
Show Gist options
  • Save julien51/101355 to your computer and use it in GitHub Desktop.
Save julien51/101355 to your computer and use it in GitHub Desktop.
require "rubygems"
require "eventmachine"
require "lib/babylon.rb"
proc = Proc.new { |stanza|
puts "+++"
puts stanza.inspect
}
@parser = Babylon::XmppParser.new(proc)
@parser.push("<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 &#x201C;Definitely Out.&#x201D; Expect Announcement Soon.</title>
<summary>Core MySpace Executive Team &#x201C;Definitely Out.&#x201D; 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>
<message>
<body>
Salut mon ami!
</body>
</message>
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]
puts substrings.join("") == string
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