<?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>Sandeep Ghael</title>
	<atom:link href="http://sandeepghael.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sandeepghael.com</link>
	<description>acts_as_blog</description>
	<lastBuildDate>Mon, 23 Aug 2010 14:27:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Top 25 Universities (US News World Report) &amp; their FM Radio Stations</title>
		<link>http://sandeepghael.com/2010/08/top-25-universities-us-news-world-report-their-fm-radio-stations/</link>
		<comments>http://sandeepghael.com/2010/08/top-25-universities-us-news-world-report-their-fm-radio-stations/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 14:27:11 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=449</guid>
		<description><![CDATA[Harvard University WHRB Princeton University WPRB Yale University WYBC Columbia University WKCR Stanford University KZSU University of Pennsylvania WQHS California Institute of Technology W6UE Massachusetts Institute of Technology WMBR Dartmouth College WDCR Duke University WXDU University of Chicago WHPK Northwestern University WNUR Johns Hopkins University WJHU Washington University in St. Louis KWUR Brown University WELH [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Harvard University                                                       WHRB</li>
<li>Princeton University                                                    WPRB</li>
<li>Yale University                                                             WYBC</li>
<li>Columbia University                                                    WKCR</li>
<li>Stanford University                                                      KZSU</li>
<li>University of Pennsylvania                                         WQHS</li>
<li>California Institute of Technology                            W6UE</li>
<li>Massachusetts Institute of Technology                  WMBR</li>
<li>Dartmouth College                                                      WDCR</li>
<li>Duke University                                                            WXDU</li>
<li>University of Chicago                                                  WHPK</li>
<li>Northwestern University                                            WNUR</li>
<li>Johns Hopkins University                                           WJHU</li>
<li>Washington University in St. Louis                           KWUR</li>
<li>Brown University                                                          WELH</li>
<li>Cornell University                                                        WVBR</li>
<li><span style="color: #ff0000;">Rice University                                                             KTRU –for sale?!</span></li>
<li>Vanderbilt University                                                   WRVU</li>
<li>University of Notre Dame                                          WVFI</li>
<li>Emory University                                                          WMRE</li>
<li>Georgetown University                                               WGTB</li>
<li>University of California – Berkeley                          KALX</li>
<li>Carnegie Mellon University                                       WRCT</li>
<li>University of Southern California                             KSCR</li>
<li>University of California – Los Angeles                     UCLARadio.com  “UCLA&#8217;s student radio station was never officially licensed as an AM or FM station due to lack of support from university administration. Due to the difficulty of purchasing a band in Los Angeles&#8217; overcrowded frequency spectrum, the station is not currently considering purchasing one.” -wikipedia</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2010/08/top-25-universities-us-news-world-report-their-fm-radio-stations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nexus One portable hotspot speed &#8211; Android 2.2 Froyo + T-Mobile 3G</title>
		<link>http://sandeepghael.com/2010/05/nexus-one-portable-hotspot-speed-android-2-2-froyo-t-mobile-3g/</link>
		<comments>http://sandeepghael.com/2010/05/nexus-one-portable-hotspot-speed-android-2-2-froyo-t-mobile-3g/#comments</comments>
		<pubDate>Sun, 23 May 2010 23:11:53 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=415</guid>
		<description><![CDATA[Thru speed test of Nexus One Android (Froyo 2.2) &#8211; Wireless Hotspot tethering on T-Mobile 3G. Macbook Pro using Nexus One + Android 2.2 (Froyo) + T-mobile 3G: Macbook Pro using ATT DSL: [ author makes no claim on scientific nature of this testing ]]]></description>
			<content:encoded><![CDATA[<p>Thru speed test of Nexus One Android (Froyo 2.2) &#8211; Wireless Hotspot tethering on T-Mobile 3G.</p>
<p><strong>Macbook Pro using Nexus One + Android 2.2 (Froyo) + T-mobile 3G:</strong></p>
<p><a href="http://sandeepghael.com/wp-content/uploads/2010/05/Tmobile-3g.png"><img class="size-full wp-image-416 alignnone" title="Tmobile 3g" src="http://sandeepghael.com/wp-content/uploads/2010/05/Tmobile-3g.png" alt="" width="313" height="183" /></a></p>
<p><strong>Macbook Pro using ATT DSL:</strong></p>
<p><a href="http://sandeepghael.com/wp-content/uploads/2010/05/DSL.png"><img class="size-full wp-image-418 alignnone" title="DSL" src="http://sandeepghael.com/wp-content/uploads/2010/05/DSL.png" alt="" width="307" height="177" /></a></p>
<p>[ author makes no claim on scientific nature of this testing ]</p>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2010/05/nexus-one-portable-hotspot-speed-android-2-2-froyo-t-mobile-3g/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>the &#8220;Google Job Experiment&#8221;</title>
		<link>http://sandeepghael.com/2010/05/the-google-job-experiment/</link>
		<comments>http://sandeepghael.com/2010/05/the-google-job-experiment/#comments</comments>
		<pubDate>Tue, 18 May 2010 01:26:48 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=406</guid>
		<description><![CDATA[A dash of social engineering + Google ad words + $6. Brilliant.]]></description>
			<content:encoded><![CDATA[<p>A dash of social engineering + Google ad words + $6.   Brilliant.  </p>
<p><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/7FRwCs99DWg&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/7FRwCs99DWg&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2010/05/the-google-job-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TWiST 00 &#8211; Jason Clacanis on online marketing tactics</title>
		<link>http://sandeepghael.com/2010/05/397/</link>
		<comments>http://sandeepghael.com/2010/05/397/#comments</comments>
		<pubDate>Fri, 14 May 2010 16:51:17 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=397</guid>
		<description><![CDATA[Some pretty solid insight into SEO, SEM, email marketing and general online hustling tactics: http://thisweekin.com/thisweekin-startups/twist-interview-with-100-things/ As always, great story telling from Calacanis.]]></description>
			<content:encoded><![CDATA[<p>Some pretty solid insight into SEO, SEM, email marketing and general online hustling tactics:</p>
<p>http://thisweekin.com/thisweekin-startups/twist-interview-with-100-things/</p>
<p>As always, great story telling from Calacanis.</p>
<p><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/yIXQ5qc_uXc&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/yIXQ5qc_uXc&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2010/05/397/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Acts_as_voteable caching in Rails</title>
		<link>http://sandeepghael.com/2010/05/acts_as_voteable-caching-in-rails/</link>
		<comments>http://sandeepghael.com/2010/05/acts_as_voteable-caching-in-rails/#comments</comments>
		<pubDate>Mon, 03 May 2010 00:08:33 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=379</guid>
		<description><![CDATA[Suppose you want to show some votes for/against an object in your template (I&#8217;m using HAML markup). This query/calculation is particularly expensive, since it has to do a &#8220;count by&#8221; in SQL each time the view is called. And since I want both votes &#8220;for&#8221; and &#8220;against&#8221;, that&#8217;s minimum two queries for each object. Now [...]]]></description>
			<content:encoded><![CDATA[<p>Suppose you want to show some votes for/against an object in your template (I&#8217;m using HAML markup).  This query/calculation is particularly expensive, since it has to do a &#8220;count by&#8221; in SQL each time the view is called.  And since I want both votes &#8220;for&#8221; and &#8220;against&#8221;, that&#8217;s minimum two queries for each object.  Now imagine there is a table with 100 rows, each showing a vote &#8220;for&#8221; and &#8220;against&#8221;.  The queries quickly add up!  And even if your db data set is small, you still incur a big penalty making a round trip to the db each time you need that info.</p>
<p>I employed this super simple caching code to reduce follow on view code calls (the 1st one is required to &#8220;warm up&#8221; the cache) to 0 queries.  Using this code, we can store the entire votes for/against HTML snippet in your cache back end of choice (like memcached).  By connecting a cache expire method to the model&#8217;s after_save hook, we can ensure that the code block will always stay fresh.</p>
<p><strong>sometemplate.html.haml </strong>:</p>
<p><code class="codecolorer rails default cc-block"><span class="rails"><span style="color:#006600; font-weight:bold;">%</span>table<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>tr<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">%</span>td= show_verdicts_for<span style="color:#006600; font-weight:bold;">&#40;</span>myobject<span style="color:#006600; font-weight:bold;">&#41;</span></span></code></p>
<p><strong>myobject_helper.rb </strong>:</p>
<p><code class="codecolorer ruby default cc-block"><span class="ruby"><span style="color:#9966CC; font-weight:bold;">def</span> show_votes_for<span style="color:#006600; font-weight:bold;">&#40;</span>myobject<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; Rails.<span style="color:#9900CC;">cache</span>.<span style="color:#9900CC;">fetch</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'votes_fragment_'</span><span style="color:#006600; font-weight:bold;">+</span>myobject.<span style="color:#9900CC;">id</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#996600;">&quot;Votes for: &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> myobject.<span style="color:#9900CC;">votes_for</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span><br />
&nbsp; &nbsp; <span style="color:#996600;">&quot;Votes against: &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> myobject.<span style="color:#9900CC;">votes_against</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></span></code></p>
<p>Rails.cache.fetch is a handy call that first checks if there is anything in the cache with that key, and if so simply returns the cache contents.  If the key results in a miss, the code is remaining code is executed and stored at with that key.</p>
<p><strong>vote.rb </strong> (based on &#8220;acts as vote-able&#8221;)</p>
<p><code class="codecolorer ruby default cc-block"><span class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Vote <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> ActivityTracker<br />
&nbsp; belongs_to <span style="color:#ff3333; font-weight:bold;">:reviewer</span><br />
&nbsp; belongs_to <span style="color:#ff3333; font-weight:bold;">:voteable</span>, <span style="color:#ff3333; font-weight:bold;">:polymorphic</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">true</span><br />
<br />
&nbsp; tracks_unlinked_activities <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:voted</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; attr_accessible <span style="color:#ff3333; font-weight:bold;">:vote</span>, <span style="color:#ff3333; font-weight:bold;">:voteable</span>, <span style="color:#ff3333; font-weight:bold;">:voteable_id</span>, <span style="color:#ff3333; font-weight:bold;">:voteable_type</span>, <span style="color:#ff3333; font-weight:bold;">:reviewer</span>, <span style="color:#ff3333; font-weight:bold;">:reviewer_id</span><br />
<br />
&nbsp; after_save <span style="color:#ff3333; font-weight:bold;">:expire_votes_fragment_myobject</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> expire_votes_fragment_myobject<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">voteable_type</span> == <span style="color:#996600;">&quot;myobject&quot;</span><br />
&nbsp; &nbsp; &nbsp; Rails.<span style="color:#9900CC;">cache</span>.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'votes_fragment_'</span><span style="color:#006600; font-weight:bold;">+</span>myobject_id.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></span></code></p>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2010/05/acts_as_voteable-caching-in-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple Red5 start/stop script (Mac OSX ready)</title>
		<link>http://sandeepghael.com/2010/01/simple-red5-startstop-script-mac-osx-ready/</link>
		<comments>http://sandeepghael.com/2010/01/simple-red5-startstop-script-mac-osx-ready/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 17:49:05 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[MacOSX]]></category>
		<category><![CDATA[Red5]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=362</guid>
		<description><![CDATA[Notes: Make sure to create a writeable log file for red5 at &#8220;/var/log/red5.log&#8221;. Usage of the script is straightforward: &#8220;/etc/init.d/red5 start&#8221;. #! /bin/sh # Author: Sandeep Ghael # put these contents at: /etc/init.d/red5 # change red5 directory path below as necessary RED5_DIR=/usr/share/red5 start&#40;&#41; &#123; &#160; &#160;echo &#34;Starting Red5 Service&#34; &#160; &#160;sudo su root -c &#34;cd [...]]]></description>
			<content:encoded><![CDATA[<p>Notes:  Make sure to create a writeable log file for red5 at &#8220;/var/log/red5.log&#8221;.  Usage of the script is straightforward: &#8220;/etc/init.d/red5 start&#8221;.</p>
<p><code class="codecolorer bash default cc-block"><span class="bash"><span style="color: #666666; font-style: italic;">#! /bin/sh</span><br />
<span style="color: #666666; font-style: italic;"># Author: Sandeep Ghael</span><br />
<span style="color: #666666; font-style: italic;"># put these contents at: /etc/init.d/red5</span><br />
<span style="color: #666666; font-style: italic;"># change red5 directory path below as necessary</span><br />
<span style="color: #007800;">RED5_DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>red5<br />
<br />
start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting Red5 Service&quot;</span><br />
&nbsp; &nbsp;<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span> root <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;cd <span style="color: #007800;">$RED5_DIR</span>; ./red5.sh &gt; /var/log/red5.log &amp;&quot;</span><br />
&nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">return</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Shutting down red5&quot;</span><br />
&nbsp; &nbsp;<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span> root <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'killall red5 java'</span> &nbsp; <br />
&nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">return</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span><br />
&nbsp; &nbsp; start<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; start<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; stop<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; stop<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; restart<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; stop<br />
&nbsp; &nbsp; &nbsp; start<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: {start|stop|restart}&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span> &nbsp; &nbsp; &nbsp;<br />
<span style="color: #000000; font-weight: bold;">esac</span><br />
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$?</span></span></code></p>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2010/01/simple-red5-startstop-script-mac-osx-ready/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ruby Server monitoring scripts w/ email alerts</title>
		<link>http://sandeepghael.com/2009/10/ruby-server-monitoring-scripts-w-email-alerts/</link>
		<comments>http://sandeepghael.com/2009/10/ruby-server-monitoring-scripts-w-email-alerts/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 19:20:16 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=324</guid>
		<description><![CDATA[While working on several rails projects, I&#8217;ve found it useful to write a couple of scripts to monitor real-time server health. Basically, I&#8217;d like to automatically be notified by email if anything peculiar is occurring on the server. Two pretty obvious things to alert on are low disk space and high average load. While there [...]]]></description>
			<content:encoded><![CDATA[<p>While working on several rails projects, I&#8217;ve found it useful to write a couple of scripts to monitor real-time server health.  Basically, I&#8217;d like to automatically be notified by email if anything peculiar is occurring on the server.  Two pretty obvious things to alert on are <strong>low disk space</strong> and <strong>high average load</strong>.  While there are great tools out there like Munin/Nagios that will give you detailed instrumentation for your server, I just needed something lightweight that I could periodically cron.  These scripts are designed for use on Ubuntu 9.04.  YMMV.</p>
<h2>disk_usage.rb</h2>
<p>This script will email foo@example.com when the disk space left on either sda1 and sda2 falls below 5GB.  The threshold is just a variable you can change.  You can also add to or remove from the list of sda devices you want to monitor using the disks array.</p>
<p><code class="codecolorer ruby default cc-block"><span class="ruby"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'send_gmail'</span><br />
<br />
TO_EMAIL = <span style="color:#996600;">'foo@example.com'</span><br />
<br />
filesys = <span style="color:#996600;">`df -h`</span><br />
<br />
disks = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
disks.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; r = filesys<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span>sda<span style="color:#008000; font-style:italic;">#{i}\s+[\d\.]+[MG]\s+[\d\.]+[MG]\s+([\d\.]+[MG])/,1]</span><br />
&nbsp; message = <span style="color:#996600;">&quot;Low disk space on /sda#{i}: only #{r.to_i}GB remaining&quot;</span><br />
&nbsp; hsh=<span style="color:#006600; font-weight:bold;">&#123;</span>:to<span style="color:#006600; font-weight:bold;">=&gt;</span>TO_EMAIL, <span style="color:#ff3333; font-weight:bold;">:subject</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'Low disk space warning!'</span>, <span style="color:#ff3333; font-weight:bold;">:body</span><span style="color:#006600; font-weight:bold;">=&gt;</span>message<span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; SendGMail.<span style="color:#9900CC;">send_gmail</span><span style="color:#006600; font-weight:bold;">&#40;</span>hsh<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> r.<span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006666;">5</span> <span style="color:#9966CC; font-weight:bold;">or</span> r<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span>M$<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> message <span style="color:#9966CC; font-weight:bold;">if</span> r.<span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006666;">5</span> <span style="color:#9966CC; font-weight:bold;">or</span> r<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span>M$<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></span></code></p>
<h2>load_check.rb</h2>
<p>This script will use the uptime command to get the avarage load.  I&#8217;m just using the 1min and 5min averages.  If the 1min average load is over 9 or the 5min average load is over 4, bar@example.com will get an email.</p>
<p><code class="codecolorer ruby default cc-block"><span class="ruby"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'send_gmail'</span><br />
<br />
TO_EMAIL = <span style="color:#996600;">'bar@example.com'</span><br />
<br />
uptime = <span style="color:#996600;">`uptime`</span><br />
<br />
load_1min = uptime.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot; &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">8</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">chop</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
load_5min = uptime.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot; &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">chop</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
message = <span style="color:#996600;">&quot;Load on server is 1min/5min avg: #{load_1min} / #{load_5min} &quot;</span><br />
<br />
hsh=<span style="color:#006600; font-weight:bold;">&#123;</span>:to<span style="color:#006600; font-weight:bold;">=&gt;</span>TO_EMAIL, <span style="color:#ff3333; font-weight:bold;">:subject</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'Load warning!'</span>, <span style="color:#ff3333; font-weight:bold;">:body</span><span style="color:#006600; font-weight:bold;">=&gt;</span>message<span style="color:#006600; font-weight:bold;">&#125;</span><br />
SendGMail.<span style="color:#9900CC;">send_gmail</span><span style="color:#006600; font-weight:bold;">&#40;</span>hsh<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>load_1min.<span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">or</span> <span style="color:#006600; font-weight:bold;">&#40;</span>load_5min.<span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#41;</span></span></code></p>
<p>You may have noticed an included module &#8220;send_gmail&#8221; and a call to &#8220;SendGMail&#8221; in the previous scripts.  Since I use Gmail for all my outbound emails, the underlying alert system needs a way to make calls to the Gmail servers.  Problem solved using this nifty little Ruby Gmailer script I found on at <a href="http://codingfrenzy.alexpmay.com/2007/12/sending-gmail-from-standalone-ruby.html">http://codingfrenzy.alexpmay.com/2007/12/sending-gmail-from-standalone-ruby.html</a>.  I did make a few modifications to the script, so I&#8217;m including it here.  You&#8217;ll want to set your gmail account/domain info if you do use this mailer.</p>
<h2>send_gmail.rb</h2>
<p><code class="codecolorer ruby default cc-block"><span class="ruby"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<br />
gem <span style="color:#996600;">'actionmailer'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'action_mailer'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'openssl'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'net/smtp'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">module</span> SendGMail<br />
<br />
<span style="color:#0066ff; font-weight:bold;">@user_name</span>=<span style="color:#996600;">'someone@example.com'</span><br />
<span style="color:#0066ff; font-weight:bold;">@domain</span>=<span style="color:#996600;">'example.com'</span><br />
<span style="color:#0066ff; font-weight:bold;">@password</span>=<span style="color:#996600;">'password'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">def</span> SendGMail.<span style="color:#9900CC;">send_gmail</span><span style="color:#006600; font-weight:bold;">&#40;</span>hsh<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
raw_attachments=hsh.<span style="color:#9900CC;">fetch</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:raw_attachements</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#9966CC; font-weight:bold;">if</span> hsh.<span style="color:#9900CC;">has_key</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:raw_attachment</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;raw_attachments.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span>hsh<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:raw_attachment</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
mail=<span style="color:#6666ff; font-weight:bold;">TMail::Mail</span>.<span style="color:#9900CC;">new</span><br />
mail.<span style="color:#9900CC;">to</span>=hsh<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:to</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
mail.<span style="color:#9900CC;">date</span>=<span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span><br />
mail.<span style="color:#9900CC;">from</span>=@user_name<br />
mail.<span style="color:#9900CC;">subject</span>=hsh<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:subject</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
main=mail<br />
main=<span style="color:#6666ff; font-weight:bold;">TMail::Mail</span>.<span style="color:#9900CC;">new</span><br />
main.<span style="color:#9900CC;">body</span> = hsh<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:body</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
main.<span style="color:#9900CC;">set_content_type</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'text/plain'</span>, <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#996600;">'charset'</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'utf-8'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
mail.<span style="color:#9900CC;">parts</span>.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">for</span> raw_attachment <span style="color:#9966CC; font-weight:bold;">in</span> raw_attachments<br />
&nbsp;part = <span style="color:#6666ff; font-weight:bold;">TMail::Mail</span>.<span style="color:#9900CC;">new</span><br />
&nbsp;transfer_encoding=raw_attachment<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:transfer_encoding</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp;body=raw_attachment<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:body</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp;<span style="color:#9966CC; font-weight:bold;">case</span> <span style="color:#006600; font-weight:bold;">&#40;</span>transfer_encoding <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">downcase</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;base64&quot;</span> <span style="color:#9966CC; font-weight:bold;">then</span><br />
&nbsp; &nbsp; &nbsp;part.<span style="color:#9900CC;">body</span> = TMail::<span style="color:#CC00FF; font-weight:bold;">Base64</span>.<span style="color:#9900CC;">folding_encode</span><span style="color:#006600; font-weight:bold;">&#40;</span>body<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;quoted-printable&quot;</span><br />
&nbsp; &nbsp; &nbsp;part.<span style="color:#9900CC;">body</span> = <span style="color:#006600; font-weight:bold;">&#91;</span>body<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">pack</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;M*&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp;part.<span style="color:#9900CC;">body</span> = body<br />
&nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <br />
&nbsp;part.<span style="color:#9900CC;">transfer_encoding</span> = transfer_encoding<br />
&nbsp;part.<span style="color:#9900CC;">set_content_type</span><span style="color:#006600; font-weight:bold;">&#40;</span>raw_attachment<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:mime_type</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#996600;">'name'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> raw_attachment<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:filename</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;part.<span style="color:#9900CC;">set_content_disposition</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;attachment&quot;</span>, <span style="color:#996600;">&quot;filename&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>raw_attachment<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:filename</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;mail.<span style="color:#9900CC;">parts</span>.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span>part<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
mail.<span style="color:#9900CC;">set_content_type</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'multipart'</span>, <span style="color:#996600;">'mixed'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <br />
<span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>.<span style="color:#9900CC;">deliver</span><span style="color:#006600; font-weight:bold;">&#40;</span>mail<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>.<span style="color:#9900CC;">smtp_settings</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><br />
<span style="color:#ff3333; font-weight:bold;">:address</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'smtp.gmail.com'</span>,<br />
<span style="color:#ff3333; font-weight:bold;">:domain</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@domain</span>,<br />
<span style="color:#ff3333; font-weight:bold;">:authentication</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:plain</span>,<br />
<span style="color:#ff3333; font-weight:bold;">:port</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">587</span>,<br />
<span style="color:#ff3333; font-weight:bold;">:user_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@user_name</span>,<br />
<span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@password</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<span style="color:#6666ff; font-weight:bold;">Net::SMTP</span>.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
private<br />
<span style="color:#9966CC; font-weight:bold;">def</span> do_start<span style="color:#006600; font-weight:bold;">&#40;</span>helodomain, user, secret, authtype<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;<span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">IOError</span>, <span style="color:#996600;">'SMTP session already started'</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@started</span><br />
&nbsp;check_auth_args user, secret <span style="color:#9966CC; font-weight:bold;">if</span> user <span style="color:#9966CC; font-weight:bold;">or</span> secret<br />
<br />
&nbsp;sock = timeout<span style="color:#006600; font-weight:bold;">&#40;</span>@open_timeout<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> TCPSocket.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>@address, <span style="color:#0066ff; font-weight:bold;">@port</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp;<span style="color:#0066ff; font-weight:bold;">@socket</span> = <span style="color:#6666ff; font-weight:bold;">Net::InternetMessageIO</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>sock<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;<span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">read_timeout</span> = <span style="color:#006666;">60</span> <span style="color:#008000; font-style:italic;">#@read_timeout</span><br />
&nbsp;<span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">debug_output</span> = STDERR <span style="color:#008000; font-style:italic;">#@debug_output</span><br />
<br />
&nbsp;check_response<span style="color:#006600; font-weight:bold;">&#40;</span>critical <span style="color:#006600; font-weight:bold;">&#123;</span> recv_response<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;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;do_helo<span style="color:#006600; font-weight:bold;">&#40;</span>helodomain<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp;<span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">'openssl library not installed'</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#9966CC; font-weight:bold;">defined</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>OpenSSL<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;starttls<br />
&nbsp;ssl = <span style="color:#6666ff; font-weight:bold;">OpenSSL::SSL::SSLSocket</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>sock<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;ssl.<span style="color:#9900CC;">sync_close</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
&nbsp;ssl.<span style="color:#9900CC;">connect</span><br />
&nbsp;<span style="color:#0066ff; font-weight:bold;">@socket</span> = <span style="color:#6666ff; font-weight:bold;">Net::InternetMessageIO</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>ssl<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;<span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">read_timeout</span> = <span style="color:#006666;">60</span> <span style="color:#008000; font-style:italic;">#@read_timeout</span><br />
&nbsp;<span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">debug_output</span> = STDERR <span style="color:#008000; font-style:italic;">#@debug_output</span><br />
&nbsp;do_helo<span style="color:#006600; font-weight:bold;">&#40;</span>helodomain<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp;authenticate user, secret, authtype <span style="color:#9966CC; font-weight:bold;">if</span> user<br />
&nbsp;<span style="color:#0066ff; font-weight:bold;">@started</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
<span style="color:#9966CC; font-weight:bold;">ensure</span><br />
&nbsp;<span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@started</span><br />
&nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># authentication failed, cancel connection.</span><br />
&nbsp; &nbsp; &nbsp;<span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">close</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">not</span> <span style="color:#0066ff; font-weight:bold;">@started</span> <span style="color:#9966CC; font-weight:bold;">and</span> <span style="color:#0066ff; font-weight:bold;">@socket</span> <span style="color:#9966CC; font-weight:bold;">and</span> <span style="color:#9966CC; font-weight:bold;">not</span> <span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">closed</span>?<br />
&nbsp; &nbsp;<span style="color:#0066ff; font-weight:bold;">@socket</span> = <span style="color:#0000FF; font-weight:bold;">nil</span><br />
&nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">def</span> do_helo<span style="color:#006600; font-weight:bold;">&#40;</span>helodomain<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">begin</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@esmtp</span><br />
&nbsp; &nbsp; &nbsp;ehlo helodomain<br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp;helo helodomain<br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp;<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">Net::ProtocolError</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@esmtp</span><br />
&nbsp; &nbsp; &nbsp;<span style="color:#0066ff; font-weight:bold;">@esmtp</span> = <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; &nbsp;<span style="color:#0066ff; font-weight:bold;">@error_occured</span> = <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">retry</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp;<span style="color:#CC0066; font-weight:bold;">raise</span><br />
&nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">def</span> starttls<br />
&nbsp;getok<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'STARTTLS'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">def</span> quit<br />
&nbsp;<span style="color:#9966CC; font-weight:bold;">begin</span><br />
&nbsp; &nbsp;getok<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'QUIT'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">EOFError</span>, <span style="color:#6666ff; font-weight:bold;">OpenSSL::SSL::SSLError</span><br />
&nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></span></code></p>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2009/10/ruby-server-monitoring-scripts-w-email-alerts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ultimate Snow Leopard Web Development machine (part 3) &#8211; Databases</title>
		<link>http://sandeepghael.com/2009/10/ultimate-snow-leopard-web-development-machine-part-3-databases/</link>
		<comments>http://sandeepghael.com/2009/10/ultimate-snow-leopard-web-development-machine-part-3-databases/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 18:37:28 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MacOSX]]></category>
		<category><![CDATA[64bit]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Postgres]]></category>
		<category><![CDATA[Snow Leopard]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=295</guid>
		<description><![CDATA[Depending on the webapp project I&#8217;m working on, I flip back and forth between MySQL and PostgresSQL, generally using Postgres for anything that needs spatial or mapping related functionality. One pain point I encountered with Snow Leopard is getting everything compiled for true 64bit, and then getting the appropriate bindings for MySQL or Postgres to [...]]]></description>
			<content:encoded><![CDATA[<p>Depending on the webapp project I&#8217;m working on, I flip back and forth between MySQL and PostgresSQL, generally using Postgres for anything that needs spatial or mapping related functionality.</p>
<p>One pain point I encountered with Snow Leopard is getting everything compiled for true 64bit, and then getting the appropriate bindings for MySQL or Postgres to work with frameworks like Rails (Ruby) or Django (Python).  I work with both, so by the end of the post you&#8217;ll be prepared to use both DB servers for either framework.</p>
<h1>Step 1: Install MySQL from source</h1>
<p>We refer here, again to the excellent tutorial from HiveLogic:</p>
<p><a href="http://hivelogic.com/articles/compiling-mysql-on-snow-leopard/"> http://hivelogic.com/articles/compiling-mysql-on-snow-leopard/</a></p>
<p>After completing the install, set up your root password:</p>
<p><code class="codecolorer bash default cc-block"><span class="bash">$ mysqladmin <span style="color: #660033;">-u</span> root password NEWPASSWORD</span></code></p>
<h1>Step 2: Install PostgreSQL from source</h1>
<p>As for Postgres, I found these instructions found on InvisionPower as a good basis to start my install from. </p>
<p><a href="http://community.invisionpower.com/topic/292849-installing-postgresql-server-on-mac-os-x-snow-leopard/">http://community.invisionpower.com/topic/292849-installing-postgresql-server-on-mac-os-x-snow-leopard/</a></p>
<p>Couple of note regarding Postgres.</p>
<p>1) the instructions in the link above seem to provide a dead link for the Postgres source.  You can <strong>try this curl command instead of theirs</strong>:</p>
<p><code class="codecolorer bash default cc-block"><span class="bash">$ curl http:<span style="color: #000000; font-weight: bold;">//</span>ftp9.us.postgresql.org<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>mirrors<span style="color: #000000; font-weight: bold;">/</span>postgresql<span style="color: #000000; font-weight: bold;">/</span>source<span style="color: #000000; font-weight: bold;">/</span>v8.4.1<span style="color: #000000; font-weight: bold;">/</span>postgresql-8.4.1.tar.gz <span style="color: #660033;">-O</span></span></code></p>
<p>2) <strong>Make sure to compile as a 64 bit application</strong>, using the &#8220;ARCH=x86_64&#8243; and other flags specified during your &#8220;make&#8221; step.</p>
<p>3) when creating and setting user/group info, I found an error in the 8th command line instructions.  The original command references a group &#8220;_postgres&#8221; before it has been created.  Do this instead:</p>
<p>Enough changes were required to make things compile and work on my new system, that I&#8217;ll simply transcribe my exact steps here: </p>
<p><code class="codecolorer bash default cc-block"><span class="bash">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src<br />
$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>src<br />
<br />
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span><br />
<br />
$ curl http:<span style="color: #000000; font-weight: bold;">//</span>ftp9.us.postgresql.org<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>mirrors<span style="color: #000000; font-weight: bold;">/</span>postgresql<span style="color: #000000; font-weight: bold;">/</span>source<span style="color: #000000; font-weight: bold;">/</span>v8.4.1<span style="color: #000000; font-weight: bold;">/</span>postgresql-8.4.1.tar.gz <span style="color: #660033;">-O</span><br />
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zvxf</span> postgresql-8.4.1.tar.gz<br />
$ <span style="color: #c20cb9; font-weight: bold;">rm</span> postgresql-8.4.1.tar.gz<br />
$ <span style="color: #7a0874; font-weight: bold;">cd</span> postgresql-8.4.1<br />
<br />
$ .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>postgresql-8.4.1<br />
<br />
$ <span style="color: #007800;">ARCH</span>=x86_64 <span style="color: #007800;">CFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64&quot;</span> <span style="color: #007800;">LDFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64&quot;</span> <span style="color: #c20cb9; font-weight: bold;">make</span><br />
$ <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span><br />
<br />
$ <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>postgresql-8.4.1 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<br />
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;PATH=/usr/local/pgsql/bin:<span style="color: #007800;">$PATH</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.profile<br />
$ <span style="color: #7a0874; font-weight: bold;">source</span> ~<span style="color: #000000; font-weight: bold;">/</span>.profile<br />
$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span><br />
<br />
$ dscl . list <span style="color: #000000; font-weight: bold;">/</span>Users UniqueID</span></code></p>
<p>I use &#8221; dscl . list /Users UniqueID | grep <##>&#8221; to find the first available number past 75.  For me it was 80.</p>
<p><code class="codecolorer bash default cc-block"><span class="bash">$ dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_postgres<br />
$ dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_postgres PrimaryGroupID <span style="color: #000000;">0</span><br />
$ dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_postgres UniqueID <span style="color: #000000;">80</span><br />
$ dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_postgres UserShell <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span><br />
$ dscl localhost <span style="color: #c20cb9; font-weight: bold;">passwd</span> <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_postgres<br />
$ dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_postgres NFSHomeDirectory <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>_postgres<br />
$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>_postgres<br />
$ <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-Rf</span> _postgres <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>_postgres<br />
$ dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Groups<span style="color: #000000; font-weight: bold;">/</span>_postgres<br />
$ dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Groups<span style="color: #000000; font-weight: bold;">/</span>_postgres UniqueID <span style="color: #000000;">80</span><br />
$ dscl localhost append <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Groups<span style="color: #000000; font-weight: bold;">/</span>_postgres GroupMembership _postgres<br />
$ <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-Rf</span> _postgres:_postgres <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>_postgres<br />
<br />
$ defaults <span style="color: #c20cb9; font-weight: bold;">write</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Preferences<span style="color: #000000; font-weight: bold;">/</span>com.apple.loginwindow.plist Hide500Users <span style="color: #660033;">-bool</span> TRUE<br />
$ <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> _postgres <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>postgresql-8.4.1<span style="color: #000000; font-weight: bold;">/</span></span></code></p>
<p>I did not exit su at this point, as suggested in the original InvisionPower article.  I needed to be su to change to user &#8220;_postgres&#8221;.</p>
<p><code class="codecolorer bash default cc-block"><span class="bash">$ <span style="color: #c20cb9; font-weight: bold;">su</span> - _postgres<br />
$ <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>initdb <span style="color: #660033;">-E</span> UTF8 <span style="color: #660033;">-D</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span><br />
$ <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_ctl <span style="color: #660033;">-D</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>postgresql.log start</span></code></p>
<p>Now test creating a new DB:</p>
<p><code class="codecolorer bash default cc-block"><span class="bash">$ <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>createdb <span style="color: #7a0874; font-weight: bold;">test</span><br />
$ <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>psql <span style="color: #7a0874; font-weight: bold;">test</span></span></code></p>
<p>Type \q to quit.</p>
<p><code class="codecolorer bash default cc-block"><span class="bash">$ <span style="color: #7a0874; font-weight: bold;">exit</span><br />
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span><br />
$ <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>home<br />
$ dscl localhost delete <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_postgres NFSHomeDirectory<br />
$ dscl localhost <span style="color: #c20cb9; font-weight: bold;">passwd</span> <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_postgres<br />
$ <span style="color: #7a0874; font-weight: bold;">exit</span></span></code></p>
<p>At this point your server is installed and tested.  The InvisionPower post provides a great script that you can use to start/stop/restart the server from the command line.  See the bottom of <a href="http://community.invisionpower.com/topic/292849-installing-postgresql-server-on-mac-os-x-snow-leopard/">their article.</a></p>
<p><em></em></p>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2009/10/ultimate-snow-leopard-web-development-machine-part-3-databases/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Ultimate Snow Leopard Web Development machine (part 2) &#8211; Command Line tweaks</title>
		<link>http://sandeepghael.com/2009/10/ultimate-snow-leopard-web-development-machine-part-2-command-line-tweaks/</link>
		<comments>http://sandeepghael.com/2009/10/ultimate-snow-leopard-web-development-machine-part-2-command-line-tweaks/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 22:50:04 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[MacOSX]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=256</guid>
		<description><![CDATA[In part one of this series, we covered the very basics of doing a clean install of Snow Leopard, including the XCode SDK packages, and installing version control tool Git. Today we&#8217;ll cover setting up your CLI (command line interface). Tweak the CLI If you have any hair on your chest (apologies to my female [...]]]></description>
			<content:encoded><![CDATA[<p>In part one of this series, we covered the very basics of doing a clean install of Snow Leopard, including the XCode SDK packages, and installing version control tool Git.  Today we&#8217;ll cover setting up your CLI (command line interface).</p>
<h1>Tweak the CLI</h1>
<p>If you have any hair on your chest (apologies to my female readers), you&#8217;re going to be using the command line a lot.  Let&#8217;s make the CLI more friendly for daily use.  I used this excellent thread from StackOverflow to compose my .profile file:  <a href="http://stackoverflow.com/questions/3746/whats-in-your-bashrc">http://stackoverflow.com/questions/3746/whats-in-your-bashrc</a>.</p>
<p>Things are a bit confusing in MacOS X world, since there is a .profile file in your home directory, but there is also a bashrc file in /private/etc.  As far as I can tell, best practice is to put user specific stuff in .profile, and put global stuff in /private/etc/bashrc.</p>
<p>To edit bashrc, use the sudo command and enter your password.</p>
<p><code class="codecolorer bash default cc-block"><span class="bash">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>bashrc</span></code></p>
<p>Since I want colorized prompt for all users, my /private/etc/bashrc file looks like</p>
<p><code class="codecolorer bash default cc-block"><span class="bash"><span style="color: #666666; font-style: italic;"># System-wide .bashrc file for interactive bash(1) shells.</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PS1</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #7a0874; font-weight: bold;">return</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #007800;">WHITE</span>=<span style="color: #ff0000;">&quot;\[\033[1;37m\]&quot;</span><br />
<span style="color: #007800;">GREEN</span>=<span style="color: #ff0000;">&quot;\[\033[0;32m\]&quot;</span><br />
<span style="color: #007800;">CYAN</span>=<span style="color: #ff0000;">&quot;\[\033[0;36m\]&quot;</span><br />
<span style="color: #007800;">GRAY</span>=<span style="color: #ff0000;">&quot;\[\033[0;37m\]&quot;</span><br />
<span style="color: #007800;">BLUE</span>=<span style="color: #ff0000;">&quot;\[\033[0;34m\]&quot;</span><br />
<span style="color: #007800;">BLACK</span>=<span style="color: #ff0000;">&quot;\[\033[0;1m\]&quot;</span><br />
<span style="color: #007800;">RESET</span>=<span style="color: #ff0000;">'\[\033[00m\]'</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${GREEN}</span>\u<span style="color: #007800;">${CYAN}</span>@<span style="color: #007800;">${BLUE}</span>\h:<span style="color: #007800;">${CYAN}</span>\w<span style="color: #007800;">${GREEN}</span> &amp;gt;$ <span style="color: #007800;">${RESET}</span>&quot;</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CLICOLOR</span>=<span style="color: #000000;">1</span><br />
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LSCOLORS</span>=ExFxCxDxBxegedabagacad<br />
<br />
<span style="color: #666666; font-style: italic;"># Make bash check its window size after a process completes</span><br />
<span style="color: #7a0874; font-weight: bold;">shopt</span> <span style="color: #660033;">-s</span> checkwinsize</span></code></p>
<p>The next time you open a command prompt things will be more readable.</p>
<p>Now lets edit your user specific .profile file :</p>
<p><code class="codecolorer bash default cc-block"><span class="bash">$ <span style="color: #c20cb9; font-weight: bold;">nano</span> ~<span style="color: #000000; font-weight: bold;">/</span>.profile</span></code></p>
<p>and make the contents as such:</p>
<p><code class="codecolorer bash default cc-block"><span class="bash"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTCONTROL</span>=erasedups<br />
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTSIZE</span>=<span style="color: #000000;">10000</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">bind</span> <span style="color: #ff0000;">'set match-hidden-files off'</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">cds</span>=<span style="color: #ff0000;">&quot;cd;clear&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">alias</span> cd..=<span style="color: #ff0000;">&quot;cd ..&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">alias</span> ..=<span style="color: #ff0000;">&quot;cd ..&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">alias</span> ...=<span style="color: #ff0000;">&quot;cd ../..&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">alias</span> ....=<span style="color: #ff0000;">&quot;cd ../../..&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">ll</span>=<span style="color: #ff0000;">&quot;ls -al&quot;</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:<span style="color: #007800;">$PATH</span>&quot;</span></span></code></p>
<p>This sets some bash history parameters, and my personal aliases for commonly used commands.  YMMV.  We&#8217;ll continue to tweak the .profile file as we continue, but for now let&#8217;s proceed to installing databases (Next Post)</p>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2009/10/ultimate-snow-leopard-web-development-machine-part-2-command-line-tweaks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ultimate Snow Leopard Web Development machine (part 1)</title>
		<link>http://sandeepghael.com/2009/10/ultimate-snow-leopard-web-development-machine-part-1/</link>
		<comments>http://sandeepghael.com/2009/10/ultimate-snow-leopard-web-development-machine-part-1/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 20:46:27 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[MacOSX]]></category>
		<category><![CDATA[GIT]]></category>
		<category><![CDATA[Snow Leopard]]></category>
		<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=152</guid>
		<description><![CDATA[Like many people, I recently upgraded my MacBook to Snow Leopard. While Mac OS X updates are mostly innocuous, Snow Leopard was a bit trickier.  Moving to the 64bit ready OS meant that some key technologies like Ruby and Python, that I use extensively for my work, didn&#8217;t quite work right after the upgrade cycle.  [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-210" title="SL1-photo1" src="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo1.jpg" alt="SL1-photo1" width="130" height="175" />Like many people, I recently upgraded my MacBook to Snow Leopard.  While Mac OS X updates are mostly innocuous, Snow Leopard was a bit trickier.   Moving to the 64bit ready OS meant that some key technologies like Ruby and Python, that I use extensively for my work, didn&#8217;t quite work right after the upgrade cycle.  With Snow Leopard,  I found it easier to back up all my info using <a href="http://www.shirt-pocket.com/SuperDuper/SuperDuperDescription.html" target="_blank">SuperDuper</a>,  and perform a clean install (not on top of previous OS) .  Then I compiled and installing many of my tools from scratch.   Several tricky issues, especially related to Python/MySQL bindings, magically started working after this clean install.   It took a few days of Google research and trial/error, but after a few days of annoying hacking at the new OS, I&#8217;ve converged on an &#8220;ultimate&#8221; Snow Leopard web-dev setup.</p>
<p>In the next few post, I&#8217;ll be documenting the steps I took on my box.  FYI, my box is an Intel based (Core 2 Duo) White MacBook 13&#8243;, 2Ghz with 4GB of Ram.  The screen shots are from the same steps done on an iMac with similar specs.</p>
<h1>Step 1:  Backup all data</h1>
<p>Any upgrade process is fraught with catastrophic risk, so please back up all your data.  You should already be using something like Time Machine, so make sure its has done a recent backup of your critical data directories.  For something like an upgrade, I prefer to also use  a tool like &#8220;SuperDuper!&#8221; which makes a clone (entire disk snapshot) to another drive.  This assumes you have an extra drive laying around, but drives are cheap and your work is not.  So take the extra precaution and feel safe knowing you can always just pop in your cloned disk and it&#8217;s as if nothing happened.</p>
<h1>Step 2:  Install Snow Leopard</h1>
<p>Well, duh!  But one key thing to note when doing either a clean, or non-clean install of Snow Leopard is to make sure you are installing all the necessary SDK packages that will allow you to compile other packages like Python or MySQL successfully for 64bit.  We&#8217;ll get to that in a bit.</p>
<p>First the routine stuff:  Pop in the Snow Leopard disk.  Hold down the &#8220;option&#8221; key during the boot to have your Mac ask you what disk to install from.  (see image)</p>
<p>Choose the Mac OS X Install disk.  As mentioned, we are doing a clean install, so we&#8217;ll first format the drive clean (you did do Step 1, right?).  Choose &#8220;Disk Utility&#8221; before the install starts.  Choose your drive, and click on the &#8220;Erase&#8221; tab.  Format the drive &#8220;Mac OS Extended (Journaled), and name the drive whatever (&#8220;iMac2&#8243; is my imaginative name).</p>
<p>Running through the rest of the installer is pretty straightforward.  If you are particular and want to save a few MB, you can click on &#8220;customize&#8221; during the process and un-check all the languages that you are not going to use.  The install process took about 30 mins to complete.</p>
<p><a href="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo2.jpg"><img class="alignnone size-full wp-image-211" title="SL1-photo2" src="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo2.jpg" alt="SL1-photo2" width="160" height="120" /></a><a href="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo3.jpg"><img class="size-full wp-image-212 alignnone" title="SL1-photo3" src="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo3.jpg" alt="SL1-photo3" width="160" height="120" /></a><a href="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo4.jpg"><img class="alignnone size-full wp-image-213" title="SL1-photo4" src="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo4.jpg" alt="SL1-photo4" width="160" height="119" /></a><a href="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo5.jpg"><img class="alignnone size-full wp-image-214" title="SL1-photo5" src="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo5.jpg" alt="SL1-photo5" width="160" height="120" /></a><a href="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo7.jpg"><img class="alignnone size-full wp-image-216" title="SL1-photo7" src="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo7.jpg" alt="SL1-photo7" width="160" height="120" /></a></p>
<h1>Step 3:  Update OS X</h1>
<p>The latest version of Mac OS X, as of this entry, is 10.6.1.  Let the OS software update manager do its thing.</p>
<p><a href="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo9.jpg"><img class="alignnone size-full wp-image-217" title="SL1-photo9" src="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo9.jpg" alt="SL1-photo9" width="160" height="120" /></a></p>
<h1>Step 4:  Install additional XCode SDK packages</h1>
<p>After updating and restarting the computer, open the installer disk and find the &#8220;Optional Installs&#8221; directory.  Open the XCode installer.  XCode will provide some very basic builing tools for 10.6.. stuff like gcc and the appropriate header files to build just about anything from source.  <strong>One thing that is absolutely essential is including &#8220;Mac OS X 10.4 Support&#8221; (see last image).  This is not clicked on by default.</strong> I&#8217;ve found that some source packages won&#8217;t build if they cannot find header files provided by this support package.</p>
<p><a href="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo10.jpg"><img class="alignnone size-full wp-image-218" title="SL1-photo10" src="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo10.jpg" alt="SL1-photo10" width="160" height="120" /></a><a href="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo11.jpg"><img class="alignnone size-full wp-image-219" title="SL1-photo11" src="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo11.jpg" alt="SL1-photo11" width="160" height="120" /></a><a href="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo12.jpg"><img class="alignnone size-full wp-image-220" title="SL1-photo12" src="http://sandeepghael.com/wp-content/uploads/2009/10/SL1-photo12.jpg" alt="SL1-photo12" width="160" height="120" /></a></p>
<h1>Step 5:  Install Git and Subversion</h1>
<p>If you do any serious development, of any sort, you&#8217;re going to be using version control (if you are sane).</p>
<p>The new school kids are using Git, but there are still plenty of things hosted with Subversion.  So besides needing either to source control your own projects, you&#8217;re going to want these tools to grab latest code (i.e. trunk) for lots of cool stuff like Python, Ruby Gems, etc.</p>
<h3>Install Git</h3>
<p>For various reasons, you are probably better off compiling Git from source.  Don&#8217;t worry, it&#8217;s not painful at all, but does assume some familiarity with using the Terminal/ Command line interface.  If you can follow instructions, you can do this.</p>
<p>Follow these awesomely documented instructions from HiveLogic: <a href="http://hivelogic.com/articles/compiling-git-on-snow-leopard/" target="_blank">http://hivelogic.com/articles/compiling-git-on-snow-leopard/</a></p>
<p>One thing to note:  you can grab the most recent stable version of Git, instead of the exact one mentioned in the HiveLogic article.  Check the repo here and find the latest version  <a href="http://kernel.org/pub/software/scm/git/ " target="_blank">http://kernel.org/pub/software/scm/git/ </a> (use the .tar.bz file).  Also since you just clean installed this computer, you probably don&#8217;t have TextMate, so use &#8220;nano&#8221; from terminal to edit your .profile file as needed</p>
<p>After you confirm that Git is installed correctly, you can also installed GitX which is a great Git &#8220;repo browser&#8221; specifically for OS X.  You can grab it here:  <a href="http://gitx.frim.nl/" target="_blank">http://gitx.frim.nl/</a> .  You probably won&#8217;t use it anytime soon, but you&#8217;ll thank me later.</p>
<h3>Install Subversion</h3>
<p>This is the easiest step here, because it&#8217;s already done for you!  Mac OS comes with Subversion, and while it&#8217;s not the very latest version, it will work just fine.  Type &#8220;which svn&#8221; to see that Subversion lives at &#8220;/usr/bin/svn&#8221;.   &#8220;svn &#8211;version&#8221; shows &#8220;version 1.6.2&#8243;</p>
<p>&#8212;</p>
<p>In &#8220;Ultimate Snow Leopard Web Development machine&#8221; Part 2, we&#8217;ll cover setting up your CLI and installing databases!</p>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2009/10/ultimate-snow-leopard-web-development-machine-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
