<?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>joey nelson &#187; ruby</title>
	<atom:link href="http://jnjnjn.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://jnjnjn.com</link>
	<description></description>
	<lastBuildDate>Mon, 19 Dec 2011 14:49:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Note to Self</title>
		<link>http://jnjnjn.com/63/note-to-self/</link>
		<comments>http://jnjnjn.com/63/note-to-self/#comments</comments>
		<pubDate>Fri, 14 Dec 2007 01:31:12 +0000</pubDate>
		<dc:creator>joey</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://jnjnjn.com/63/note-to-self/</guid>
		<description><![CDATA[This is how to install the Ruby mysql gem with your dumb xampp setup:

sudo gem install mysql -- --with-mysql-dir=/Applications/xampp/xamppfiles/ --with-mysql-include=/usr/local/mysql/include
sudo install_name_tool -change /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib /Applications/xampp/xamppfiles/lib/mysql/libmysqlclient.15.0.0.dylib  /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle

]]></description>
			<content:encoded><![CDATA[<p>This is how to install the Ruby mysql gem with your dumb xampp setup:</p>
<pre>
sudo gem install mysql -- --with-mysql-dir=/Applications/xampp/xamppfiles/ --with-mysql-include=/usr/local/mysql/include
sudo install_name_tool -change /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib /Applications/xampp/xamppfiles/lib/mysql/libmysqlclient.15.0.0.dylib  /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jnjnjn.com/63/note-to-self/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subversion commit email notification script</title>
		<link>http://jnjnjn.com/56/subversion-commit-email-notification-script/</link>
		<comments>http://jnjnjn.com/56/subversion-commit-email-notification-script/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 16:36:37 +0000</pubDate>
		<dc:creator>joey</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://jnjnjn.com/56/subversion-commit-email-notification-script/</guid>
		<description><![CDATA[So I&#8217;ve been using Subversion on a Linux box for a while now to manage my code for various freelance and personal projects.  I&#8217;ve recently started working with some other people who need access to the server, and I wanted to receive emails when they make a commit.  I also didn&#8217;t want to [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been using Subversion on a Linux box for a while now to manage my code for various freelance and personal projects.  I&#8217;ve recently started working with some other people who need access to the server, and I wanted to receive emails when they make a commit.  I also didn&#8217;t want to deal with <a href="http://search.cpan.org/dist/SVN-Notify/">svnnotify</a> (um, or I possibly didn&#8217;t know about it until it was too late).  Luckily Subversion makes it very easy to write a post-commit script to do this.  Here&#8217;s the ruby script I ended up with:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color: #808080; font-style: italic;">#!/usr/bin/ruby</span>
<span style="color: #888888;">require</span> <span style="color: #888888; background-color: #fbf6c5;">'rubygems'</span>
<span style="color: #888888;">require</span> <span style="color: #888888; background-color: #fbf6c5;">'action_mailer'</span>
&nbsp;
<span style="color: #888888">class</span> SimpleMailer &lt; <span style="">ActionMailer::Base</span>
  <span style="color: #888888">def</span> simple_message<span style="color: #bbbbbb;">&#40;</span>to, <span style="color: #888888;">sub</span>, message<span style="color: #bbbbbb;">&#41;</span>			                
    from <span style="color: #888888; background-color: #fbf6c5;">'walrus svn &lt;svn@wlrs.net&gt;'</span>					                
    recipients to.<span style="color: #F8320D;">join</span><span style="color: #bbbbbb;">&#40;</span><span style="color: #888888; background-color: #fbf6c5;">&quot;, &quot;</span><span style="color: #bbbbbb;">&#41;</span>
    subject <span style="color: #888888;">sub</span>
    body message
  <span style="color: #888888">end</span>
<span style="color: #888888">end</span>
&nbsp;
path = ARGV<span style="color: #bbbbbb;">&#91;</span><span style="color: #F8320D;">0</span><span style="color: #bbbbbb;">&#93;</span>
revision = ARGV<span style="color: #bbbbbb;">&#91;</span><span style="color: #F8320D;">1</span><span style="color: #bbbbbb;">&#93;</span>
&nbsp;
user = <span style="color: #888888; background-color: #fbf6c5;">`/usr/bin/svnlook author #{path} -r #{revision}`</span>.<span style="color: #888888;">chomp</span>
log = <span style="color: #888888; background-color: #fbf6c5;">`/usr/bin/svnlook log #{path} -r #{revision}`</span>.<span style="color: #888888;">chomp</span>
changed = <span style="color: #888888; background-color: #fbf6c5;">`/usr/bin/svnlook changed #{path} -r #{revision}`</span>.<span style="color: #888888;">chomp</span>
diff = <span style="color: #888888; background-color: #fbf6c5;">`/usr/bin/svnlook diff #{path} -r #{revision}`</span>.<span style="color: #888888;">chomp</span>
dirs = <span style="color: #888888; background-color: #fbf6c5;">`/usr/bin/svnlook dirs-changed #{path} -r #{revision}`</span>.<span style="color: #888888;">chomp</span>
date = <span style="color: #888888; background-color: #fbf6c5;">`/usr/bin/svnlook date #{path} -r #{revision}`</span>.<span style="color: #888888;">chomp</span>
&nbsp;
dir_list = dirs.<span style="color: #888888;">split</span><span style="color: #bbbbbb;">&#40;</span><span style="color: #888888; background-color: #fbf6c5;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #bbbbbb;">&#41;</span>.<span style="color: #F8320D;">collect</span> <span style="color: #888888">do</span> |dir| 
  dir =~ /<span style="color: #bbbbbb;">&#40;</span><span style="color: #bbbbbb;">&#91;</span>^\/<span style="color: #bbbbbb;">&#93;</span>+<span style="color: #bbbbbb;">&#41;</span>/
  $<span style="color: #F8320D;">1</span>
<span style="color: #888888">end</span>
dir_list.<span style="color: #F8320D;">uniq</span>!
&nbsp;
recipients = <span style="color: #bbbbbb;">&#91;</span><span style="color: #888888; background-color: #fbf6c5;">&quot;joey@wlrs.net&quot;</span><span style="color: #bbbbbb;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#other people might want these emails</span>
recipients &lt;&lt; <span style="color: #888888; background-color: #fbf6c5;">&quot;team@mycompany.com&quot;</span> <span style="color: #888888">if</span> dir_list.<span style="color: #888888">include</span>?<span style="color: #bbbbbb;">&#40;</span><span style="color: #888888; background-color: #fbf6c5;">&quot;mycompany.com&quot;</span><span style="color: #bbbbbb;">&#41;</span>
recipients &lt;&lt; <span style="color: #888888; background-color: #fbf6c5;">&quot;someone.else@oursite.com&quot;</span> <span style="color: #888888">if</span> dir_list.<span style="color: #888888">include</span>?<span style="color: #bbbbbb;">&#40;</span><span style="color: #888888; background-color: #fbf6c5;">&quot;oursite.com&quot;</span><span style="color: #bbbbbb;">&#41;</span>
&nbsp;
subject_log = log.<span style="color: #888888;">split</span><span style="color: #bbbbbb;">&#40;</span><span style="color: #888888; background-color: #fbf6c5;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #bbbbbb;">&#41;</span><span style="color: #bbbbbb;">&#91;</span><span style="color: #F8320D;">0</span><span style="color: #bbbbbb;">&#93;</span>.<span style="color: #F8320D;">slice</span><span style="color: #bbbbbb;">&#40;</span><span style="color: #F8320D;">0</span>..<span style="color: #F8320D;">60</span><span style="color: #bbbbbb;">&#41;</span>
dir_string = dir_list.<span style="color: #F8320D;">join</span><span style="color: #bbbbbb;">&#40;</span><span style="color: #888888; background-color: #fbf6c5;">&quot;, &quot;</span><span style="color: #bbbbbb;">&#41;</span>
subject = <span style="color: #888888; background-color: #fbf6c5;">&quot;r#{revision} #{user} in #{dir_string}: <span style="color: #000099; font-weight: bold;">\&quot;</span>#{subject_log}<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>
message = <span style="color: #888888; background-color: #fbf6c5;">&quot;#{user} committed these changes on #{date}:<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>#{log}<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>#{changed}<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>#{diff}&quot;</span>
<span style="">ActionMailer::Base</span>.<span style="color: #F8320D;">smtp_settings</span> = <span style="color: #bbbbbb;">&#123;</span> <span style="">:address</span> =&gt; <span style="color: #888888; background-color: #fbf6c5;">'localhost'</span>, <span style="">:port</span> =&gt; <span style="color: #F8320D;">25</span>, <span style="">:domain</span> =&gt; <span style="color: #888888; background-color: #fbf6c5;">'localdomain'</span><span style="color: #bbbbbb;">&#125;</span>
SimpleMailer.<span style="color: #F8320D;">deliver_simple_message</span><span style="color: #bbbbbb;">&#40;</span>recipients, subject, message<span style="color: #bbbbbb;">&#41;</span></pre></div></div>

<p>Projects in my repository are setup like this:</p>
<pre>
svn/oursite.com/trunk
svn/mycompany.com/trunk
</pre>
<p>That means we just look at the svn directory to see which project is being modified, then we alert the appropriate people.  The emails are plain text and include the commit comments, modified files, and a full diff of the commit.  What else do you need?</p>
]]></content:encoded>
			<wfw:commentRss>http://jnjnjn.com/56/subversion-commit-email-notification-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recalculate WordPress comment count</title>
		<link>http://jnjnjn.com/22/recalculate-wordpress-comment-count/</link>
		<comments>http://jnjnjn.com/22/recalculate-wordpress-comment-count/#comments</comments>
		<pubDate>Mon, 25 Sep 2006 02:33:50 +0000</pubDate>
		<dc:creator>joey</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://bloop.org/joey/2006/09/24/recalculate-wordpress-comment-count/</guid>
		<description><![CDATA[So I&#8217;ve been doing some work on the long-neglected Fontleech and today found myself removing over .25 million spam comments.  That sounds herculean, but it was actually pretty easy.
The WordPress frontend pulls the comment count for each post from the &#8216;comment_count&#8217; field in the wp_posts table.  obviously that doesn&#8217;t get updated when you [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been doing some work on the long-neglected <a href="http://fontleech.com">Fontleech</a> and today found myself removing over .25 million spam comments.  That sounds herculean, but it was actually pretty easy.</p>
<p>The WordPress frontend pulls the comment count for each post from the &#8216;comment_count&#8217; field in the wp_posts table.  obviously that doesn&#8217;t get updated when you manually delete spam directly from the database, so here&#8217;s a simple ruby script that will update that for you (just define your db variables):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color: #808080; font-style: italic;">#!/usr/bin/ruby</span>
<span style="color: #888888;">require</span> <span style="color: #888888; background-color: #fbf6c5;">'mysql'</span>
&nbsp;
db = Mysql.<span style="color: #F8320D;">real_connect</span><span style="color: #bbbbbb;">&#40;</span>host, user, pass, dbname<span style="color: #bbbbbb;">&#41;</span>
ids = db.<span style="color: #F8320D;">query</span><span style="color: #bbbbbb;">&#40;</span><span style="color: #888888; background-color: #fbf6c5;">&quot;SELECT `ID` FROM `wp_posts` WHERE 1&quot;</span><span style="color: #bbbbbb;">&#41;</span>
&nbsp;
ids.<span style="color: #F8320D;">each_hash</span> <span style="color: #888888">do</span> |post|
  id = post<span style="color: #bbbbbb;">&#91;</span><span style="color: #888888; background-color: #fbf6c5;">'ID'</span><span style="color: #bbbbbb;">&#93;</span>
  num = <span style="color: #F8320D;">0</span>
  comments = db.<span style="color: #F8320D;">query</span><span style="color: #bbbbbb;">&#40;</span><span style="color: #888888; background-color: #fbf6c5;">&quot;SELECT COUNT(1) FROM `wp_comments` WHERE `comment_post_ID`='#{id}' AND `comment_approved`='1';&quot;</span><span style="color: #bbbbbb;">&#41;</span>
  comments.<span style="color: #F8320D;">each</span> <span style="color: #bbbbbb;">&#123;</span>|x| num = x<span style="color: #bbbbbb;">&#91;</span><span style="color: #F8320D;">0</span><span style="color: #bbbbbb;">&#93;</span><span style="color: #bbbbbb;">&#125;</span>
  up = db.<span style="color: #F8320D;">query</span><span style="color: #bbbbbb;">&#40;</span><span style="color: #888888; background-color: #fbf6c5;">&quot;UPDATE `wp_posts` SET `comment_count`='#{num}' WHERE `ID`='#{id}';&quot;</span><span style="color: #bbbbbb;">&#41;</span>
<span style="color: #888888">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://jnjnjn.com/22/recalculate-wordpress-comment-count/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Finding WIN32OLE method names in Ruby</title>
		<link>http://jnjnjn.com/13/finding-win32ole-method-names-in-ruby/</link>
		<comments>http://jnjnjn.com/13/finding-win32ole-method-names-in-ruby/#comments</comments>
		<pubDate>Wed, 21 Jun 2006 08:00:00 +0000</pubDate>
		<dc:creator>joey</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[watir]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[For the past couple months at work I&#8217;ve been using Watir, a Ruby library for controlling Internet Explorer, to automate some of the testing on our site.  But the Snap site is a beast, with an enormous amount of Javascript and hundreds of dynamically-modified divs.
Since Watir can bog down while iterating through 100+ div [...]]]></description>
			<content:encoded><![CDATA[<p>For the past couple months at work I&#8217;ve been using <a href="http://openqa.org/watir/">Watir</a>, a Ruby library for controlling Internet Explorer, to automate some of the testing on our site.  But the <a href="http://snap.com/#snap">Snap site is a beast</a>, with an enormous amount of Javascript and hundreds of dynamically-modified divs.</p>
<p>Since Watir can bog down while iterating through 100+ div objects, I&#8217;m working directly with WIN32OLE objects for certain things.</p>
<p>I&#8217;m very new to ruby. And WIN32OLE is weird. I had just been copying code from the watir library and modifying it to suit my needs, but today I had to do some more complicated stuff.  In ruby, you can view the available methods of any object by doing this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color: #888888;">puts</span> foo.<span style="color: #F8320D;">methods</span></pre></div></div>

<p>But if you do that with a WIN32OLE object it doesn&#8217;t give you jack.  I finally managed to find a <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/71620">ruby-talk post</a> from 3 years ago that shed some light on this.  So here&#8217;s a method that can pull it off:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color: #888888">class</span> WIN32OLE
  <span style="color: #888888">def</span> list_ole_methods
    method_names = ole_methods.<span style="color: #F8320D;">collect</span> <span style="color: #bbbbbb;">&#123;</span>|m| m.<span style="color: #F8320D;">name</span><span style="color: #bbbbbb;">&#125;</span>
    <span style="color: #888888;">puts</span> method_names.<span style="color: #F8320D;">sort</span>.<span style="color: #F8320D;">uniq</span>
  <span style="color: #888888">end</span>
<span style="color: #888888">end</span></pre></div></div>

<p>So doing:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">foo.<span style="color: #F8320D;">list_ole_methods</span></pre></div></div>

<p>Will give you a long list of method names you can call with your object.</p>
<p>I realize this isn&#8217;t, uh, interesting, but hopefully the next tard trying to figure this stuff out will be able to find this post on Google.  </p>
<p>And just for the record, Watir fucking rules.  It easily outperformed every other automation tool we evaluated (many of which cost tens of thousands of dollars) and, not coincidentally, harnesses the power of an awesome language like Ruby.  A lot of the other packages we looked at use strange proprietary languages that aren&#8217;t really documented (because then they can talk you into taking a weeklong $8k training course) and can&#8217;t pull off half the stuff we&#8217;ve already done using Watir.</p>
]]></content:encoded>
			<wfw:commentRss>http://jnjnjn.com/13/finding-win32ole-method-names-in-ruby/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

