<?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>ChrisBellini.com &#187; Ruby</title>
	<atom:link href="http://www.chrisbellini.com/category/programming/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisbellini.com</link>
	<description>test</description>
	<lastBuildDate>Mon, 21 Dec 2009 02:04:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>quick calc</title>
		<link>http://www.chrisbellini.com/2006/11/02/quick-calc/</link>
		<comments>http://www.chrisbellini.com/2006/11/02/quick-calc/#comments</comments>
		<pubDate>Thu, 02 Nov 2006 12:12:39 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.chrisbellini.com/?p=561</guid>
		<description><![CDATA[Often, I need to do some quick arithmetic involving multiple operations and don't have a good calculator handy.  There's a calculator application on my cell phone, but I'm an atrociously slow cell phone typer.  Most simple calculator apps, like calc.exe in Windows, are fine for single operations like 2+2 or 67 * 1.14, [...]]]></description>
			<content:encoded><![CDATA[<p>Often, I need to do some quick arithmetic involving multiple operations and don't have a good calculator handy.  There's a calculator application on my cell phone, but I'm an atrociously slow cell phone typer.  Most simple calculator apps, like <em>calc.exe</em> in Windows, are fine for single operations like 2+2 or 67 * 1.14, but for multiple-operation expressions, those simple apps won't cut it without needing to resort to some copy 'n' pasting or [gasp] manual jotting with a writing utensil.</p>
<p>When I'm in front of a computer and I need to quickly calculate an arithmetic expression to figure out sales tax, find averages, multiply numbers too large for my brain to deal with, etc, writing a script or a total application would be overkill.  Here are the <a href="http://en.wikipedia.org/wiki/Cross-platform" target="_blank">cross-platform</a> solutions that I find myself resorting to:</p>
<p><strong>Python (<a href="http://www.python.org" target="_blank">python.org</a>)</strong><br />
<img src="images/blog/idle_calc.jpg" border="0" alt="Python's IDLE" /><br />
Python's interpreter is convenient.  It allows you to enter any mathematical express and it will evaluate it as if it were a line in a Python script.  You could even assign values to variables or other data structures, use loops, conditions, and create functions like you would in any ol' script.</p>
<p><strong>Ruby (<a href="http://www.ruby-lang.org" target="_blank">ruby-lang.org</a>)</strong><br />
<img src="images/blog/irb-fxri_calc.jpg" border="0" alt="Ruby's IRB" /><br />
Ruby's interpreter has nearly identical features to Python's interpreter, except that the language is Ruby instead of Python...duh <img src='http://www.chrisbellini.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong>Mozilla Firefox JavaScript Error Console (<a href="http://www.mozilla.org/firefox/" target="_blank">mozilla.org/firefox/</a>)</strong><br />
In Firefox, selecting "Error Console" from the Tools menu item will launch the JavaScript Error Console window.  The Error Console is useful for debugging JavaScript in Web applications.  However, much like Python's and Ruby's interpreter, it too can quickly evaluate arithmetic expressions.  Its main shortcoming, when compared to the aforementioned Python and Ruby interpreters, is that can only evaluate one line at a time.  So you cannot store data in variables, since once you click the evaluate button, your variables are destroyed.<br />
<img src="images/blog/firefox_calc.jpg" border="0" alt="Firefox's JavaScript Error Console" /></p>
<p><strong>Google (<a href="http://www.google.com" target="_blank">google.com</a>)</strong><br />
Google's powerful searching abilities are one thing, but did you know that it can also perform calculations (Ex: <a href="http://www.google.ca/search?hl=en&q=%2899*66%29%5E2&btnG=Google+Search&meta=" target="_blank">(99*66)<sup>2</sup></a>), unit conversions (Ex: <a href="http://www.google.ca/search?hl=en&q=120+kilometres+in+miles&btnG=Search&meta=" target="_blank">120 kilometres in miles</a>) and even unit+currency conversion (Ex: <a href="http://www.google.com/search?hl=en&lr=&q=%242.85+per+gallon+in+Canadian+money+per+liter&btnG=Search" target="_blank">help the in laws figure out Canadian gas prices</a> ).</p>
<p><strong>Instacalc (<a href="http://instacalc.com" target="_blank">instacalc.com</a>)</strong><br />
I've just recently come across this website and haven't explored all of the features yet.  However, it looks very promising.  Using <a href="http://en.wikipedia.org/wiki/AJAX" target="_blank">AJAX</a> to display answers as you type in your expression is a nice touch.</p>
<p>For <a href="http://www.microsoft.com/windows/" target="_blank">Windows</a> users, there's also the <a href="http://download.microsoft.com/download/whistler/Install/2/WXP/EN-US/PowerCalcPowertoySetup.exe" target="_blank">Power Calculator</a> that's part of the suite of <a href="http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx" target="_blank">Windows XP PowerToys</a>.  I keep it bound to the Calculator key on my keyboard.</p>
<p>better calculators + me = happy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisbellini.com/2006/11/02/quick-calc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SendKeys()? meh. how about SendFood() or SendMoney()?</title>
		<link>http://www.chrisbellini.com/2006/04/01/sendkeys-meh-how-about-sendfood-or-sendmoney/</link>
		<comments>http://www.chrisbellini.com/2006/04/01/sendkeys-meh-how-about-sendfood-or-sendmoney/#comments</comments>
		<pubDate>Sat, 01 Apr 2006 15:38:21 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SendKeys]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://www.chrisbellini.com/?p=472</guid>
		<description><![CDATA[At work last week, it so happened that I had a very tedious manual task to perform.  Due to an NDA, I can't say which server application this task involved.  Let's just say that there isn't an easy way to import lots values for a picklist field.  I had to add 245 [...]]]></description>
			<content:encoded><![CDATA[<p>At work last week, it so happened that I had a very tedious manual task to perform.  Due to an <acronym title="Non-Disclosure Agreement">NDA</acronym>, I can't say which server application this task involved.  Let's just say that there isn't an easy way to import lots values for a picklist field.  I had to add 245 values from an <a href="http://office.microsoft.com/excel/" target="_blank">Excel</a> worksheet to 3 picklist fields - that would require me to switch to <a href="http://office.microsoft.com/excel/" target="_blank">Excel</a>, select the value, copy, switch to the server application, click "Add", paste, click "OK" 735 times!  There is apparently a way to do this by writing a <a href="http://msdn.microsoft.com/netframework/" target="_blank">.NET</a> assembly, but I was assured that finding the neccessary info to accomplish this would take longer that actually doing the manual task.  And that's when the thought of my wrists in firey pain from repetive stress foced me to recall and old friend of mine from shell32.dll - the SendKeys() method.</p>
<p>SendKeys() does what it sounds like...it sends keystrokes.  Plain and simple.  For that task, I knew what keystrokes I needed to do.  I could've written something in C# or VB.NET, since there's a SendKeys() method in the System.Windows.Forms namespace, but time was not on my side.  There's nothing like the cling and static-free scripting languages to save the day <img src='http://www.chrisbellini.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   So using the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/scriptinga.asp" target="_blank">Windows Scripting Host</a> and 15 minutes of my time, I wrote some <a href="http://msdn.microsoft.com/library/en-us/script56/html/1e9b3876-3d38-4fd8-8596-1bbfe2330aa9.asp" target="_blank">JScript</a> code (as an aside, it appears that <a href="http://www.microsoft.com" target="_blank">Microsoft</a> is downplaying <a href="http://msdn.microsoft.com/library/en-us/script56/html/0a8270d7-7d8f-4368-b2a7-065acb52fc54.asp" target="_blank">VBScript</a> more and more all the time) that read all of the values from the <a href="http://office.microsoft.com/excel/" target="_blank">Excel</a> worksheet, stored them, and then switched back to the server application's window to add values in the manual process.  I could then take my hands off of the keyboard and watch my "ghost writer" do the work, saving me plenty of time and preventing a repetitive stress injury <img src='http://www.chrisbellini.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>SendKeys() seems old-school to me, but comes in handy when an application you're working with doesn't have any of its functionality exposed via <a href="http://en.wikipedia.org/wiki/Component_Object_Model" target="_blank">COM</a> or <a href="http://msdn.microsoft.com/netframework/" target="_blank">.NET</a> or whatever.  Even if it does, sometimes it's quicker to send keystrokes than read <acronym title="Application Programming Interface">API</acronym> documentation.  As a cheesy example, let's fire up MSCONFIG and automatically switch to the "Startup" tab to see what's launching when <a href="http://www.microsoft.com/windows/" target="_blank">Windows</a> boots:</p>
<pre class="vb">&nbsp;
// <span style="color: #b1b100;">Let</span><span style="color: #808080;">'s get to the good stuff in shell32.dll.</span>
<span style="color: #b1b100;">var</span> objWSHShell = WScript.<span style="color: #b1b100;">CreateObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;WScript.Shell&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
// Launch MSCONFIG.
<span style="color: #66cc66;">objWSHShell</span>.<span style="color: #66cc66;">Run</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;msconfig&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
// Wait a couple of seconds <span style="color: #b1b100;">for</span> MSCONFIG <span style="color: #b1b100;">to</span> launch.
<span style="color: #66cc66;">WScript</span>.<span style="color: #66cc66;">Sleep</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2000</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
// <span style="color: #b1b100;">Switch</span> the focus <span style="color: #b1b100;">to</span> MSCONFIG.
<span style="color: #66cc66;">objWSHShell</span>.<span style="color: #b1b100;">AppActivate</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;System Configuration Utility&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
// Keystroke <span style="color: #b1b100;">time</span>!
// SHIFT+<span style="color: #b1b100;">TAB</span> sets the keyboard focus <span style="color: #b1b100;">to</span> the row of tabs.
<span style="color: #66cc66;">objWSHShell</span>.<span style="color: #b1b100;">SendKeys</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;+{TAB}&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
// Hit the <span style="color: #b1b100;">right</span> cursor key <span style="color: #cc66cc;">5</span> times <span style="color: #b1b100;">to</span> <span style="color: #b1b100;">get</span> <span style="color: #b1b100;">to</span> the Startup <span style="color: #b1b100;">tab</span>.
<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">var</span> i = <span style="color: #cc66cc;">0</span>; i &lt; <span style="color: #cc66cc;">5</span>; i++<span style="color: #66cc66;">&#41;</span>
    objWSHShell.<span style="color: #b1b100;">SendKeys</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;{RIGHT}&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Pretty simple, and you don't need the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/scriptinga.asp" target="_blank">Windows Scripting Host</a> to use SendKeys() from a scripting language.  You can use non-<a href="http://www.microsoft.com" target="_blank">Microsoft</a> languages too.  For example, the scripting language that has my attention lately is <a href="http://www.ruby-lang.org" target="_blank">Ruby</a> -  it's like <a href="http://www.python.org" target="_blank">Python</a> on steroids.  This script will do the same thing as the one above, but this time, I'll write it in <a href="http://www.ruby-lang.org" target="_blank">Ruby</a> (without comments):</p>
</pre>
<pre class="ruby">&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'win32ole'</span>
&nbsp;
objWSHShell = WIN32OLE.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;WScript.Shell&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
objWSHShell.<span style="color:#9900CC;">Run</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;msconfig&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">sleep</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
objWSHShell.<span style="color:#9900CC;">AppActivate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;System Configuration Utility&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
objWSHShell.<span style="color:#9900CC;">SendKeys</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;+{TAB}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#006666;">5</span>.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;">do</span>
   objWSHShell.<span style="color:#9900CC;">SendKeys</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;{RIGHT}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;</pre>
<p>Think of the fun you can have automating all sorts of tasks in <a href="http://www.microsoft.com/windows/" target="_blank">Windows</a> with the SendKeys() method <img src='http://www.chrisbellini.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisbellini.com/2006/04/01/sendkeys-meh-how-about-sendfood-or-sendmoney/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ridin&#8217; the rails with ubuntu</title>
		<link>http://www.chrisbellini.com/2005/11/25/ubuntu-im-sold/</link>
		<comments>http://www.chrisbellini.com/2005/11/25/ubuntu-im-sold/#comments</comments>
		<pubDate>Sat, 26 Nov 2005 02:10:35 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.chrisbellini.com/?p=426</guid>
		<description><![CDATA[I had enough of hearing about how wonderful Ruby On Rails is, so I wanted to see it for myself.  Being the type of person who's interested in many things all at the same time, I had a reason to try out another much-talked about thing.  In order to properly try out RoR, [...]]]></description>
			<content:encoded><![CDATA[<p>I had enough of hearing about how wonderful <a href="http://www.rubyonrails.com" target="_blank">Ruby On Rails</a> is, so I wanted to see it for myself.  Being the type of person who's interested in many things all at the same time, I had a reason to try out another much-talked about thing.  In order to properly try out <a href="http://www.rubyonrails.com" target="_blank">RoR</a>, I wanted a decent web server, so I installed <a href="http://www.ubuntulinux.org" target="_blank">Ubuntu Linux</a>.  <a href="http://www.ubuntulinux.org" target="_blank">Ubuntu</a> is by far the easiest Linux distro I've used thus far.  As such, its installation  is quite basic - aiming at the desktop user demographic.  But that didn't stop me, and <a href="http://www.ubuntulinux.org" target="_blank">Ubuntu</a> makes it simple to add what you want.  Sometimes I used apt-get and other times I used the <acronym title="Graphical User Interface">GUI</acronym> app that allows you to search for and install new and updated packages.</p>
<p>First, I needed web server software, so installing and configuring <a href="http://httpd.apache.org" target="_blank">Apache</a> 2.0 was my top priority.  The next thing that I installed was <a href="http://www.php.net" target="_blank">PHP</a> 5.0; I'm familiar with 3.x and 4.x but I thought I should begin to explore 5.  <a href="http://dev.mysql.com" target="_blank">MySQL</a> 5 wasn't available in the repository at the time, so I installed the latest 4 release.  To make life easier, I installed <a href="http://www.phpmyadmin.net" target="_blank">PHPMyAdmin</a>; normally I prefer a command line but sometimes I just need to stave the <acronym title="Repetitive Stress Injury">RSI</acronym> symptoms.    Then came time to install the <a href="http://www.ruby-lang.org" target="_blank">Ruby</a> interpreter.  Finally, using Gems, I installed <a href="http://www.rubyonrails.com" target="_blank">Rails</a>.</p>
<p>After browsing some tutorials, I saw how easy it was to generate the skeleton of a data-driven web application with <a href="http://www.rubyonrails.com" target="_blank">Ruby On Rails</a>.  As such, it got me thinking of what's possible now that a lot of overhead is taken care of by <a href="http://www.rubyonrails.com" target="_blank">RoR</a>.  I just need a way to narrow down my list of possible project ideas.</p>
<p>Take a look at my screenshots below of my <a href="http://www.ubuntulinux.org" target="_blank">Ubuntu</a> web server.</p>
<p><a href="/images/plan/ubuntu_phpinfo.png" target="_blank">php_info()</a> | <a href="/images/plan/ubuntu_ror.png" target="_blank">RoR WEBrick</a> | <a href="/images/plan/ubuntu_phpmyadmin.png" target="_blank">PHPMyAdmin</a></p>
<p>Total time to get everything installed and configured = 1.5 hours <img src='http://www.chrisbellini.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>EDIT (09.05.2006): If you're interested in learning how to install PHPMyAdmin on Ubuntu Linux, I've posted something explaining how to accomplish that <a href="http://www.chrisbellini.com/?p=527">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisbellini.com/2005/11/25/ubuntu-im-sold/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
