<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users865</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/865" rel="self"/>
  <title>tyranarchy.myopenid.com</title>
  <updated>Thu Jul 24 07:50:25 -0700 2008</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor13708</id>
    <published>2008-07-24T07:50:25-07:00</published>
    <title>[Ruby] On Euler 14</title>
    <content type="html">&lt;p&gt;From the euler forums&lt;/p&gt;

&lt;pre&gt;array = []
 
(1..1_000_000).each do |x|
  sum = 0
  while x != 1
    sum += 1
    if x % 2 == 0
      x = x / 2
    else
      x = (3 * x) + 1
    end
  end
  array &amp;lt;&amp;lt; sum
end
 
puts array.index(array.max) + 1&lt;/pre&gt;</content>
    <author>
      <name>tyranarchy.myopenid.com</name>
      <email>tyranarchy@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/276-euler-14/refactors/13708" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code398</id>
    <published>2008-07-24T07:08:44-07:00</published>
    <updated>2008-07-24T07:08:44-07:00</updated>
    <title>[Ruby] Easier way to do this?</title>
    <content type="html">&lt;p&gt;This is for the online poker site Pokerstars, it creates a log file and using it you can determine when you've busted out of a tournament.  It searches the file for instances where you've won or lost.  Then it takes the HWND of the tournament (it's in the text file as well) and uses AutoItX to close the window.  I couldn't figure out how to import the win32api to use sendmessage WM_CLOSE to do it but I suspect there's an easier way.  &lt;/p&gt;

&lt;p&gt;Also if two windows end up having the same HWND in the log file it will close it even if you're still in the tournament, and it reads the whole file instead of what's just recently been added.  Can you tell I'm new to ruby?&lt;/p&gt;

&lt;pre&gt;require 'win32ole'
autoit = WIN32OLE.new('AutoItX3.Control')

hwnd = Array.new

while true do
    File.readlines(&amp;quot;C:\\Program Files\\PokerStars\\PokerStars.log.0&amp;quot;).each do |line|
        
      if line =~ /You finished/ or line =~ /You have/ and !hwnd.include?(line[19..26])
        hwnd.push(line[19..26])
        autoit.Winclose(&amp;quot;[HANDLE:#{hwnd[hwnd.length-1].to_s}]&amp;quot;) 
      end
    end
    sleep (10)
  
end&lt;/pre&gt;</content>
    <author>
      <name>tyranarchy.myopenid.com</name>
      <email>tyranarchy@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/398-easier-way-to-do-this" rel="alternate"/>
  </entry>
</feed>

