<?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>Expendable Words &#187; Ruby</title>
	<atom:link href="http://www.expendablewords.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.expendablewords.com</link>
	<description>No guarantees on quality or cohesiveness. Read at your own risk.</description>
	<lastBuildDate>Sat, 26 Sep 2009 15:14:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Automatic My Coke Rewards Code Entry</title>
		<link>http://www.expendablewords.com/2008/09/01/automatic-my-coke-rewards-code-entry/</link>
		<comments>http://www.expendablewords.com/2008/09/01/automatic-my-coke-rewards-code-entry/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 23:00:07 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Play]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.expendablewords.com/?p=47</guid>
		<description><![CDATA[Until recently I had a large backlog of My Coke Rewards points. In addition to all the codes I collected myself, I also received quite a few from my friends and family (Thanks!). The problem is that the site only allows you to redeem 10 codes per day, and I had a hard time remembering [...]]]></description>
			<content:encoded><![CDATA[<p>Until recently I had a large backlog of <em>My Coke Rewards</em> points. In addition to all the codes I collected myself, I also received quite a few from my friends and family (Thanks!). The problem is that the site only allows you to redeem 10 codes per day, and I had a hard time remembering to enter them every day.</p>
<p>To help, I created a Ruby script for automatically processing codes. Every day, it reads 10 codes from a text file, then submits them to mycokerewards.com and logs the result. That way, I could just add all my codes to a file and it would take care of the rest.</p>
<p>I&#8217;ve provided the script below, as well as instructions for configuring it on a Mac (should be similar  on Unix/Linux). If you&#8217;re using Windows, you can do the same thing by downloading Ruby and setting up a scheduled task. This isn&#8217;t the most user-friendly process, so a little development and/or command line experience would be helpful, but if you don&#8217;t have that you should be able to work it out by stepping through the instructions. Good luck and happy redeeming!</p>
<p><span id="more-47"></span><br />
<strong>Here&#8217;s the code</strong><br/></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'xmlrpc/client'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'logger'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> McrSender 
  @@SERVICE_URL = <span style="color:#996600;">&quot;https://secure.mycokerewards.com/xmlrpc&quot;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>codeFile, logFile, readCount, username, password<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@codeFile</span> = codeFile
	<span style="color:#0066ff; font-weight:bold;">@logFile</span> = logFile
    <span style="color:#0066ff; font-weight:bold;">@readCount</span> = readCount
    <span style="color:#0066ff; font-weight:bold;">@username</span> = username
    <span style="color:#0066ff; font-weight:bold;">@password</span> = password
    <span style="color:#0066ff; font-weight:bold;">@logger</span> = <span style="color:#CC00FF; font-weight:bold;">Logger</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>@logFile<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> send_codes
    i = <span style="color:#006666;">1</span>
    <span style="color:#008000; font-style:italic;"># read file into an array</span>
    lines = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">readlines</span><span style="color:#006600; font-weight:bold;">&#40;</span>@codeFile<span style="color:#006600; font-weight:bold;">&#41;</span>
    lineCount = lines.<span style="color:#9900CC;">length</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>lineCount <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">and</span> lines<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">strip</span>.<span style="color:#9900CC;">length</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#008000; font-style:italic;"># login</span>
      <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>login == <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#0066ff; font-weight:bold;">@logger</span>.<span style="color:#9900CC;">info</span> <span style="color:#996600;">&quot;Successfully logged in.&quot;</span>
&nbsp;
        <span style="color:#CC0066; font-weight:bold;">puts</span> lineCount
&nbsp;
        <span style="color:#008000; font-style:italic;"># process items and remove them from the array</span>
        i = <span style="color:#006666;">0</span>
        <span style="color:#9966CC; font-weight:bold;">while</span> <span style="color:#006600; font-weight:bold;">&#40;</span>i <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#0066ff; font-weight:bold;">@readCount</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> i <span style="color:#006600; font-weight:bold;">&lt;</span> lineCount<span style="color:#006600; font-weight:bold;">&#41;</span>
          code = lines<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">chomp</span>
          send_code<span style="color:#006600; font-weight:bold;">&#40;</span>code<span style="color:#006600; font-weight:bold;">&#41;</span>
          lines.<span style="color:#9900CC;">delete_at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>
          i <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
        <span style="color:#008000; font-style:italic;"># write array back to file</span>
        <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>@codeFile, <span style="color:#996600;">&quot;w&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span>
          file.<span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span>lines.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#0066ff; font-weight:bold;">@logger</span>.<span style="color:#9900CC;">error</span> <span style="color:#996600;">&quot;Could not login with username '#{@username}' and password '#{@password}'.&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#0066ff; font-weight:bold;">@logger</span>.<span style="color:#9900CC;">info</span> <span style="color:#996600;">&quot;No codes found in code file (or the first line is empty). Exiting.&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  private
    <span style="color:#9966CC; font-weight:bold;">def</span> send_code<span style="color:#006600; font-weight:bold;">&#40;</span>code<span style="color:#006600; font-weight:bold;">&#41;</span>
      args = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">'emailAddress'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@username</span>, <span style="color:#996600;">'password'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@password</span>, <span style="color:#996600;">'screenName'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">' '</span>, <span style="color:#996600;">'capCode'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> code, <span style="color:#996600;">'VERSION'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'3.0'</span><span style="color:#006600; font-weight:bold;">&#125;</span>
      service = <span style="color:#6666ff; font-weight:bold;">XMLRPC::Client</span>.<span style="color:#9900CC;">new2</span><span style="color:#006600; font-weight:bold;">&#40;</span>@@SERVICE_URL<span style="color:#006600; font-weight:bold;">&#41;</span>
      result = service.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'points.enterCode'</span>, args<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>result<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'ENTER_CODE_RESULT'</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#996600;">&quot;true&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        earned = result<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'POINTS_EARNED'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        <span style="color:#0066ff; font-weight:bold;">@logger</span>.<span style="color:#9900CC;">info</span> <span style="color:#996600;">&quot;Successfully entered code '#{code}' Points earned '#{earned}'. &quot;</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        message = result<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'MESSAGES'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        <span style="color:#0066ff; font-weight:bold;">@logger</span>.<span style="color:#9900CC;">error</span> <span style="color:#996600;">&quot;Error entering code '#{code}'. Error message: '#{message}'.&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> login
      args = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">'emailAddress'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@username</span>, <span style="color:#996600;">'password'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@password</span>, <span style="color:#996600;">'screenName'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">' '</span>, <span style="color:#996600;">'VERSION'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'3.0'</span><span style="color:#006600; font-weight:bold;">&#125;</span>
      service = <span style="color:#6666ff; font-weight:bold;">XMLRPC::Client</span>.<span style="color:#9900CC;">new2</span><span style="color:#006600; font-weight:bold;">&#40;</span>@@SERVICE_URL<span style="color:#006600; font-weight:bold;">&#41;</span>
      result = service.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'points.pointsBalance'</span>, args<span style="color:#006600; font-weight:bold;">&#41;</span>
      result<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'LOGIN_RESULT'</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#996600;">&quot;true&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
sender = McrSender.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;codes.txt&quot;</span>, <span style="color:#996600;">&quot;log.txt&quot;</span>, <span style="color:#006666;">10</span>, <span style="color:#996600;">&quot;YOUR_EMAIL&quot;</span>, <span style="color:#996600;">&quot;YOUR_PASSWORD&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
sender.<span style="color:#9900CC;">send_codes</span></pre></td></tr></table></div>

<p><strong>How to install</strong><br/></p>
<ol>
<li>
Make sure Ruby is installed on your Mac. (It is by default in Leopard). You can open terminal and type the following to check. It will return the Ruby version if it&#8217;s installed.</p>
<pre>
ruby -v
</pre>
</li>
<li>
Download the <a href='http://www.expendablewords.com/wp-content/uploads/2008/09/mcrsender.zip'>zip file</a> containing the script, code file and log file.
</li>
<li>
Extract the archive, the move the McrSender folder to the desired location. I&#8217;ll use <em>/Users/doug</em> for the remaining instructions. Replace <em>/Users/doug</em> with your own path.
</li>
<li>
In the bottom two lines of McrSender.rb, change &#8220;codes.txt&#8221; to the full path to your codes.txt file, &#8220;log.txt&#8221; to the full path to your log.txt file, &#8220;YOUR_EMAIL&#8221; to the email address you use for My Coke Rewards, and &#8220;YOUR_PASSWORD&#8221; to the password you use for My Coke Rewards. (NOTE: All of these values should be surrounded in double quotes)
</li>
<li>
Add your My Coke Rewards Codes to the codes.txt file. There should be one code per line.
</li>
<li>
Open terminal then type the following commands to change permissions on the Ruby script to make it executable and on the codes.txt and log.txt files to make them readable and writable.</p>
<pre>
cd /Users/doug
chmod 755 McrSender.rb
chmod 666 codes.txt
chmod 666 log.txt
</pre>
</li>
<li>
Create a cron job to run the script every day. Again, in Terminal type:</p>
<pre>
EDITOR=nano
crontab -e
</pre>
<p>Your cron file will open up in the nano command line text editor. Add the following line to run the script at 6:00 am every morning:</p>
<pre>
0 6 * * * ruby /Users/dwburns/scripts/McrSender/McrSender.rb
</pre>
<p>(Again, change the path to your own path).
</li>
</ol>
<p>You can test it the first time by running (something like) the following in Terminal:</p>
<pre>
/Users/doug/McrSender/McrSender.rb
</pre>
<p><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.expendablewords.com/2008/09/01/automatic-my-coke-rewards-code-entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter Developer Interview</title>
		<link>http://www.expendablewords.com/2008/08/10/twitter-developer-interview/</link>
		<comments>http://www.expendablewords.com/2008/08/10/twitter-developer-interview/#comments</comments>
		<pubDate>Sun, 10 Aug 2008 12:52:20 +0000</pubDate>
		<dc:creator>Doug</dc:creator>
				<category><![CDATA[Work (Tech Stuff)]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://expendablewords.wordpress.com/?p=14</guid>
		<description><![CDATA[There&#8217;s a short interview with Alex Payne, one of the Twitter developers over at radicalbehavior.com. He&#8217;s a Ruby / RoR developer (and big fan), but points out how it falls short for high traffic applications.
A few interesting quotes:
All the convenience methods and syntactical sugar that makes Rails such a pleasure for coders ends up being [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a short interview with Alex Payne, one of the Twitter developers over at <a href="http://www.radicalbehavior.com/5-question-interview-with-twitter-developer-alex-payne/">radicalbehavior.com</a>. He&#8217;s a Ruby / RoR developer (and big fan), but points out how it falls short for high traffic applications.</p>
<p>A few interesting quotes:</p>
<blockquote><p>All the convenience methods and syntactical sugar that makes Rails such a pleasure for coders ends up being absolutely punishing, performance-wise.</p></blockquote>
<blockquote><p>It’s also worth mentioning that there shouldn’t be doubt in anybody’s mind at this point that Ruby itself is slow.</p></blockquote>
<blockquote><p>All of us working on Twitter are big Ruby fans, but I think it’s worth being frank that this isn’t one of those relativistic language issues.  Ruby is slow.</p></blockquote>
<p>Ruby is a great language, but this is just further proof that you need to take a close look at your requirements up front, then pick the best (not necessarily the coolest) tool for the job at hand.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.expendablewords.com/2008/08/10/twitter-developer-interview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
