<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>project-2501.net &#187; programming</title>
	<atom:link href="http://project-2501.net/index.php/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://project-2501.net</link>
	<description>The net is vast and infinite.</description>
	<lastBuildDate>Mon, 14 May 2012 07:10:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PCRE and newlines (in PHP)</title>
		<link>http://project-2501.net/index.php/2012/05/pcre-and-newlines-in-php/</link>
		<comments>http://project-2501.net/index.php/2012/05/pcre-and-newlines-in-php/#comments</comments>
		<pubDate>Mon, 14 May 2012 07:09:47 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=440</guid>
		<description><![CDATA[I just wasted far too much time trying to work out why a regex would work for my example test cases but not with real data. Turns out &#8220;.&#8221;, DOT_ALL, and newlines are more complicated than I realised. My problem essentially came down to not knowing that the imap messages I was working with used [...]]]></description>
			<content:encoded><![CDATA[<p>I just wasted far too much time trying to work out why a regex would work for my example test cases but not with real data.  Turns out &#8220;.&#8221;, DOT_ALL, and newlines are more complicated than I realised.</p>
<p>My problem essentially came down to not knowing that the imap messages I was working with used CRLF and that my OS/shell/applications were silently converting text to LF when I was constructing my test cases.</p>
<p><a href="http://nikic.github.com/"><strong>nikic</strong></a> has a good post covering many details with <A href="http://nikic.github.com/2011/12/10/PCRE-and-newlines.html">PCRE and newlines</a></p>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2012/05/pcre-and-newlines-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roman Numerals</title>
		<link>http://project-2501.net/index.php/2011/08/roman-numerals/</link>
		<comments>http://project-2501.net/index.php/2011/08/roman-numerals/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 10:00:13 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=363</guid>
		<description><![CDATA[From reddit.com/r/programingchallenges: I googled this and I haven&#8217;t found a similar challenge, so I&#8217;d like to pose this question to you all! Let&#8217;s say I give you a range from 1 to 2000. Within this range, find the number that yields the most characters. I asked a friend of mine and he worked out that [...]]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://www.reddit.com/r/programingchallenges/comments/i1m62/challenge_find_the_number_in_a_given_range_that/">reddit.com/r/programingchallenges</a>:</p>
<blockquote><p> I googled this and I haven&#8217;t found a similar challenge, so I&#8217;d like to pose this question to you all!<br />
Let&#8217;s say I give you a range from 1 to 2000. Within this range, find the number that yields the most characters. I asked a friend of mine and he worked out that 1888 has a lot of characters (MDCCCLXXXVIII).</p></blockquote>
<p><Strong>Solution</strong></p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span><br />
<br />
SYMBOLS <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'M'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'CM'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">900</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'D'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">500</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'CD'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">400</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'C'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'XC'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">90</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'L'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">50</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'XL'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">40</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'X'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'IX'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">9</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'V'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'IV'</span><span style="color: #66cc66;">,</span> &nbsp;<span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #483d8b;">'I'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> roman_numeral<span style="color: black;">&#40;</span>number<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; roman_number <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span><span style="color: #dc143c;">symbol</span><span style="color: #66cc66;">,</span> value<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> SYMBOLS:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">while</span> value <span style="color: #66cc66;">&lt;=</span> number:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; roman_number.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">symbol</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; number -<span style="color: #66cc66;">=</span> value<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>roman_number<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
<br />
<br />
start <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
<br />
pairs <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>i<span style="color: #66cc66;">,</span> roman_numeral<span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">2000</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><br />
pairs.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> a<span style="color: #66cc66;">,</span>b: <span style="color: #008000;">cmp</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>b<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Longest roman numeral for numbers 1-2000 = %d -&gt; %s'</span> % &nbsp;\<br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>pairs<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span> pairs<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Took: %.2fsec'</span> % <span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> - start<span style="color: #66cc66;">,</span><span style="color: black;">&#41;</span></div></div>
<p><strong>Output</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Longest roman numeral for numbers 1-2000 = 1888 -&gt; MDCCCLXXXVIII<br />
Took: 0.14sec</div></div>
<p><strong>Notes</strong><br />
Turns out historically there wasn&#8217;t a strict set of rules for Roman numerals, for example IV and IIII are both valid representations of the number 4.  Only recent rules have added limits on the number of repeated characters and what values can be subtracted from other values. <a href="http://en.wikipedia.org/wiki/Roman_numerals#Reading Roman numerals">Reference</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/08/roman-numerals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IP Address Range PHP Class</title>
		<link>http://project-2501.net/index.php/2011/07/ip-address-range-php-class/</link>
		<comments>http://project-2501.net/index.php/2011/07/ip-address-range-php-class/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 12:00:10 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=349</guid>
		<description><![CDATA[I&#8217;m not sure how useful this piece of code really is, but it gave me the chance to write some funky PHP code (have a look at the next() method). Example usage &#60;?php // Single host: foreach&#40;new IpRange&#40;'10.10.10.10'&#41; as $ip&#41; &#123; &#160; &#160; echo $ip . &#34;\n&#34; &#125; // &#62;&#62;&#62; 10.10.10.10 // All hosts on [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure how useful this piece of code really is, but it gave me the chance to write some funky PHP code (have a look at the next() method).</p>
<h3>Example usage</h3>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Single host:</span><br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> IpRange<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'10.10.10.10'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ip</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 10.10.10.10</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">// All hosts on a private network:</span><br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> IpRange<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'192.168.0.1-255'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ip</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 192.168.0.1</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 192.168.0.2</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; ...</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 192.168.0.254</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 192.168.0.255</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">// All normal (not broadcast, or multicast) IP addresses:</span><br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> IpRange<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1-232.0-255.0-255.0-255'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$k</span> =&gt; <span style="color: #006699; font-weight: bold;">$v</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 0 =&gt; 1.0.0.0</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 1 =&gt; 1.0.0.1</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 2 =&gt; 1.0.0.2</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; ...</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 7315795 =&gt; 1.111.161.83</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; 7315796 =&gt; 1.111.161.84</span><br />
<span style="color: #666666; font-style: italic;">// &gt;&gt;&gt; etc</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<h3>Source</h3>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/*<br />
<br />
&nbsp; &nbsp; Copyright (c) 2011, Matthew Davey &lt;matthewd@project-2501.net&gt;<br />
&nbsp; &nbsp; All rights reserved.<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Redistribution and use in source and binary forms, with or without<br />
&nbsp; &nbsp; modification, are permitted provided that the following conditions are met:<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; Redistributions of source code must retain the above copyright notice,<br />
&nbsp; &nbsp; &nbsp; &nbsp; this list of conditions and the following disclaimer.<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; Redistributions in binary form must reproduce the above copyright<br />
&nbsp; &nbsp; &nbsp; &nbsp; notice, this list of conditions and the following disclaimer in the<br />
&nbsp; &nbsp; &nbsp; &nbsp; documentation and/or other materials provided with the distribution.<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;<br />
&nbsp; &nbsp; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br />
&nbsp; &nbsp; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br />
&nbsp; &nbsp; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE<br />
&nbsp; &nbsp; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br />
&nbsp; &nbsp; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br />
&nbsp; &nbsp; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br />
&nbsp; &nbsp; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br />
&nbsp; &nbsp; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br />
&nbsp; &nbsp; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br />
&nbsp; &nbsp; POSSIBILITY OF SUCH DAMAGE.<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/*<br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; IpRange Class<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Given an IP address where each octet can either be a number between 0 and<br />
&nbsp; &nbsp; 255, or a range i.e. 100-200. &nbsp;Return an iterable object that returns all<br />
&nbsp; &nbsp; IP addresses in between.<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Examples<br />
&nbsp; &nbsp; --------<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Single host:<br />
&nbsp; &nbsp; &nbsp; &nbsp; foreach(new IpRange('10.10.10.10') as $ip)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $ip . &quot;\n&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 10.10.10.10<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; All hosts on a private network:<br />
&nbsp; &nbsp; &nbsp; &nbsp; foreach(new IpRange('192.168.0.1-255') as $ip)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $ip . &quot;\n&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 192.168.0.1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 192.168.0.2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 192.168.0.254<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 192.168.0.255<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; All normal (not broadcast, or multicast) IP addresses:<br />
&nbsp; &nbsp; &nbsp; &nbsp; foreach(new IpRange('1-232.0-255.0-255.0-255') as $key =&gt; $value)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo &quot;$key =&gt; $value\n&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 0 =&gt; 1.0.0.0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 1 =&gt; 1.0.0.1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 2 =&gt; 1.0.0.2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; ...<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 7315795 =&gt; 1.111.161.83<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 7315796 =&gt; 1.111.161.84<br />
&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; etc<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; */</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> IpRange implements Iterator<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$count</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Current position, used as the key</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// ranges for each octet, l =&gt; low, h =&gt; high</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$b</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Most significant to least is aaa.bbb.ccc.ddd</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$d</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$ca</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// current value of a</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$cb</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// current value of b</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$cc</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// current value of c</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$cd</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// current value of d</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$isValid</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// flag set when next() is call at end of ranges</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#^(\d+|\d+-\d+)\.(\d+|\d+-\d+)\.(\d+|\d+-\d+)\.(\d+|\d+-\d+)$#'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> InvalidArgumentException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid format. &nbsp;Each octet should either be a number between 0 and 255, or a range &quot;40-120&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Parse each octet and find the low/high values (high === low if there is no range specified)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'d'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$position</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$range</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$range</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$low</span><span style="color: #339933;">,</span> <span style="color: #000088;">$high</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$range</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$low</span><span style="color: #339933;">,</span> <span style="color: #000088;">$high</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$range</span><span style="color: #339933;">,</span> <span style="color: #000088;">$range</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check the IP address is at least mostly valid. &nbsp;We don't need to check for &lt;0 as our regex will reject it first.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$high</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> InvalidArgumentException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Invalid IP address. &nbsp;The octet '<span style="color: #006699; font-weight: bold;">$high</span>' cannot be greater than 255&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// If given a range like 255-0, flip the high/low value over</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$low</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$high</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$high</span><span style="color: #339933;">,</span> <span style="color: #000088;">$low</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$low</span><span style="color: #339933;">,</span> <span style="color: #000088;">$high</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$position</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'l'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$low</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'h'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$high</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">rewind</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$this-&gt;ca}</span>.<span style="color: #006699; font-weight: bold;">{$this-&gt;cb}</span>.<span style="color: #006699; font-weight: bold;">{$this-&gt;cc}</span>.<span style="color: #006699; font-weight: bold;">{$this-&gt;cd}</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">key</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">count</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">rewind</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ca</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'l'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cb</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">b</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'l'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">c</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'l'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cd</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">d</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'l'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> valid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">count</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Least significant to most. &nbsp;Null is our guard.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$position</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check if unable to generate the next IP address</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$position</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check if the value is less than the maximum for this </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// position, if so increment the value and stop. &nbsp;Otherwise set</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// this position to its lowest value, and continue onto the next</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// highest position.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;c<span style="color: #006699; font-weight: bold;">$position</span>&quot;</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$position</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'h'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;c<span style="color: #006699; font-weight: bold;">$position</span>&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;c<span style="color: #006699; font-weight: bold;">$position</span>&quot;</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$position</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'l'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/07/ip-address-range-php-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Smell</title>
		<link>http://project-2501.net/index.php/2011/07/code-smell/</link>
		<comments>http://project-2501.net/index.php/2011/07/code-smell/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 03:26:06 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=319</guid>
		<description><![CDATA[&#8220;In computer programming, code smell is any symptom in the source code of a program that possibly indicates a deeper problem.&#8221; &#8212; Wikipedia I found this piece of code this morning, I think it counts as something gone terribly, terribly wrong: return displayItemDetails(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode, 14059111); (The code was in-line JavaScript, inserted into a onclick handler, generated [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>&#8220;In computer programming, code smell is any symptom in the source code of a program that possibly indicates a deeper problem.&#8221; &#8212; <a href="http://en.wikipedia.org/wiki/Code_smell">Wikipedia</a></p></blockquote>
<p>I found this piece of code this morning, I think it counts as something gone terribly, terribly wrong:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">return displayItemDetails(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode, 14059111);</div></div>
<p><em>(The code was in-line JavaScript, inserted into a onclick handler, generated in PHP)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/07/code-smell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sources of Holy Power Generation</title>
		<link>http://project-2501.net/index.php/2011/04/sources-of-holy-power-generation/</link>
		<comments>http://project-2501.net/index.php/2011/04/sources-of-holy-power-generation/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 08:32:17 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[games]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=266</guid>
		<description><![CDATA[Note: The information present in this post is a couple of months out of date. I&#8217;ve not had the time to re-update WoL data and create new graphs, but thought it might be interesting share the data/code anyway When choosing a Holy Paladin spec for 10 mans I was never completely sure about benefits of [...]]]></description>
			<content:encoded><![CDATA[<p><em>Note: The information present in this post is a couple of months out of date.  I&#8217;ve not had the time to re-update WoL data and create new graphs, but thought it might be interesting share the data/code anyway</em></p>
<p>When choosing a Holy Paladin spec for 10 mans I was never completely sure about benefits of Tower of Radiance or Blessed Life.  ToR seems like a safe choice, though the frequency that you DL/FoL your beacon seemed low.  Blessed Life on the other hand was obviously a PvP talent, but it would generate free HP from some raid damage.</p>
<p>I set out to scrape the top 200 Paladins for each 10-N boss fights from <a href="http://www.­worldoflogs.­com">World of Logs</a> and record their source of HP generation.  I created two graphs; one that looks at all 200 parses in general, and a second that only counts when the ability is present.  e.g.  Only 10 or so Paladins used CS on Cho&#8217;gall, and they generated very little HP overall, but if you just look at lose 10 parses, the average is 8.  This is used as a crude way to see when certain talents are taken.</p>
<h3>Overall</h3>
<p><a href="http://project-2501.net/gallery/wow/holy-power-gen-overall.png"><img src="http://project-2501.net/gallery/.thumbs/gallery_wow_holy-power-gen-overall.png.jpeg"></a></p>
<h3>Only when abilities are present</h3>
<p><a href="http://project-2501.net/gallery/wow/holy-power-gen-only-when-present.png"><img src="http://project-2501.net/gallery/.thumbs/gallery_wow_holy-power-gen-only-when-present.png.jpeg"></a></p>
<p>I&#8217;ve included the python code used to generate the data for these graphs below.  My general disclaimer applies (i.e. be afraid)</p>
<h3>grab-details.py</h3>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib2</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span><br />
<br />
pages <span style="color: #66cc66;">=</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'magmaw-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Magmaw/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Magmaw/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Magmaw/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Magmaw/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Magmaw/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #483d8b;">'omnitron-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Omnitron_Defense_System/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Omnitron_Defense_System/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Omnitron_Defense_System/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Omnitron_Defense_System/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Omnitron_Defense_System/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #483d8b;">'chimaeron-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Chimaeron/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Chimaeron/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Chimaeron/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Chimaeron/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Chimaeron/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #483d8b;">'atramedes-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Atramedes/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Atramedes/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Atramedes/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Atramedes/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Atramedes/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #483d8b;">'maloriak-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Maloriak/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Maloriak/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Maloriak/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Maloriak/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Maloriak/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #483d8b;">'nefarian-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Nefarian/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Nefarian/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Nefarian/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Nefarian/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Blackwing_Descent/Nefarian/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #483d8b;">'halfus-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Halfus_Wyrmbreaker/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Halfus_Wyrmbreaker/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Halfus_Wyrmbreaker/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Halfus_Wyrmbreaker/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Halfus_Wyrmbreaker/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #483d8b;">'valiona-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Valiona_&amp;_Theralion/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Valiona_&amp;_Theralion/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Valiona_&amp;_Theralion/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Valiona_&amp;_Theralion/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Valiona_&amp;_Theralion/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #483d8b;">'twilight-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Twilight_Ascendant_Council/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Twilight_Ascendant_Council/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Twilight_Ascendant_Council/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Twilight_Ascendant_Council/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Twilight_Ascendant_Council/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
<br />
&nbsp; &nbsp; <span style="color: #483d8b;">'chogall-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Cho<span style="color: #000099; font-weight: bold;">\'</span>gall/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Cho<span style="color: #000099; font-weight: bold;">\'</span>gall/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Cho<span style="color: #000099; font-weight: bold;">\'</span>gall/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Cho<span style="color: #000099; font-weight: bold;">\'</span>gall/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Bastion_of_Twilight/Cho<span style="color: #000099; font-weight: bold;">\'</span>gall/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #483d8b;">'conclave-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Throne_of_the_4_Winds/Conclave_of_Wind/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Throne_of_the_4_Winds/Conclave_of_Wind/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Throne_of_the_4_Winds/Conclave_of_Wind/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Throne_of_the_4_Winds/Conclave_of_Wind/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Throne_of_the_4_Winds/Conclave_of_Wind/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #483d8b;">'alakir-10-n'</span>: <span style="color: black;">&#91;</span><span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Throne_of_the_4_Winds/Al<span style="color: #000099; font-weight: bold;">\'</span>Akir/10N/Holy_Paladin/'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Throne_of_the_4_Winds/Al<span style="color: #000099; font-weight: bold;">\'</span>Akir/10N/Holy_Paladin/?page=2'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Throne_of_the_4_Winds/Al<span style="color: #000099; font-weight: bold;">\'</span>Akir/10N/Holy_Paladin/?page=3'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Throne_of_the_4_Winds/Al<span style="color: #000099; font-weight: bold;">\'</span>Akir/10N/Holy_Paladin/?page=4'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'http://worldoflogs.com/rankings/players/Throne_of_the_4_Winds/Al<span style="color: #000099; font-weight: bold;">\'</span>Akir/10N/Holy_Paladin/?page=5'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <br />
<span style="color: black;">&#125;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> extract_player_pages<span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; regex &nbsp; <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">&quot;&lt;td&gt;&lt;a href='(/reports/[^']+)'&gt;([^&lt;]+)&lt;/a&gt;&lt;/td&gt;&quot;</span><br />
&nbsp; &nbsp; html &nbsp; &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; matches <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">findall</span><span style="color: black;">&#40;</span>regex<span style="color: #66cc66;">,</span> html<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> matches<br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> extract_player_details<span style="color: black;">&#40;</span>report_url<span style="color: #66cc66;">,</span> player_name<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># First load the healing summary page</span><br />
&nbsp; &nbsp; url &nbsp; <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'http://worldoflogs.com'</span> + report_url<br />
&nbsp; &nbsp; html &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; match <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;a href='(/reports/[^']+)'&gt;&quot;</span> + player_name + <span style="color: #483d8b;">&quot;&lt;/a&gt;&quot;</span><span style="color: #66cc66;">,</span> html<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># now load the players healing detail page</span><br />
&nbsp; &nbsp; url &nbsp; <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'http://worldoflogs.com'</span> + match.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; html &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> html<br />
<br />
<br />
<span style="color: #ff7700;font-weight:bold;">for</span> boss <span style="color: #ff7700;font-weight:bold;">in</span> pages:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> boss<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> url <span style="color: #ff7700;font-weight:bold;">in</span> pages<span style="color: black;">&#91;</span>boss<span style="color: black;">&#93;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; reports <span style="color: #66cc66;">=</span> extract_player_pages<span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> report_details <span style="color: #ff7700;font-weight:bold;">in</span> reports:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report_url &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">=</span> report_details<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report_player_name <span style="color: #66cc66;">=</span> report_details<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Extracting'</span><span style="color: #66cc66;">,</span> report_player_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; html <span style="color: #66cc66;">=</span> extract_player_details<span style="color: black;">&#40;</span>report_url<span style="color: #66cc66;">,</span> report_player_name<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f &nbsp; &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'data/'</span> + boss + <span style="color: #483d8b;">'/'</span> + report_player_name<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'w+'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: black;">write</span><span style="color: black;">&#40;</span>html<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Done'</span></div></div>
<h3>generate-report.py</h3>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">glob</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Spell IDs</span><br />
HOLY_SHOCK &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">20473</span><br />
ETERNAL_GLORY &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #ff4500;">88676</span><br />
TOWER_OF_RADIANCE &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #ff4500;">88852</span><br />
BLESSED_LIFE &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">89023</span><br />
PURSUIT_OF_JUSTICE <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">89024</span><br />
CRUSADER_STRIKE &nbsp; &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #ff4500;">35395</span><br />
<br />
bosses <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'alakir-10-n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'atramedes-10-n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'chimaeron-10-n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'chogall-10-n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'conclave-10-n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'halfus-10-n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'magmaw-10-n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'maloriak-10-n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'nefarian-10-n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'omnitron-10-n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'twilight-10-n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'valiona-10-n'</span><span style="color: #66cc66;">,</span><br />
<span style="color: black;">&#93;</span><br />
<br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> extract_holy_power<span style="color: black;">&#40;</span>html<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; regex &nbsp; <span style="color: #66cc66;">=</span> r<span style="color: #483d8b;">&quot;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td class='name'&gt;&lt;a href='/reports/[^']+' rel='spell=(<span style="color: #000099; font-weight: bold;">\d</span>+)' class='spell'&gt;&lt;span [^&gt;]+&gt;([^&lt;]+)&lt;/span&gt;&lt;/a&gt;<span style="color: #000099; font-weight: bold;">\S</span>+<span style="color: #000099; font-weight: bold;">\n</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;(<span style="color: #000099; font-weight: bold;">\d</span>+) holy power&lt;/td&gt;&quot;</span><br />
&nbsp; &nbsp; matches <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">findall</span><span style="color: black;">&#40;</span>regex<span style="color: #66cc66;">,</span> html<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; results <span style="color: #66cc66;">=</span> <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> match <span style="color: #ff7700;font-weight:bold;">in</span> matches:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span>spell_id<span style="color: #66cc66;">,</span> spell_name<span style="color: #66cc66;">,</span> count<span style="color: black;">&#41;</span> <span style="color: #66cc66;">=</span> match<br />
&nbsp; &nbsp; &nbsp; &nbsp; results<span style="color: black;">&#91;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>spell_id<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>count<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> results<br />
<br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> generate_holy_power_summary<span style="color: black;">&#40;</span>boss<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; summary <span style="color: #66cc66;">=</span> <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; files <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">glob</span>.<span style="color: #dc143c;">glob</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'data/'</span> + boss + <span style="color: #483d8b;">'/*'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: #008000;">file</span> <span style="color: #ff7700;font-weight:bold;">in</span> files:<br />
&nbsp; &nbsp; &nbsp; &nbsp; html <span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; results <span style="color: #66cc66;">=</span> extract_holy_power<span style="color: black;">&#40;</span>html<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> spell_id <span style="color: #ff7700;font-weight:bold;">in</span> results:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; count <span style="color: #66cc66;">=</span> results<span style="color: black;">&#91;</span>spell_id<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> summary.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span>spell_id<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; summary<span style="color: black;">&#91;</span>spell_id<span style="color: black;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; summary<span style="color: black;">&#91;</span>spell_id<span style="color: black;">&#93;</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>count<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> summary<br />
<br />
<br />
report_on <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #483d8b;">'spell_name'</span>: <span style="color: #483d8b;">'HOLY_SHOCK'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'spell_id'</span>: HOLY_SHOCK<span style="color: black;">&#125;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #483d8b;">'spell_name'</span>: <span style="color: #483d8b;">'ETERNAL_GLORY'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'spell_id'</span>: ETERNAL_GLORY<span style="color: black;">&#125;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #483d8b;">'spell_name'</span>: <span style="color: #483d8b;">'TOWER_OF_RADIANCE'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'spell_id'</span>: TOWER_OF_RADIANCE<span style="color: black;">&#125;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #483d8b;">'spell_name'</span>: <span style="color: #483d8b;">'BLESSED_LIFE'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'spell_id'</span>: BLESSED_LIFE<span style="color: black;">&#125;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #483d8b;">'spell_name'</span>: <span style="color: #483d8b;">'PURSUIT_OF_JUSTICE'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'spell_id'</span>: PURSUIT_OF_JUSTICE<span style="color: black;">&#125;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #483d8b;">'spell_name'</span>: <span style="color: #483d8b;">'CRUSADER_STRIKE'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'spell_id'</span>: CRUSADER_STRIKE<span style="color: black;">&#125;</span><span style="color: #66cc66;">,</span><br />
<span style="color: black;">&#93;</span><br />
<br />
<br />
<span style="color: #ff7700;font-weight:bold;">for</span> boss <span style="color: #ff7700;font-weight:bold;">in</span> bosses:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> boss<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; summary <span style="color: #66cc66;">=</span> generate_holy_power_summary<span style="color: black;">&#40;</span>boss<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> summary.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span>HOLY_SHOCK<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Skipping, no data'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">continue</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; total_count <span style="color: #66cc66;">=</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>summary<span style="color: black;">&#91;</span>HOLY_SHOCK<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Total reports'</span><span style="color: #66cc66;">,</span> total_count<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> total_count <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">0</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">continue</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> report_details <span style="color: #ff7700;font-weight:bold;">in</span> report_on:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> summary.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span>report_details<span style="color: black;">&#91;</span><span style="color: #483d8b;">'spell_id'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> report_details<span style="color: black;">&#91;</span><span style="color: #483d8b;">'spell_name'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">continue</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; spell_count &nbsp; <span style="color: #66cc66;">=</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>summary<span style="color: black;">&#91;</span>report_details<span style="color: black;">&#91;</span><span style="color: #483d8b;">'spell_id'</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; total_average <span style="color: #66cc66;">=</span> <span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>summary<span style="color: black;">&#91;</span>report_details<span style="color: black;">&#91;</span><span style="color: #483d8b;">'spell_id'</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> / total_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; spell_average <span style="color: #66cc66;">=</span> <span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>summary<span style="color: black;">&#91;</span>report_details<span style="color: black;">&#91;</span><span style="color: #483d8b;">'spell_id'</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> / spell_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> report_details<span style="color: black;">&#91;</span><span style="color: #483d8b;">'spell_name'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span> total_average</div></div>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/04/sources-of-holy-power-generation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Text Twist Bot</title>
		<link>http://project-2501.net/index.php/2011/03/text-twist-bot/</link>
		<comments>http://project-2501.net/index.php/2011/03/text-twist-bot/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 06:29:28 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[games]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=254</guid>
		<description><![CDATA[Yesterday I watched someone play a bit of the browser based game Text Twist. Upon trying myself I found that I was awful, so I did what any programmer would do; cheated. Results of a few hours hacking: Features: Scan for game area and crash and burn if it&#8217;s not detected (Crudely) detect what letters [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I watched <a href="http://day9.tv">someone</a> play a bit of the browser based game <a href="http://games.yahoo.com/game/text-twist">Text Twist</a>.  Upon trying myself I found that I was awful, so I did what any programmer would do;  cheated.</p>
<p>Results of a few hours hacking:<br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/E3HANgwLPf0?hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/E3HANgwLPf0?hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<h3>Features:</h3>
<ul>
<li>Scan for game area and crash and burn if it&#8217;s not detected</li>
<li>(Crudely) detect what letters are shown</li>
<li>Find all 3, 4, 5 and 6 letter combinations, and then throw them against a basic word list + simple anagram lookup table</li>
<li>Send key presses to the window to (try and) solve all possible words (and overwrite any work you were doing when the window loses focus)</li>
<li>Reliably gets all but one or two words for each puzzle, leaving you plenty of time to go crazy trying to finish it </li>
</ul>
<p>Horrible source for the curious  (it should at least help anyone wondering how to send key presses, or capture the current screen in python)</p>
<h3>TextTwistBot.py</h3>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;"># Text Twist Bot</span><br />
<span style="color: #808080; font-style: italic;"># http://games.yahoo.com/game/text-twist</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">import</span> win32com.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">as</span> comclt<br />
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">time</span> <span style="color: #ff7700;font-weight:bold;">import</span> sleep<br />
<br />
<span style="color: #ff7700;font-weight:bold;">from</span> PIL <span style="color: #ff7700;font-weight:bold;">import</span> ImageGrab<br />
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">itertools</span> <span style="color: #ff7700;font-weight:bold;">import</span> combinations<br />
<br />
<span style="color: #ff7700;font-weight:bold;">from</span> Board <span style="color: #ff7700;font-weight:bold;">import</span> Board<br />
<span style="color: #ff7700;font-weight:bold;">from</span> Pixels <span style="color: #ff7700;font-weight:bold;">import</span> Pixels<br />
<span style="color: #ff7700;font-weight:bold;">from</span> Anagrams <span style="color: #ff7700;font-weight:bold;">import</span> Anagrams<br />
<br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> sorted_unique_character_groups<span style="color: black;">&#40;</span>letters<span style="color: #66cc66;">,</span> length<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; c <span style="color: #66cc66;">=</span> <span style="color: #008000;">list</span><span style="color: black;">&#40;</span>combinations<span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>letters<span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> length<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; c <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>e<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> e <span style="color: #ff7700;font-weight:bold;">in</span> c<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; c <span style="color: #66cc66;">=</span> <span style="color: #008000;">list</span><span style="color: black;">&#40;</span><span style="color: #008000;">set</span><span style="color: black;">&#40;</span>c<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; c.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> c<br />
<br />
<br />
anagrams <span style="color: #66cc66;">=</span> Anagrams<span style="color: black;">&#40;</span><span style="color: #483d8b;">'ispell-enwl-3.1.20/english.all'</span><span style="color: black;">&#41;</span><br />
pixels &nbsp; <span style="color: #66cc66;">=</span> Pixels<span style="color: black;">&#40;</span>ImageGrab.<span style="color: black;">grab</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
board &nbsp; &nbsp;<span style="color: #66cc66;">=</span> Board<span style="color: black;">&#40;</span>pixels<span style="color: black;">&#41;</span><br />
letters &nbsp;<span style="color: #66cc66;">=</span> board.<span style="color: black;">get_letters</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># letters = ['d', 'e', 'l', 'a', 'p', 'd']</span><br />
possible_answers <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
lengths <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: #66cc66;">,</span><span style="color: #ff4500;">4</span><span style="color: #66cc66;">,</span><span style="color: #ff4500;">5</span><span style="color: #66cc66;">,</span><span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">for</span> length <span style="color: #ff7700;font-weight:bold;">in</span> lengths:<br />
&nbsp; &nbsp; words <span style="color: #66cc66;">=</span> sorted_unique_character_groups<span style="color: black;">&#40;</span>letters<span style="color: #66cc66;">,</span> length<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> word <span style="color: #ff7700;font-weight:bold;">in</span> words:<br />
&nbsp; &nbsp; &nbsp; &nbsp; possible_answers.<span style="color: black;">extend</span><span style="color: black;">&#40;</span>anagrams.<span style="color: black;">find</span><span style="color: black;">&#40;</span>word<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
<br />
possible_answers <span style="color: #66cc66;">=</span> <span style="color: #008000;">list</span><span style="color: black;">&#40;</span><span style="color: #008000;">set</span><span style="color: black;">&#40;</span>possible_answers<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> possible_answers<br />
<br />
<br />
wsh <span style="color: #66cc66;">=</span> comclt.<span style="color: black;">Dispatch</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;WScript.Shell&quot;</span><span style="color: black;">&#41;</span><br />
wsh.<span style="color: black;">AppActivate</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Windows Internet Explorer&quot;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">for</span> word <span style="color: #ff7700;font-weight:bold;">in</span> possible_answers:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> letter <span style="color: #ff7700;font-weight:bold;">in</span> word:<br />
&nbsp; &nbsp; &nbsp; &nbsp; wsh.<span style="color: black;">SendKeys</span><span style="color: black;">&#40;</span>letter<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sleep<span style="color: black;">&#40;</span><span style="color: #ff4500;">0.05</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; wsh.<span style="color: black;">SendKeys</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Done'</span></div></div>
<h3>Pixels.py</h3>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">class</span> Pixels:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> img<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">img</span> <span style="color: #66cc66;">=</span> img<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">data</span> <span style="color: #66cc66;">=</span> <span style="color: #008000;">list</span><span style="color: black;">&#40;</span>img.<span style="color: black;">getdata</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">width</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">self</span>.<span style="color: black;">height</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">=</span> img.<span style="color: black;">size</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> at<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> x<span style="color: #66cc66;">,</span> y<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; offset <span style="color: #66cc66;">=</span> <span style="color: black;">&#40;</span>y * <span style="color: #008000;">self</span>.<span style="color: black;">width</span><span style="color: black;">&#41;</span> + x<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">data</span><span style="color: black;">&#91;</span>offset<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> grab_area<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> x1<span style="color: #66cc66;">,</span> y1<span style="color: #66cc66;">,</span> x2<span style="color: #66cc66;">,</span> y2<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; raw <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> y <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>y1<span style="color: #66cc66;">,</span> y2<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>x1<span style="color: #66cc66;">,</span> x2<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raw.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">at</span><span style="color: black;">&#40;</span>x<span style="color: #66cc66;">,</span> y<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> raw</div></div>
<h3>Anagrams.py</h3>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">class</span> Anagrams:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> word_list<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>._load_word_list<span style="color: black;">&#40;</span>word_list<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> _load_word_list<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> filename<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Loading word list...'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; lines <span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; words <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span>line.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">lower</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> lines<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">lookup</span> <span style="color: #66cc66;">=</span> <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> word <span style="color: #ff7700;font-weight:bold;">in</span> words:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key <span style="color: #66cc66;">=</span> <span style="color: #008000;">self</span>._sort_letters<span style="color: black;">&#40;</span>word<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> key <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">lookup</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">lookup</span><span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> word <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">lookup</span><span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">lookup</span><span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>word<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Done'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> _sort_letters<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> word<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; letters <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span>l <span style="color: #ff7700;font-weight:bold;">for</span> l <span style="color: #ff7700;font-weight:bold;">in</span> word<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; letters.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>letters<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> find<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> word<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; key <span style="color: #66cc66;">=</span> <span style="color: #008000;">self</span>._sort_letters<span style="color: black;">&#40;</span>word<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> key <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">lookup</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; results <span style="color: #66cc66;">=</span> <span style="color: #008000;">self</span>.<span style="color: black;">lookup</span><span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">#if word in results:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># &nbsp; &nbsp;results.remove(word)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> results</div></div>
<h3>Board.py (be afraid)</h3>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">class</span> Board:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> pixels<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Color of the outside border, used to find the edges of the game</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">border_green</span> <span style="color: #66cc66;">=</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">204</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">255</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Bounding boxes for each letter (including the circle and background)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Each letter is 45x45</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># I've chopped off 8pixels from each side to remove any background</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">letter_coords</span> <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">161</span>+<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">161</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">215</span>+<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">215</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">269</span>+<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">269</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">323</span>+<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">323</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">377</span>+<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">377</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">431</span>+<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">431</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">178</span>+<span style="color: #ff4500;">45</span>-<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Pixel data for each letter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">letter_data</span> <span style="color: #66cc66;">=</span> <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Snipped 300Kb of data</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Yikes, didn't realize it was so big</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># If anyone actually cares for the letter data, you </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># can reconstruct it from error messages.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Format is:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># 'a': [(r, g, b), (r, g, b)....],</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># 'b': [(r, g, b), (r, g, b)....],</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">pixels</span> <span style="color: #66cc66;">=</span> pixels<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>._get_edges<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> _get_edges<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; horz <span style="color: #66cc66;">=</span> <span style="color: #008000;">self</span>._find_pixels<span style="color: black;">&#40;</span><span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">self</span>.<span style="color: black;">pixels</span>.<span style="color: black;">width</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp;<span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">self</span>.<span style="color: black;">pixels</span>.<span style="color: black;">height</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">self</span>.<span style="color: black;">border_green</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; vert <span style="color: #66cc66;">=</span> <span style="color: #008000;">self</span>._find_pixels<span style="color: black;">&#40;</span><span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">self</span>.<span style="color: black;">pixels</span>.<span style="color: black;">width</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">self</span>.<span style="color: black;">pixels</span>.<span style="color: black;">height</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp;<span style="color: #008000;">self</span>.<span style="color: black;">border_green</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; left &nbsp; <span style="color: #66cc66;">=</span> <span style="color: #008000;">min</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>x <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span>x<span style="color: #66cc66;">,</span>y<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> horz<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; right &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #008000;">max</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>x <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span>x<span style="color: #66cc66;">,</span>y<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> horz<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; top &nbsp; &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #008000;">min</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>y <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span>x<span style="color: #66cc66;">,</span>y<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> vert<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; bottom <span style="color: #66cc66;">=</span> <span style="color: #008000;">max</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>y <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span>x<span style="color: #66cc66;">,</span>y<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> vert<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">left</span> &nbsp; <span style="color: #66cc66;">=</span> left<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">right</span> &nbsp;<span style="color: #66cc66;">=</span> right<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">top</span> &nbsp; &nbsp;<span style="color: #66cc66;">=</span> top<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">bottom</span> <span style="color: #66cc66;">=</span> bottom<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> _find_pixels<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> x_range<span style="color: #66cc66;">,</span> y_range<span style="color: #66cc66;">,</span> color<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; edges <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> y <span style="color: #ff7700;font-weight:bold;">in</span> y_range:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> x_range:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">pixels</span>.<span style="color: black;">at</span><span style="color: black;">&#40;</span>x<span style="color: #66cc66;">,</span> y<span style="color: black;">&#41;</span> <span style="color: #66cc66;">==</span> color:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edges.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>x<span style="color: #66cc66;">,</span> y<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> edges<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> get_letters<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; letters <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> coords <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">letter_coords</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x1 <span style="color: #66cc66;">=</span> coords<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> + <span style="color: #008000;">self</span>.<span style="color: black;">left</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x2 <span style="color: #66cc66;">=</span> coords<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> + <span style="color: #008000;">self</span>.<span style="color: black;">left</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y1 <span style="color: #66cc66;">=</span> coords<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + <span style="color: #008000;">self</span>.<span style="color: black;">top</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y2 <span style="color: #66cc66;">=</span> coords<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + <span style="color: #008000;">self</span>.<span style="color: black;">top</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data <span style="color: #66cc66;">=</span> <span style="color: #008000;">self</span>.<span style="color: black;">pixels</span>.<span style="color: black;">grab_area</span><span style="color: black;">&#40;</span>x1<span style="color: #66cc66;">,</span> y1<span style="color: #66cc66;">,</span> x2<span style="color: #66cc66;">,</span> y2<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># print 'Got data for pos', coords</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; found <span style="color: #66cc66;">=</span> <span style="color: #008000;">False</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> key <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">letter_data</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">letter_data</span><span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span> <span style="color: #66cc66;">==</span> data:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; letters.<span style="color: black;">append</span><span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; found <span style="color: #66cc66;">=</span> <span style="color: #008000;">True</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">break</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> found <span style="color: #66cc66;">==</span> <span style="color: #008000;">False</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\'</span>?<span style="color: #000099; font-weight: bold;">\'</span>:'</span><span style="color: #66cc66;">,</span> data<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">','</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> letters</div></div>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2011/03/text-twist-bot/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Intial Divine Guardian Tests</title>
		<link>http://project-2501.net/index.php/2010/02/intial-divine-guardian-tests/</link>
		<comments>http://project-2501.net/index.php/2010/02/intial-divine-guardian-tests/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 08:51:50 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[games]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=233</guid>
		<description><![CDATA[I been wanting to look in the effectiveness of the 20% raid wall granted by Divine Guardian (4th tier talent in a Paladin&#8217;s protection tree). To do this I wrote a very simple Python program to read the combat log, detect with DG goes up and then record all the damage that was taken while [...]]]></description>
			<content:encoded><![CDATA[<p>I been wanting to look in the effectiveness of the 20% raid wall granted by Divine Guardian (4th tier talent in a Paladin&#8217;s protection tree).  To do this I wrote a very simple Python program to read the combat log, detect with DG goes up and then record all the damage that was taken while it was present on a unit, and work out how much was mitigated.  Of course, as the script was hacked up, it has all sorts of limitations:</p>
<ul>
<li>Ignores Divine Sacrifice</li>
<li>Ignores any other mitigation effects (Talents / Sanc / Inspiration / etc)</li>
<li>Ignores overkills</li>
<li>Undefined behavior when used by two Paladins</li>
</ul>
<p>Below is the results for a two nights in ICC 25, while I&#8217;m sure it&#8217;s not 100% it should be a reasonable ballpark figure.</p>
<p><!-- Horrible CCS hacks to add padding back to my poor tables --></p>
<style>
.mytable_233 td, .mytable_233 th
{
padding: 0.3em;
}
</style>
<table class='mytable_233' cellspacing="0" cellpadding="2" cols="1" border="1" style="border: 1px solid #ccc; border-collapse: collapse;">
<tr>
<th>Fight</th>
<th>Damage Mitigated via DG</th>
</tr>
<tr>
<td>Gaseous Blight</td>
<td>37057</td>
</tr>
<tr>
<td>Gaseous Blight</td>
<td>32664</td>
</tr>
<tr>
<td>Ooze Explosion/Melee</td>
<td>39923</td>
</tr>
<tr>
<td>Trash before Blood Queen</td>
<td>21145</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>42212</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>54410</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>17679</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>29315</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>32029</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>51281</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>34494</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>14201</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>41417</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>18817</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>35641</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>49571</td>
</tr>
<tr>
<td>Blood Queen (Fear/Bloodbolt)</td>
<td>26427</td>
</tr>
<tr>
<td>Average</td>
<td>34017</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2010/02/intial-divine-guardian-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript; sending me insane</title>
		<link>http://project-2501.net/index.php/2010/01/javascript-sending-me-insane/</link>
		<comments>http://project-2501.net/index.php/2010/01/javascript-sending-me-insane/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 03:55:38 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=228</guid>
		<description><![CDATA[&#62;&#62;&#62; &#91;&#93; &#91;&#93; &#62;&#62;&#62; &#91;&#93; == true false &#62;&#62;&#62; &#91;&#93; == false true &#62;&#62;&#62; &#91;&#93; == &#91;&#93; false &#62;&#62;&#62; false == false true]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><br />
<span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">true</span><br />
<span style="color: #003366; font-weight: bold;">false</span><br />
<span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><br />
<span style="color: #003366; font-weight: bold;">true</span><br />
<span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><br />
<span style="color: #003366; font-weight: bold;">false</span><br />
<span style="color: #339933;">&gt;&gt;&gt;</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><br />
<span style="color: #003366; font-weight: bold;">true</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2010/01/javascript-sending-me-insane/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>total mysql rows</title>
		<link>http://project-2501.net/index.php/2009/09/total-mysql-rows/</link>
		<comments>http://project-2501.net/index.php/2009/09/total-mysql-rows/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 01:50:04 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=213</guid>
		<description><![CDATA[Turns out our Mysql server at work is a little bigger than I thought: Databases 75 Tables &#160; &#160;1,549 Rows &#160; &#160; &#160;1,018,085,348 However over the last couple of months, we&#8217;ve only averaged 130 queries/second Hacked up PHP to gather stats: class MysqlCounter &#123; &#160; &#160; public function __construct&#40;$host, $username, $password&#41; &#160; &#160; &#123; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Turns out our Mysql server at work is a little bigger than I thought:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Databases 75<br />
Tables &nbsp; &nbsp;1,549<br />
Rows &nbsp; &nbsp; &nbsp;1,018,085,348</div></div>
<p>However over the last couple of months, we&#8217;ve only averaged 130 queries/second</p>
<p><strong>Hacked up PHP to gather stats:</strong></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> MysqlCounter<br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conn</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conn</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unable to connect to Mysql server: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_databases</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_tables</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_rows</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> query<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unable to run query: <span style="color: #006699; font-weight: bold;">$sql</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conn</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$rows</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$rows</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$rows</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> gather_stats<span style="color: #009900;">&#40;</span><span style="color: #000088;">$callback</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SHOW DATABASES&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row_database</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_databases</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;USE `<span style="color: #006699; font-weight: bold;">{$row_database['Database']}</span>`&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SHOW TABLE STATUS&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row_table</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_tables</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_rows</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$row_table</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Rows'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$callback</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row_database</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Database'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row_table</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row_table</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Rows'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">call_user_func_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$callback</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> default_callback<span style="color: #009900;">&#40;</span><span style="color: #000088;">$database</span><span style="color: #339933;">,</span> <span style="color: #000088;">$table</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rows</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%s</span> <span style="color: #009933; font-weight: bold;">%s</span> <span style="color: #009933; font-weight: bold;">%d</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$database</span><span style="color: #339933;">,</span> <span style="color: #000088;">$table</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rows</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000088;">$counter</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MysqlCounter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'hostname'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$counter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">gather_stats</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MysqlCounter'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'default_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Databases <span style="color: #006699; font-weight: bold;">{$counter-&gt;num_databases}</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Tables &nbsp; &nbsp;<span style="color: #006699; font-weight: bold;">{$counter-&gt;num_tables}</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Rows &nbsp; &nbsp; &nbsp;<span style="color: #006699; font-weight: bold;">{$counter-&gt;num_rows}</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2009/09/total-mysql-rows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WoW Combat Log Splitter</title>
		<link>http://project-2501.net/index.php/2009/09/wow-combat-log-splitter/</link>
		<comments>http://project-2501.net/index.php/2009/09/wow-combat-log-splitter/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 07:55:11 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[games]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://project-2501.net/?p=199</guid>
		<description><![CDATA[Something quick I whipped up last night, after noticing that after my log file was > 4GB the WorldOfLogs parser will no longer do real time logging. Edit: Turns out that the WoW client itself stopped logging, even though the log file was a little over expected limit (4,334,806,196 bytes) Note: The code is just [...]]]></description>
			<content:encoded><![CDATA[<p>Something quick I whipped up last night, after noticing that after my log file was > 4GB the <a href="http://www.worldoflogs.com/">WorldOfLogs</a> parser will no longer do real time logging.</p>
<p><strong>Edit:</strong> Turns out that the WoW client itself stopped logging, even though the log file was a little over expected limit (4,334,806,196 bytes)</p>
<p><em>Note: The code is just a one off script; things are hard coded, and it&#8217;s pretty slow (100MB a minute)</em></p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span><br />
<br />
GAP_SIZE_IN_SECONDS <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">60</span> * <span style="color: #ff4500;">60</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">class</span> CombatLog:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> filename<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">filename</span> <span style="color: #66cc66;">=</span> filename<br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> process<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; last_timestamp <span style="color: #66cc66;">=</span> <span style="color: #008000;">None</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; line_count <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; split_log <span style="color: #66cc66;">=</span> <span style="color: #008000;">None</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">filename</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line_count +<span style="color: #66cc66;">=</span> <span style="color: #ff4500;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timestamp <span style="color: #66cc66;">=</span> <span style="color: #008000;">self</span>.<span style="color: black;">parse_timestamp</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> timestamp <span style="color: #66cc66;">==</span> <span style="color: #008000;">None</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Unparsable data on line %d&quot;</span> % <span style="color: black;">&#40;</span>line_count<span style="color: #66cc66;">,</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">continue</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># To handle the first line</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> last_timestamp <span style="color: #66cc66;">==</span> <span style="color: #008000;">None</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last_timestamp <span style="color: #66cc66;">=</span> timestamp<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; split_log <span style="color: #66cc66;">=</span> Appender<span style="color: black;">&#40;</span>timestamp<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Starting new file&quot;</span><span style="color: #66cc66;">,</span> split_log.<span style="color: black;">filename</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; difference <span style="color: #66cc66;">=</span> timestamp - last_timestamp<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> difference.<span style="color: black;">seconds</span> <span style="color: #66cc66;">&gt;</span> GAP_SIZE_IN_SECONDS:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Close the old log file, and start a new one</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; split_log.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; split_log <span style="color: #66cc66;">=</span> Appender<span style="color: black;">&#40;</span>timestamp<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Starting new file&quot;</span><span style="color: #66cc66;">,</span> split_log.<span style="color: black;">filename</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; split_log.<span style="color: black;">append</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last_timestamp <span style="color: #66cc66;">=</span> timestamp<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> line_count % <span style="color: #ff4500;">100000</span> <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">0</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Processed %d lines&quot;</span> % <span style="color: black;">&#40;</span>line_count<span style="color: #66cc66;">,</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> parse_timestamp<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> line<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># m/d hh:mm:ss.msec</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># 6/6 21:04:29.435</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; regex <span style="color: #66cc66;">=</span> r<span style="color: #483d8b;">&quot;^(<span style="color: #000099; font-weight: bold;">\d</span>+)/(<span style="color: #000099; font-weight: bold;">\d</span>+) (<span style="color: #000099; font-weight: bold;">\d</span>+):(<span style="color: #000099; font-weight: bold;">\d</span>+):(<span style="color: #000099; font-weight: bold;">\d</span>+).(<span style="color: #000099; font-weight: bold;">\d</span>+) &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; matches <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>regex<span style="color: #66cc66;">,</span> line<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> matches <span style="color: #66cc66;">==</span> <span style="color: #008000;">None</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">None</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; timestamp <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2009</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>matches.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>matches.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>matches.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>matches.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>matches.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>matches.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">6</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>*<span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> timestamp<br />
<br />
<br />
<span style="color: #ff7700;font-weight:bold;">class</span> Appender:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> timestamp<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">filename</span> <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">&quot;WoWCombatLog_&quot;</span> + timestamp.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%Y%m%d_%H%M%S&quot;</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;.txt&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">handle</span> <span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">filename</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'a'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> append<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> line<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">handle</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> close<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">self</span>.<span style="color: black;">handle</span>.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<br />
<br />
splitter <span style="color: #66cc66;">=</span> CombatLog<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;../WoWCombatLog.20090904.txt&quot;</span><span style="color: black;">&#41;</span><br />
splitter.<span style="color: black;">process</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Done&quot;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://project-2501.net/index.php/2009/09/wow-combat-log-splitter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (Requested URI is rejected)
Database Caching 4/26 queries in 0.015 seconds using disk
Object Caching 1211/1258 objects using disk

Served from: project-2501.net @ 2012-05-20 07:56:25 -->
