<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Daddy Fixes Everything</title>
	
	<link>http://blog.spoolz.com</link>
	<description>A father and programmer's skewed view of the world</description>
	<lastBuildDate>Sun, 26 Apr 2009 03:29:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DaddyFixesEverything" /><feedburner:info uri="daddyfixeseverything" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Monitor Your Elk-M1, Log to MySQL, and Daemonize it!</title>
		<link>http://feedproxy.google.com/~r/DaddyFixesEverything/~3/0m_l_iHd0sA/</link>
		<comments>http://blog.spoolz.com/2009/04/25/monitor-your-elk-m1-log-to-mysql-and-daemonize-it/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 03:29:43 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[Home Automation]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[daemon]]></category>
		<category><![CDATA[elk]]></category>

		<guid isPermaLink="false">http://blog.spoolz.com/?p=188</guid>
		<description><![CDATA[I received a request a couple of days ago from someone who saw my posts on the Elk&#8211;Control perl library that I took over responsibility for. I had mentioned that I logged every Elk event into a MySQL database.
I am happy to report that I have this script running as a daemon, logging every ElkM1 [...]]]></description>
			<content:encoded><![CDATA[<p>I received a request a couple of days ago from someone who saw my posts on the <a href="http://blog.spoolz.com/2009/01/30/elk-m1-security-system-control-with-perl-script/">Elk&#8211;Control</a> perl library that I took over responsibility for. I had mentioned that I logged every Elk event into a MySQL database.</p>
<p>I am happy to report that I have this script running as a daemon, logging every ElkM1 event into my database. And it runs for months without issue.</p>
<p>I will keep these instructions brief. If you have detailed questions, please ask in the comments and I&#8217;ll help the best I can.</p>
<h3>Download</h3>
<p>You can download all the scirpts, <a href='http://blog.spoolz.com/wp-content/uploads/2009/04/elk_mysql_scripts.zip'>just click here</a>.</p>
<h3>Notables</h3>
<ol>
<li>If you don&#8217;t know a least a little perl and some MySQL basics, you may want to look elsewhere.</li>
<li>The script and accompanying files are designed to work in concert as a daemonized process.</li>
<li>Everything is logged into &#8216;elk_monitor.log&#8217; in the same directory (or directory of your choosing) as the script. If you have a lot of passive infra-red motion detectors, you will want to monitor the log size.
</ol>
<h3>Basic File Structure</h3>
<p><img src="http://blog.spoolz.com/wp-content/uploads/2009/04/picture-13.png" alt="file structure" title="file structure" width="169" height="110" class="aligncenter size-full wp-image-189" /></p>
<h4>elk_monitor.pl</h4>
<p>This is the main script, it runs in a loop checking for new messages every second. You <em>will</em> need edit the %zonelist, %outputs, %areas near the top. Also, you will need to set some paths, look near the top of the file.</p>
<p>Required: <a href="http://github.com/threadhead/elkm1--control/tree/master">ElkM1::Control</a>, <a href="http://log4perl.sourceforge.net/">Log4perl</a></p>
<h4>elk_monitor.sh</h4>
<p>This is the shell script that controls <em>elk_monitor.pl</em> as a daemon. Setting up daemons can be complex as each system is different, so google around for some help.</p>
<h4>elkm1.sql</h4>
<p>A MySQL script to setup the tables and fields that the <em>elk_monitor.pl</em> script uses. You <em>will</em> need to add a database named &#8216;elkm1&#8242;. After that you can execute this script to create everything else for you.</p>
<h4>lib/elkm1_db.pl</h4>
<p>The database setting and basic sql commands are abstracted into this library. This is where you will need to set MySQL&#8217;s host, name, password, etc.</p>
<h4>lib/file_tickler.pl</h4>
<p>I use a custom ruby script to monitor the daemon. This library just touches a file every minute to let us know the <em>elk_monitor.pl</em> script is still running. Why? Well, I have had the script &#8216;freeze&#8217; without exiting and most monitoring applications do not detect this. Obviously, this part is optional.</p>
<h3>Conclusion</h3>
<p>If you get all the settings right, she should run all day/week/month for you.</p>
<p>I and <strong>not</strong> a perl expert. Far from it. So I&#8217;m sure everything could use some tidying. If you do, please let me know and I&#8217;ll incorporate your changes.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=0m_l_iHd0sA:LHdEelf-R1s:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=0m_l_iHd0sA:LHdEelf-R1s:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=0m_l_iHd0sA:LHdEelf-R1s:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=0m_l_iHd0sA:LHdEelf-R1s:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=0m_l_iHd0sA:LHdEelf-R1s:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/DaddyFixesEverything/~4/0m_l_iHd0sA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.spoolz.com/2009/04/25/monitor-your-elk-m1-log-to-mysql-and-daemonize-it/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.spoolz.com/2009/04/25/monitor-your-elk-m1-log-to-mysql-and-daemonize-it/</feedburner:origLink></item>
		<item>
		<title>Sinatra-Tailer: a small app for viewing server log files</title>
		<link>http://feedproxy.google.com/~r/DaddyFixesEverything/~3/iLrLJfETtHc/</link>
		<comments>http://blog.spoolz.com/2009/03/18/sinatra-tailer-a-small-app-for-viewing-server-log-files/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 23:03:24 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[sinatra]]></category>
		<category><![CDATA[tail]]></category>

		<guid isPermaLink="false">http://blog.spoolz.com/?p=177</guid>
		<description><![CDATA[I was reading Jason Seifer&#8217;s: Offline Gem Server Rdocs, which is an apache/passenger served Sinatra app that allows you to view the Rdocs of installed gems without using gem server. Nice. So I installed it on our sandbox server for all to enjoy.
But it got me thinking, there is another think I like to keep [...]]]></description>
			<content:encoded><![CDATA[<p>I was reading <a href="http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs">Jason Seifer&#8217;s: Offline Gem Server Rdocs</a>, which is an apache/passenger served <a href="http://www.sinatrar.com">Sinatra</a> app that allows you to view the Rdocs of installed gems without using <em>gem server</em>. Nice. So I installed it on our sandbox server for all to enjoy.</p>
<p>But it got me thinking, there is another think I like to keep an eye on on our servers&#8230; log files. Oh, and I was looking for good excuse to play around with Sinatra. So, &#8220;with a one, and-a-two, and-a-three&#8230;&#8221; we have <a href="http://github.com/threadhead/sinatra-tailer/tree">Sinatra-Tailer</a>.</p>
<p>You can <a href="http://github.com/threadhead/sinatra-tailer/tree">read all about it on the github page</a>, but in short it simply performs a <em>tail</em> and displays the last X lines of the log file.</p>
<pre class="brush: bash">
tail -n /path/to/my/log/file.log
</pre>
<h3>Features</h3>
<ol>
<li>refreshes the list every X seconds, set by the user</li>
<li>only one config.yml file to edit</li>
<li>supports file globs, so you can grab a whole list of file with one line</li>
<li>specify the number of lines to show</li>
<li>completely unobtrusive js, because I&#8217;m cool?</li>
</ol>
<h3>Requirements</h3>
<ol>
<ul><a href="http://www.sinatrarb.com">Sinatra framework</a> (tested on 0.9.1.1, earlier may work)</ul>
</ol>
<p>I whipped this up pretty quickly so I&#8217;m sure there are a few bugs. There is some testing for a few unit tests, but nothing functional.</p>
<p>One word of warning, if you want to put this on a production server my recommendation is to put it on a separate port (like 9876) and <strong>for heaven&#8217;s sake</strong>, at a minimum use http basic authentication. From the sinatra <a href="http://www.sinatrarb.com/intro.html">readme</a>:</p>
<pre class="brush: ruby">
 use Rack::Auth::Basic do |username, password|
    username == &#039;admin&#039; &amp;&amp; password == &#039;secret&#039;
  end
</pre>
<p>Enjoy!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=iLrLJfETtHc:zcFAkLkE6N8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=iLrLJfETtHc:zcFAkLkE6N8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=iLrLJfETtHc:zcFAkLkE6N8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=iLrLJfETtHc:zcFAkLkE6N8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=iLrLJfETtHc:zcFAkLkE6N8:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/DaddyFixesEverything/~4/iLrLJfETtHc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.spoolz.com/2009/03/18/sinatra-tailer-a-small-app-for-viewing-server-log-files/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://blog.spoolz.com/2009/03/18/sinatra-tailer-a-small-app-for-viewing-server-log-files/</feedburner:origLink></item>
		<item>
		<title>Apache Virtual Hosts, Rails, Rack, Passenger on Local Net</title>
		<link>http://feedproxy.google.com/~r/DaddyFixesEverything/~3/oXAydZoV280/</link>
		<comments>http://blog.spoolz.com/2009/03/12/apache-virtual-hosts-rails-rack-passenger-on-local-net/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 19:51:03 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[sinatra]]></category>
		<category><![CDATA[virtual host]]></category>

		<guid isPermaLink="false">http://blog.spoolz.com/?p=143</guid>
		<description><![CDATA[This one has been bugging me for a couple of years and I just didn&#8217;t want to put in the time and testing to nail it down. But tonight was my night.
The Problem
Here in my development palace I have a couple of laptops that I use for development and an Ubuntu (hardy) server as a [...]]]></description>
			<content:encoded><![CDATA[<p>This one has been bugging me for a couple of years and I just didn&#8217;t want to put in the time and testing to nail it down. But tonight was my night.</p>
<h3>The Problem</h3>
<p>Here in my development palace I have a couple of laptops that I use for development and an Ubuntu (hardy) server as a <a href="http://rubyonrails.org/">Rails</a>/<a href="http://rack.rubyforge.org/">Rack</a> sandbox that I run with <a href="http://modrails.com">Passenger</a>. While I have always been able to serve up either a Rails or <a href="http://www.sinatrarb.com/">Sinatra</a> project, I typically have 3 or 4 going at the same time. But I had to access them with urls like: <em>http://192.168.0.2/project1</em> and <em>http://192.168.0.2/project2</em>.</p>
<p>So, what&#8217;s the problem, eh?</p>
<p>Well, for starters, you can&#8217;t do anything concerning subdomains. That&#8217;s a show stopper for many apps.</p>
<p>Second, it really messes with your environment variables like <em>["PATH_INFO"]</em>. So if you do any routing and you expect the base url to be <em>&#8216;/&#8217;</em>, it won&#8217;t be. The root url will be &#8216;/projectx&#8217;. Bummer.</p>
<h3>The Solution</h3>
<p>To remedy the issues with non-<a href="http://en.wikipedia.org/wiki/Top-level_domain">tld</a> virtual hosts (also called sub URIs?) we need to add the domains to the laptops and server, then add the virtualhosts on the server for apache. This means that I can now goto <em>http://project1.ubuntu.remote</em> url to get to my rails/rack app.</p>
<p>For reference, I am using the following:</p>
<ul>
<li>Laptops: Mac OS X, 10.5.7 and 10.4.11</li>
<li>Server: <a href="http://www.ubuntu.com/">Ubuntu</a> Desktop 8.04LTS, <a href="http://www.apache.org/">Apache</a>/2.2.8 (Ubuntu) <a href="http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html">mod_fastcgi</a>/2.4.6 PHP/5.2.4-2ubuntu5.5 with <a href="http://modrails.com">Suhosin-Patch Phusion_Passenger/2.0.6</a></li>
</ul>
<h4>On Each Laptop</h4>
<p>These instructions are for Mac OS X, but should be identical for your favorite flavor of *nix. We are going to add some friendly names to our ubuntu server using it&#8217;s ip address (192.168.0.2). In this example we will be able to access the root web documents using <em>http://ubuntu.remote</em>, and one of our Sinatra projects using <em>http://project1.ubuntu.remote</em>.</p>
<p><strong>Important!</strong> Don&#8217;t use a name ending in <em>&#8216;.local&#8217;</em>. While it did work for me, I read about a few instances where some systems will not resolve domain names ending in .local outside the local machine. Also, don&#8217;t change <strong>anything</strong> else in your /etc/hosts file except to add the lines at the end.</p>
<pre class="brush: python">
mate /etc/hosts

# add the following line to the END of your /etc/hosts file and save
# note: there is a &lt;space&gt; character between the ip address and each host name
192.168.0.2 ubuntu.remote project1.ubuntu.remote
</pre>
<h4>On The Server: Hosts File</h4>
<p>Nothing will work until we tell the server machine that it can accept incoming traffic from our new friendly names. Similar to on the mac, we need to edit our /etc/hosts file but we will add a slightly different line. In this case we are telling the server that incoming traffic from &#8216;ubuntu.remote&#8217; and &#8216;gems.ubuntu.remote&#8217; are just names for the localhost (127.0.0.1).</p>
<pre class="brush: shell">sudo pico /etc/hosts

# add the following line to the end of our /etc/hosts file and save
# you can added after your existing 127.0.0.1 line if you wish
127.0.0.1 ubuntu.remote project1.ubuntu.remote
</pre>
<h4>On The Server: VirtualHosts</h4>
<p>As a final step we will need to add or change the virtual host definitions for your rails/rack project. Depending on your Apache setup or Linux distro, the default enabled site may be slightly different and you may have to adapt your virtual host file to your default setup.</p>
<p>First, in my /etc/apache2/apache.conf file, I have the following line near the end of the file. This was to eliminate a warning every time apache was started/restarted. It may affect your virtual host default, but shouldn&#8217;t, so add it if you get errors.</p>
<pre class="brush: shell">
#added near end of /etc/apache2/apache.conf
ServerName localhost
</pre>
<p>Next we need to check our default virtual host setup to see how the NameVirtualHost is defined. We will duplicate that in each new virtual host that we add. The parts we are looking is the NameVirtualHost and VirtualHost near the top. They could be &#8216;NameVirtualHost *&#8217; and &#8216;&lt;VirtualHost *&gt;&#8217; or &#8216;NameVirtualHost *:80&#8242; and &#8216;&lt;VirtualHost *:80&gt;&#8217;. See the pattern? We need to use the same definition in our new virtual files.</p>
<p>Let&#8217;s check our default virtual host setup:</p>
<pre class="brush: shell">
cd /etc/apache2/sites-enabled
ls # your are looking for the name of your default site file

  total 0

  lrwxrwxrwx 1 root root 36 2009-02-27 18:49 000-default -&gt; /etc/apache2/sites-available/default

cat /etc/apache2/sites-enabled/000-default

  NameVirtualHost *
  &lt;VirtualHost *&gt;
    ServerAdmin webmaster@localhost
  # snipped several lines #
  &lt;/VirtualHost&gt;
</pre>
<p>On my system the NameVirtualHost is &#8216;*&#8217;, so that is what we need to use for the new virtual host. In this case, I am going to add a virtual host file for a rack based project. It&#8217;s a Sinatra app, but that doesn&#8217;t matter as this will work for any rack based project, even a rails/rack project (since rails 2.2.2?).</p>
<p>Also, I like using the Apache2 system to enable and disable sites. It&#8217;s clean, easy to use, and if any apache admin comes along they will know exactly what is going on.</p>
<p>It&#8217;s also work mentioning that you should disable or delete any existing virtual host files that you were using previously.</p>
<pre class="brush: shell">cd /etc/apache2/sites-available
sudo pico gems

# enter this as your virtual host setup
&lt;VirtualHost *&gt;
  ServerName project1.ubuntu.remote

  DocumentRoot &quot;/path/to/your/application/project/public&quot;

  RackEnv production
  &lt;directory &quot;/path/to/your/application/project/public&quot;&gt;
    Order allow,deny
    Allow from all
  &lt;/directory&gt;
&lt;/VirtualHost&gt;

# save the file and reload apache

sudo /etc/init.d/apache2 reload
</pre>
<h4>The Fun Part</h4>
<p>Assuming you saw no errors when you reloaded apache, you should be able to go to your new urls see both the root files and your rack application.</p>
<p>http://ubuntu.remote</p>
<p>http://project1.ubuntu.remote</p>
<p><strong>Dyn-O-Mite!</strong></p>
<h3>Bonus Points!</h3>
<p>For extra credit, let&#8217;s say you have admin access to your router, and you are one of those gotta-have-control-of-everything dudes (or dudettes) so you installed a 3rd party firmware. You&#8217;re in luck! You can probably add some custom entries in your DNS and you don&#8217;t have to edit the /etc/hosts files on your laptop.</p>
<p>I installed <a href="http://www.polarcloud.com/tomato/">Tomato firmware</a> on my Linksys wireless router. Tomato uses <a href="http://localhost:9292/doc_root/actionmailer-1.3.6/rdoc/index.html">Dnsmasq</a> with allows you to set internal host names.</p>
<p>Maybe I&#8217;ll cover that in another post.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=oXAydZoV280:oYRx79MK83I:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=oXAydZoV280:oYRx79MK83I:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=oXAydZoV280:oYRx79MK83I:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=oXAydZoV280:oYRx79MK83I:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=oXAydZoV280:oYRx79MK83I:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/DaddyFixesEverything/~4/oXAydZoV280" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.spoolz.com/2009/03/12/apache-virtual-hosts-rails-rack-passenger-on-local-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.spoolz.com/2009/03/12/apache-virtual-hosts-rails-rack-passenger-on-local-net/</feedburner:origLink></item>
		<item>
		<title>Elk M1 Security System Control with Perl Script</title>
		<link>http://feedproxy.google.com/~r/DaddyFixesEverything/~3/KeafEKqEvQ0/</link>
		<comments>http://blog.spoolz.com/2009/01/30/elk-m1-security-system-control-with-perl-script/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 17:42:26 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[Home Automation]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[elk]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.spoolz.com/?p=129</guid>
		<description><![CDATA[I have an Elk M1 security system that I like to monitor and record all the activity. It&#8217;s useful to know what doors are open and how long they have been open. For several years in the past I have use Homeseer to do the monitoring where I wrote VBScript files to push the activity [...]]]></description>
			<content:encoded><![CDATA[<p>I have an <a href="http://www.elkproducts.com/index2.html" target="_blank">Elk M1 security</a> system that I like to monitor and record all the activity. It&#8217;s useful to know what doors are open and how long they have been open. For several years in the past I have use <a href="http://www.homeseer.com/" target="_blank">Homeseer</a> to do the monitoring where I wrote VBScript files to push the activity and changes to my MySQL server. Honestly, I have never likes Homseer, it&#8217;s flaky and I prefer that I don&#8217;t depend on WinXP either.</p>
<p>About a year ago, James Russo released a script on <a href="http://www.cocoontech.com" target="_blank">Cocoontech</a> to monitor and control your Elk M1 from a perl script. You can <a href="http://www.cocoontech.com/index.php?showtopic=8920" target="_blank">read the forum post</a> for more details. Thanks to James and other Cocoontech members, it works fairly well.</p>
<p>But there have been no updates or bug fixes in over a year. Not wanting to relive my perl days (sorry, I never really liked perl), I decided to revive the project and give it a new home. I asked James for permission to take over the project and he gracefully agreed.</p>
<h4>ElkM1::Control New Home on Github</h4>
<p>Go check it out! <a href="http://github.com/threadhead/elkm1--control/tree">ElkM1::Control on github</a>.</p>
<p>Why github? First, I have stopped using SVN. And sourceforge, ElkM1::Control&#8217;s original home, doesn&#8217;t support git. Second, github makes it too easy to fork a project and make changes yourself, then push them back up so that I can integrate those changes. You really should try <a href="http://git-scm.com/" target="_blank">git</a> if you haven&#8217;t before. And you don&#8217;t need git to download ElkM1::Control and install it.</p>
<h4>Updates and Bug Fixes!</h4>
<p>You read that right, I have made a few bug fixes and added a couple of new features. I have been running ElkM1::Control on my Ubuntu Hardy server for about a month with no problems. I have also run and do some debugging on OS X (10.5.x).</p>
<p>I also changed the version numbering system to the more common <em>major.minor.release</em> notation. We are not at version 0.1.0.</p>
<h4>Quick Installation Instructions</h4>
<ol>
<li>Goto the <a href="http://github.com/threadhead/elkm1--control/tree" target="_blank">project home page</a> and click the <em>download</em> button. Select the ZIP version (for some reason the TAR doesn&#8217;t work sometimes).</li>
<li>Follow the README file, don&#8217;t forget the PREREQUISITES section. For those who don&#8217;t rtfm&#8230;</li>
<li>From your favorite shell, you may need to add sudo in front of each: &#8216;perl Makefile.PL&#8217;</li>
<li>&#8216;make&#8217;</li>
<li>&#8216;make test&#8217;</li>
<li>Then to install: &#8216;make install&#8217;</li>
</ol>
<p>Next, you&#8217;ll need a little script to get going. There are <a href="http://www.cocoontech.com/index.php?showtopic=8920" target="_blank">several scripts posted on Cocoontech</a>, but this one should get you started:</p>
<pre class="brush: php">
# Example 2: Display all M1 messages
use ElkM1::Control;
    my $elk = ElkM1::Control-&gt;new(host =&gt; &#039;192.168.0.251&#039;, port =&gt; 2101);
    while (1) {  # Loop forever
        while (my $msg = $elk-&gt;readMessage) { # Read the M1&#039;s messages
                print $msg-&gt;toString;  # Print the messages
        }
    }
</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=KeafEKqEvQ0:4EKE0cEypds:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=KeafEKqEvQ0:4EKE0cEypds:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=KeafEKqEvQ0:4EKE0cEypds:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=KeafEKqEvQ0:4EKE0cEypds:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=KeafEKqEvQ0:4EKE0cEypds:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/DaddyFixesEverything/~4/KeafEKqEvQ0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.spoolz.com/2009/01/30/elk-m1-security-system-control-with-perl-script/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.spoolz.com/2009/01/30/elk-m1-security-system-control-with-perl-script/</feedburner:origLink></item>
		<item>
		<title>Authlogic – Rails Authentication Done Right</title>
		<link>http://feedproxy.google.com/~r/DaddyFixesEverything/~3/fbY4weLLugI/</link>
		<comments>http://blog.spoolz.com/2008/11/20/authlogic-rails-authentication-done-right/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 21:56:24 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[authentication]]></category>

		<guid isPermaLink="false">http://blog.spoolz.com/?p=119</guid>
		<description><![CDATA[Sorry to borrow the title line directly from Ben&#8217;s site, but Authlogic is the authentication system I have been looking for. Bye, bye restful authentication. Hello easy, simple, get out of my way, easily upgradeable, smartly written Authlogic.
I shouldn&#8217;t disrespect restful authentication much as she has been with me for over a year now. But [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry to borrow the title line directly from Ben&#8217;s site, but <a href="http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup">Authlogic</a> is the authentication system I have been looking for. Bye, bye restful authentication. Hello easy, simple, get out of my way, easily upgradeable, smartly written Authlogic.</p>
<p>I shouldn&#8217;t disrespect restful authentication much as she has been with me for over a year now. But every time I had to install, setup, and get the basics working in RA I couldn&#8217;t help gnashing my teeth. I jumped on the RA bandwagon like so many other Rails developers looking for an authentication system that just and move on to more important things.</p>
<p>Enter Authlogic by Ben Johnson of <a href="http://www.binarylogic.com/">BinaryLogic</a>. By luck, I was starting a new rails app this week, so I decided to take Authlogic out for a test drive. Following Ben&#8217;s <a title="Tutorial: Authlogic Basic Setup" href="http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup">Tutorial: Authlogic Basic Setup</a> I had a basic login/logout/session management system up and running in a ridiculously little amount of code. The best part of Authlogic is that it truly get&#8217;s out of my way and provides me with what I need&#8230; a robust and secure methodology of authentication and session management.</p>
<p>The benefits of Authlogic are:</p>
<ul>
<li>It&#8217;s a plugin and a gem. When Ben pushes an update, getting the latest release is super simple.</li>
<li>It&#8217;s a plugin and a gem. This keeps the authentication code separate from your codes, the way it should be.</li>
<li>Session are treated like ActiveRecord objects. This is just as cools as it sounds and is very Rails-like.</li>
<li>Better security. Authlogic uses a non-reversible token that is changed on every session initiation and password change, thus virtually eliminating session persistence and brute force session attacks.</li>
<li>Ben Johnson. Ben knows what he is doing and has been quickly releasing updates.</li>
<li>Ben Johnson. Sorry for the repetition, but Ben also has a nice series of tutorials with supporting project code you can download.
<ul>
<li><a title="Tutorial: Reset passwords with Authlogic the RESTful way" href="http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic">Tutorial: Reset passwords with Authlogic the RESTful way</a></li>
<li><a title="Tutorial: Authlogic Basic Setup" href="http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup">Tutorial: Authlogic Basic Setup</a></li>
</ul>
</li>
</ul>
<div>Read more on on <a href="http://www.binarylogic.com/2008/10/25/authlogic-released-rails-authentication-done-right">BinaryLogic</a> or get it at <a href="http://github.com/binarylogic/authlogic/tree/master">Github</a>.</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=fbY4weLLugI:HYvXOE1hz94:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=fbY4weLLugI:HYvXOE1hz94:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=fbY4weLLugI:HYvXOE1hz94:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=fbY4weLLugI:HYvXOE1hz94:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=fbY4weLLugI:HYvXOE1hz94:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/DaddyFixesEverything/~4/fbY4weLLugI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.spoolz.com/2008/11/20/authlogic-rails-authentication-done-right/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://blog.spoolz.com/2008/11/20/authlogic-rails-authentication-done-right/</feedburner:origLink></item>
		<item>
		<title>iPhoto AppleScript to Remove Duplicates</title>
		<link>http://feedproxy.google.com/~r/DaddyFixesEverything/~3/WaruBZho9_c/</link>
		<comments>http://blog.spoolz.com/2008/11/03/iphoto-applescript-to-remove-duplicates/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 18:04:56 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[iphoto]]></category>

		<guid isPermaLink="false">http://blog.spoolz.com/?p=72</guid>
		<description><![CDATA[Short Story:
I had several years of photos that I needed to identify and remove the duplicate. Instead of manually combing through 12,000 (read Long Story below) and before carpal tunnel set in, I needed a script to help me out. My situation may or may not be unique, so this script may not work 100% [...]]]></description>
			<content:encoded><![CDATA[<h3>Short Story:</h3>
<p><img class="alignleft size-full wp-image-78" title="iphoto_icon" src="http://blog.spoolz.com/wp-content/uploads/2008/11/iphoto_icon.png" alt="" width="128" height="128" />I had several years of photos that I needed to identify and remove the duplicate. Instead of manually combing through 12,000 (read Long Story below) and before carpal tunnel set in, I needed a script to help me out. My situation may or may not be unique, so this script may not work 100% out-of-the-box for you, but it should get you started.</p>
<p><a href="http://blog.spoolz.com/wp-content/uploads/2008/11/iphoto-remove-duplicates.zip"><img src="http://blog.spoolz.com/wp-content/uploads/2008/11/download_scpt_button-trans.png" alt="" title="download_scpt_button-trans" width="206" height="85" class="alignright size-full wp-image-95" /></a></p>
<div>This script will identify duplicate photos in your iPhoto library and mark them with a comment (keyword) of &#8220;duplicate&#8221;. <em>It will not delete anything</em>.</div>
<p>To use:</p>
<ol>
<li>Download and unzip the script</li>
<li>Double-click the script to open in Script Editor</li>
<li>Go into iPhoto and select a group of photos you want to compare</li>
<li>Switch back to Script Editor and run the script</li>
<li><strong>Don&#8217;t Touch Anything!</strong> Just let the script finish, it could take a while if you are comparing a lot of photos</li>
<li>After the script is done, go back into iphoto and search for &#8220;duplicate&#8221; <img class="alignnone size-full wp-image-81" title="duplicate" src="http://blog.spoolz.com/wp-content/uploads/2008/11/duplicate.png" alt="" width="200" height="28" /></li>
<li>You can highlight all the duplicates and delete them or move them some place safe</li>
</ol>
<p>Photos are considered a duplicate if:</p>
<ol>
<li>both heights match</li>
<li>both widths match</li>
<li>the photo date in iPhoto match, this is typically the EXIF creation date</li>
</ol>
<div>There are no error checks in this script and it presents no interface except an alert when it&#8217;s done. If you need help, just post a comment below and I&#8217;ll do my best.</div>
<h3>Long Story:</h3>
<p><span id="more-72"></span></p>
<div>About a year ago I was editing down my iPhoto library of about 6000 images, just gitting rid of those out-of-focus shots and the ones of my wife&#8217;s feet (a curiously large number of these). After a long night of editing, the next morning I awoke to start again, but when I ran iPhoto there was nothing in the library.</div>
<div><strong>It was all gone!</strong></div>
<div>I couldn&#8217;t find anything anywhere. Could I restore from a backup? Ooh nooo. I had erased my backup drive the day before in preparation for moving the unwanted photos onto the backup drive and then making a new backup of my iPhoto Library. So I had no backup.</div>
<div>Not really funny. These were all the shots of my boys being born, first steps, first birthdays, first everything. I was up sh*t creek and it put a serious hurt in my stomach. At least I knew what to do: do nothing on the computer, boot from the Mac OS X install DVD and use Disk Utility to make a byte-for-byte copy of my internal hard disk. I could use this disk image to recover the images, hopefully.</div>
<div>So I tried several image recovery utilities and finally settled on <a href="http://www.datarescue.com/photorescue/v3/index.htm" target="_blank">PhotoRescue</a> for Mac. I mounted the disk image of my internal disk and set PhotoRescue to the task. About 9 hours later (not a typo), PhotoRescue gave me several folders of recovered JPEGs, TIFFs, GIFs and PNGs. I tossed all but the JPEGs. I felt a little better at this point.</div>
<div>But when I looked in the JPEG folder there was over 12,000 images! Huh? Well, PhotoRescue does not discriminate, it recovers ALL images, including thumnails, web graphics, <a href="http://en.wikipedia.org/wiki/Pron#Pr0n">pron</a> (you&#8217;ve been warned). Frankly, it was unbelievable and overwhelming.</div>
<div>So I set about dividing the images into folder that I knew were junk images and ones that I may want to keep. First, I eliminated everything below about 120K. I knew that my oldest digital camera was around 3M pixels and it saved a file that was typically &gt; 200K so those images below 120K were most likely thumbnails and web images. That cut my stack almost in half.</div>
<div>Next I looked for images &gt; 3M. These were corrupted image files that while they looked ok in Preview, I knew there was no way a 1200&#215;1600 images was 40M. Just a consequence of PhotoRescue&#8217;s recovery routine. I can live with that, believe me. So I tossed everything &gt; 3M because my current 6M pixel camera images are under 2M in size.</div>
<div>This left me with about 6,000 images that I imported into a new iPhoto Library. From the looks of it, all my images were there! What a relief, but the bad news was nothing was rotated properly, and there were many, many duplicates. Thousands of duplicates to be exact. After I rotated all the images so that I could view them properly, I set about removing the duplicates.</div>
<div>The good news about removing the duplicates was that they were fairly easy to spot. When I imported all the recovered images into iPhoto it apparently used the EXIF data data to date stamp each photo instead of using the photo file&#8217;s creation date, which was set by PhotoRescue to the day I performed the recovery. So all my photo&#8217;s were dated properly, I just had to look at each photo that matches (they were sorted by date) the one next to it and delete one of them.</div>
<div>A closer look at the duplicate photos revealed that while they had the same height, width and date/time, they varied in size. I was not able to determine why the file sizes varied as the images themselves looked identical, but my best guess is that the size difference came about from iPhoto&#8217;s insistence that when you rotate an image iPhoto considers this an &#8220;edit&#8221; and makes a copy of the original and add&#8217;s some iPhoto specific data (no verification on this though). So hey, if you are going to keep one, why not keep the smaller of the image files? So that&#8217;s what I was doing.</div>
<div>After hours and days of removing duplicates, I decided there has to be a better way. A bit of searching for &#8220;applescript iphoto remove duplicates&#8221; let me to <a href="http://www.brattoo.com/propaganda/index.php?action=software" target="_blank">Brattoo Propaganda Software&#8217;s Duplicate Annihilator</a>. I tried the demo and it works very well. But there was one thing I wanted to do that Duplicate Annihilator could not, and that is mark the larger of the duplicate files. Duplicate Annihilator marks duplicate files by date/time which I am sure is what most people want to do. So definitely check it out.</div>
<div>So Duplicate Annihilator minor missing feature led me to write my own AppleScript to do pretty much the same. The script is pretty simple and requires no additional libraries or command line voodoo. But I will say that coding in Ruby for the past year-and-a-half really reminds my why I don&#8217;t like AppleScript. AS gets the job done, but it&#8217;s so much more work, frankly it&#8217;s confusing, and if you don&#8217;t do it often it&#8217;s a lot of work getting your head around AS&#8217;s nomenclature.</div>
<div>For you fellow rubists, there is <a href="http://appscript.sourceforge.net/rb-appscript/index.html" target="_blank">rb-appscript</a> which would have made my pain a little easier, but it relies on ruby and having the rb-appscript gem installed and that would be too much for most casual Mac users. So AppleScript won this round, but only because I knew I wanted to share the script for others.</div>
<div>Good luck to all you photo recoverers. I&#8217;ve been down your road before.</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=WaruBZho9_c:mQLNMMoeAqQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=WaruBZho9_c:mQLNMMoeAqQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=WaruBZho9_c:mQLNMMoeAqQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=WaruBZho9_c:mQLNMMoeAqQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=WaruBZho9_c:mQLNMMoeAqQ:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/DaddyFixesEverything/~4/WaruBZho9_c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.spoolz.com/2008/11/03/iphoto-applescript-to-remove-duplicates/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		<feedburner:origLink>http://blog.spoolz.com/2008/11/03/iphoto-applescript-to-remove-duplicates/</feedburner:origLink></item>
		<item>
		<title>Batter Blaster – Wrong for America</title>
		<link>http://feedproxy.google.com/~r/DaddyFixesEverything/~3/CYEgLXStCj4/</link>
		<comments>http://blog.spoolz.com/2008/09/11/batter-blaster-wrong-for-america/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 04:05:37 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[Peeves]]></category>

		<guid isPermaLink="false">http://blog.spoolz.com/?p=47</guid>
		<description><![CDATA[Ok, the title is a tad hyperbolic, but when I saw this in Costco a few months ago a tiny rage welled inside. We were shopping on a Saturday when we came across Batter Blaster. The spiel was along the lines of how much easier breakfast would be with pancakes from a can.
Breakfast from a [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="http://www.batterblaster.com/index.php" href="http://blog.spoolz.com/wp-content/uploads/2008/09/batter_blaster1.jpg" target="_blank"><img class="alignright size-full wp-image-52" title="batter_blaster1" src="http://blog.spoolz.com/wp-content/uploads/2008/09/batter_blaster1.jpg" alt="" width="180" height="160" /></a>Ok, the title is a tad hyperbolic, but when I saw this in <a href="http://www.costco.com/">Costco</a> a few months ago a tiny rage welled inside. We were shopping on a Saturday when we came across <a href="http://www.batterblaster.com/index.php" target="_blank">Batter Blaster</a>. The spiel was along the lines of how much easier breakfast would be with pancakes from a can.</p>
<p><strong>Breakfast from a Can? WTF!</strong></p>
<p><span id="more-47"></span></p>
<p>At first, I honestly thought it was a joke, but I was compelled to stop and pick up the can and watch our demo maven squirt batter out of a can onto the griddle. I did try one, and it tasted OK, but nothing better than what I make for the kids on weekends. That&#8217;s when the whole thing <em>really</em> started to bother me.</p>
<h4>Ridiculously High Cost!</h4>
<p>I doubt one can could hold its own against my two boys. And the three pack can was something like $7.00 (please comment if you know the real price). Geeze Louise that is expensive. According to the label each can will make 28 &#8211; 4in. pancakes. I have some pretty serious doubts about that claim. Those must be <em>some darn thin pancakes</em>.</p>
<p>By their own admission, there is only 2.25 cups of batter in each can. When I make pancakes, I use a ladle that is 6oz. which I reckon results in 4oz. <strong>per pancake</strong>. And each of my boys will eat 3 to 4 of those suckers, without batting an eye. That comes out to <span style="text-decoration: underline;"><strong>ONE </strong></span><span style="text-decoration: underline;"><strong>CAN</strong></span> per child. And my kids are not the video game, boob tube species either. In fact both are a tad on the skinny side.</p>
<h4>Could You Be More Environmentally Unfriendly or What?</h4>
<p>Don&#8217;t prattle on to me about how steel cans are recyclable. The amount of energy to produce and recycle those cans, the extra weight of shipping, the added shelf space, not to mention that you must keep it refrigerated are all energy wastes. And completely unnecessary.</p>
<p>My pancakes come in paper bags&#8230; um, flour, pinch of baking soda and baking powder, maybe some buttermilk if I have it around, , dash of salt, and an egg or two. Not much to recycle there. Even if you go the pancake mix route, all you have is one small box or plastic (recyclable) bag. Even better, Elise has a great recipe for <a href="http://www.elise.com/recipes/archives/001347blueberry_buttermilk_pancakes.php" target="_blank">Blueberry Buttermilk Pancakes</a> over at <a href="http://www.elise.com/recipes/" target="_blank">Simply Recipes</a>. Yum.</p>
<p>All that steel in the name of convenience is a shameful waste.</p>
<h4>Are People Really That Lazy?</h4>
<p>That was probably my first thought. Have people become so darn lazy that can&#8217;t mix a little water with some batter mix and make semi-homemade pancakes? I hope not. For crying in a bucket, how hard is it to mix up a little batter!</p>
<p>If you poke around on the blaster site, they have so-called testimonials from overly exuberant customers espousing how much time Batter Blaster has saved them and how convenient it was. All I can picture is one of those self-absorbed parents, squirting goo out of a can, while yapping on their cell phone, kids with permanent carpel tunnel jamming out on their NDS,  while cooking some pancakes. Woot, ain&#8217;t multi-tasking great. America, we sure have come a long way baby.</p>
<p><a rel="http://www.continentalmills.com/brands/krusteaz/pancake_waffle_mixes/buttermilk_pancake_mix/" href="http://blog.spoolz.com/wp-content/uploads/2008/09/krusteaz_-_pancake_mix_-_buttermilk.jpg" target="_blank"><img class="alignleft size-full wp-image-49" title="krusteaz_-_pancake_mix_-_buttermilk" src="http://blog.spoolz.com/wp-content/uploads/2008/09/krusteaz_-_pancake_mix_-_buttermilk.jpg" alt="" width="120" height="165" /></a>Let me put a better vision in your mind&#8230; you take a box of <a href="http://www.continentalmills.com/brands/krusteaz/pancake_waffle_mixes/buttermilk_pancake_mix/">Krusteaz Pancake &amp; Waffle Mix</a> out of your cupboard, let your son or daughter measure out a couple of cups of mix, show them how to calculate the appropriate amount of water to add, topping it off with a short mixing lesson. You just made something together, and they enjoyed spending time with you, and they will enjoy cooking because they actually did something useful.</p>
<p>Wow, educating your kids about cooking and math all while you develop a real relationship with your kids FTW! Flipping amazing.</p>
<p>BTW, they sell the Krusteaz mix in big bags at <a href="http://www.costco.com/">Costco</a> for around the same price as the blasters. I can only guess the <em>hundreds</em> of pancakes you can make with that bag, plus you&#8217;ll forgo chucking enough steel to build a <a href="http://en.wikipedia.org/wiki/Image:Go_Yugo.jpg" target="_blank">Yugo</a>.</p>
<h4>Please, Please, Please&#8230;</h4>
<p>Don&#8217;t by this product. It exists for only the wrong reasons. Do what is better for your wallet, your planet, and your family by exercising your brain and hands. Trust me, your kids will like you better for it.</p>
<p>If you have a favorite pancake or waffle recipe, please add it in the comments below.</p>
<p>I feel better now℠</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=CYEgLXStCj4:vW1lGGb5Kec:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=CYEgLXStCj4:vW1lGGb5Kec:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=CYEgLXStCj4:vW1lGGb5Kec:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=CYEgLXStCj4:vW1lGGb5Kec:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=CYEgLXStCj4:vW1lGGb5Kec:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/DaddyFixesEverything/~4/CYEgLXStCj4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.spoolz.com/2008/09/11/batter-blaster-wrong-for-america/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.spoolz.com/2008/09/11/batter-blaster-wrong-for-america/</feedburner:origLink></item>
		<item>
		<title>Butt Biter: Rails ‘truncate’ Method Broken in Ruby 1.8.7</title>
		<link>http://feedproxy.google.com/~r/DaddyFixesEverything/~3/teMG7pfzruQ/</link>
		<comments>http://blog.spoolz.com/2008/09/02/butt-biter-rails-truncate-method-broken-in-ruby-187/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 04:01:48 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[butt biter]]></category>

		<guid isPermaLink="false">http://blog.spoolz.com/?p=38</guid>
		<description><![CDATA[This one threw me for far too many minutes. In ActionView::Helpers::TextHelper the truncate method is broken for Ruby 1.8.7. I&#8217;m not exactly sure the version of ruby that it stopped working for, but I was previously on 1.8.6, and I don&#8217;t recall it not working. But after I upgraded to the latest patchlevel of 1.8.7, truncate [...]]]></description>
			<content:encoded><![CDATA[<p>This one threw me for far too many minutes. In <a href="http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=C00000713&amp;name=TextHelper">ActionView::Helpers::TextHelper</a> the <a href="http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=M002044&amp;name=truncate">truncate</a> method is broken for Ruby 1.8.7. I&#8217;m not exactly sure the version of ruby that it stopped working for, but I was previously on 1.8.6, and I don&#8217;t recall it not working. But after I upgraded to the latest patchlevel of 1.8.7, truncate stopped working.</p>
<h3><span style="color: #800000;">Update 12/2/08: Fixed in Rails 2.2! (<a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/867">read more</a>)</span></h3>
<p>The error that I received was thus:</p>
<p><code>ActionView::TemplateError (undefined method `length' for #) on line #83 of dashboard/index.html.erb:<br />
</code></p>
<p>Fortunately, someone has submitted a <a href="http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/867">ticket to Rails core</a>. I hope it&#8217;s applied in the Rails 2.2.0 release.</p>
<p><span id="more-38"></span></p>
<h3>Current Method, Done Busted</h3>
<p>As of Rails 2.1.0, this is the current method (Rails 2.0.2 is similar, and also broken).</p>
<pre class="brush: ruby">&lt;br /&gt;
# File actionpack/lib/action_view/helpers/text_helper.rb, line 49&lt;br /&gt;
def truncate(text, length = 30, truncate_string = &quot;...&quot;)&lt;br /&gt;
if text&lt;br /&gt;
l = length - truncate_string.chars.length&lt;br /&gt;
chars = text.chars&lt;br /&gt;
(chars.length &gt; length ? chars[0...l] + truncate_string : text).to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
</pre>
<p>The problem is that <em>chars</em> method called on the string object (<em>truncate_string</em>) returns an &lt;Enumerable::Enumerator&gt; object. And according to the Ruby 1.8.7 RDoc, there is no &#8216;length&#8217; method in Enumerable::Enumerator. To be honest, I can&#8217;t find the &#8216;chars&#8217; method in any of the Ruby <a href="http://www.ruby-doc.org/core/">1.8.6 docs</a> or <a href="http://www.ruby-doc.org/core-1.8.7/index.html">1.8.7 docs</a>. I guessing that it may have been Rails method at some time.</p>
<h3>Fix #1</h3>
<p>The fix is to get rid of all the <em>chars</em> methods. On the bug ticket, the author gives his fix, but you are going to have to monkey-patch rails, or change the method name.</p>
<pre class="brush: ruby">&lt;br /&gt;
def truncate(text, length = 30, truncate_string = &quot;...&quot;)&lt;br /&gt;
if text&lt;br /&gt;
l = length - truncate_string.chars.to_a.length&lt;br /&gt;
chars = text.chars&lt;br /&gt;
(chars.to_a.length &gt; length ? chars.to_a[0...l].to_s + truncate_string : text).to_s&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
</pre>
<h3>Fix #2 (mine, tiny bit better?)</h3>
<p>I&#8217;m not exactly sure why the string needs to be converted to an array, when the <a href="http://www.ruby-doc.org/core/classes/String.html#M000789">length</a> function works just dandy on string objects. So I added this to my <em>application_helper.rb</em> file. Also, in the submitted patch, the result of the ternary is converted to a string (.to_s), when all the resulting methods of the ternary return strings. Unnecessary IMHO and probably left over from when the string object was converted to an enumerable. Note that I started with the Rail 2.0.1 version, so it&#8217;s slightly different than if I started with the 2.1.0 version.</p>
<pre class="brush: ruby">&lt;br /&gt;
def truncate_string(text, length = 30, truncate_string = &#039;...&#039;)&lt;br /&gt;
if text.nil? then return end&lt;br /&gt;
l = length - truncate_string.length&lt;br /&gt;
text.length &gt; length ? text[0...l] + truncate_string : text&lt;br /&gt;
end&lt;br /&gt;
</pre>
<p>Yeah, yeah, I could have monkey-patched the TextHelper module, but why tempt fate if you don&#8217;t have to. A quick find/replace on &#8216;truncate&#8217; to &#8216;truncate_string&#8217; is all that was necessary. Works for me.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=teMG7pfzruQ:cJWPKwFFhC8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=teMG7pfzruQ:cJWPKwFFhC8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=teMG7pfzruQ:cJWPKwFFhC8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=teMG7pfzruQ:cJWPKwFFhC8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=teMG7pfzruQ:cJWPKwFFhC8:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/DaddyFixesEverything/~4/teMG7pfzruQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.spoolz.com/2008/09/02/butt-biter-rails-truncate-method-broken-in-ruby-187/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.spoolz.com/2008/09/02/butt-biter-rails-truncate-method-broken-in-ruby-187/</feedburner:origLink></item>
		<item>
		<title>Ruby on Rails Ubuntu Server VM with VMPlayer</title>
		<link>http://feedproxy.google.com/~r/DaddyFixesEverything/~3/E1d18rawcQY/</link>
		<comments>http://blog.spoolz.com/2008/07/30/ruby-on-rails-ubuntu-server-vm-with-vmplayer/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 23:15:41 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[vm]]></category>

		<guid isPermaLink="false">http://blog.spoolz.com/?p=21</guid>
		<description><![CDATA[I had to setup a Ubuntu (8.04) Server virtual machine and get Rails up-to-speed on it this morning, so I thought I would document my steps for those who find the need to repeat. Here is what I needed:

A production server, not a development server, with only what is necessary
A virtual machine that runs under [...]]]></description>
			<content:encoded><![CDATA[<p>I had to setup a Ubuntu (8.04) Server virtual machine and get Rails up-to-speed on it this morning, so I thought I would document my steps for those who find the need to repeat. Here is what I needed:</p>
<ul>
<li>A production server, not a development server, with only what is necessary</li>
<li>A virtual machine that runs under <a href="http://www.vmware.com/download/player/">VMware Player</a></li>
<li><a href="http://www.ubuntu.com/products/WhatIsUbuntu/serveredition">Ubuntu Server</a>, 8.04 is the current, referred to as Hardy Heron</li>
<li><a href="http://httpd.apache.org/">Apache2</a> with <a href="http://www.modrails.com">Phusion Passenger</a> to handle Rails applications</li>
<li><a href="http://www.ruby-lang.org/en/">Ruby</a>, <a href="http://rubyforge.org/projects/rubygems/">Rubygems</a>, <a href="http://www.rubyonrails.org/">Ruby on Rails</a>, a full Rails stack</li>
<li><a href="http://www.mysql.com/">MySQL Server</a> and <a href="http://www.sqlite.org/">SQLite</a>,  with <a href="http://www.phpmyadmin.net/">phpMyAdmin</a> to admin MySQL server</li>
<li>All native drivers for Rails (MySQL and SQLite)</li>
<li><a href="http://www.openssh.com/">OpenSSH</a> server to access the server</li>
<li><a href="http://www.postfix.org/">Postfix</a> to send (only) emails</li>
</ul>
<p>What you need to start:</p>
<p><span id="more-21"></span></p>
<ol>
<li>VMware Player installed. Download it from <a href="http://www.vmware.com/download/player/">VMware</a> directly and follow their instructions (aptitude has older version 1.x)</li>
<li><a href="http://www.ubuntu.com/getubuntu/download">Download the Ubuntu 8.04 Server ISO file</a> for your machine. For torrent users, <a href="http://releases.ubuntu.com/8.04/ubuntu-8.04.1-server-i386.iso.torrent">download the current i386 torrent file</a>.</li>
<li>Download my <a href="http://blog.spoolz.com/wp-content/uploads/2008/07/ubuntu840server.vmx">VMX</a> and <a href="http://blog.spoolz.com/wp-content/uploads/2008/07/ubuntu840servervmdk.zip">VMDK</a> files (vmplayer config and empty virtual disk).</li>
</ol>
<h3>Step 1: Setup Directory and Config File</h3>
<p>Create a new directory somwhere (I called mine &#8216;Ubuntu840Server&#8217;) and copy the Ubuntu ISO file and the VMX and VMDK (don&#8217;t forget to unzip) files into it. You will need to do some quick editing to the Ubuntu840Server.vmx file, so fire up your favorite editor (in Ubuntu Desktop, right-click and Open with &#8220;Text Editor&#8221;). The only sections you may need to edit are:</p>
<ul>
<li><em>ide1:1.filename</em>, make sure it matches the name of your ISO file, something like &#8220;ubuntu-8.04.1-serverr-i386.iso&#8221;</li>
<li><em>fileSearchPath</em>, change to the path of the directory you created</li>
</ul>
<h3>Step 2: Run VMWare Player</h3>
<p>Run VMware Player and open the Ubuntu840Server.vmx. If all the config settings are correct and the ISO files is in the directory, you should boot into Ubuntu Installer.</p>
<h3>Step 3: Install Ubuntu Server</h3>
<p>I won&#8217;t go into details here because Ubuntu has <a href="https://help.ubuntu.com/8.04/serverguide/C/index.html">step-by-step instructions on how to install</a>. But the short story is: <em>accept the defaults</em>.</p>
<p>There is one selection that will make installation easier, select LAMP Server when asked for the Software selection. <a href="http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29">LAMP</a> stands for Linux/Apache/MySQL/PHP. It will install all those packages and configure them automatically for you.</p>
<p><a href="http://blog.spoolz.com/wp-content/uploads/2008/07/picture-1.png"><img class="alignnone size-medium wp-image-22" title="picture-1" src="http://blog.spoolz.com/wp-content/uploads/2008/07/picture-1-300x151.png" alt="" width="300" height="151" /></a></p>
<p>Note: even though I selected a LAMP server, for some reason it did not install Apache/Mysql/PHP. If this happens to you, just do the following after the server re-boots:</p>
<p><code>sudo apt-get install apache mysql-server php5 libapache2-mod-php5 php5-mysql<br />
</code></p>
<h3>Step 4: Get the Latest Updates</h3>
<p>If everything went well, you should reboot into Ubuntu Server and see the <em>login:</em> prompt. Go ahead and login with the username and password you supplied during the installation. Make sure you have the latest updates for Ubuntu by running (this may take a while):</p>
<p><code>sudo apt-get update<br />
sudo apt-get upgrade<br />
</code></p>
<h3>Step 5: Install OpenSSH</h3>
<p>I like to administer my VMs from the terminal via SSH. Ubuntu Server does not come preconfigured with an SSH server, so lets install one:</p>
<p><code>sudo apt-get install openssh-client<br />
sudo apt-get install openssh-server<br />
</code></p>
<p>You don&#8217;t really need the openssh-client, but I like to have it in case I ever need to ssh from the server to somewhere else. I can&#8217;t recommend enough that you secure your SSH server. If you server is exposed to the internet, <strong>it will be attacked</strong>, and one of the favorite vulnerabilities is SSH. Read this article on <a href="http://www.supportsmb.com/2007/02/20/how-to-secure-openssh/">how to Secure an OpenSSH Server</a>!</p>
<h3>Step 6: Install phpMyAdmin</h3>
<p>Since we are using MySQL, having a graphic administration program is nice and it&#8217;s hard to beat phpMyAdmin. I installed it from aptitude, but it did not set the proper aliases for apache2, so there are a few extra steps:</p>
<p><code>sudo apt-get install phpmyadmin</p>
<p># create a site file for apache2<br />
sudo pico /etc/apache2/sites-available/phpmyadmin</p>
<p># enter the following in pico<br />
Alias /phpmyadmin/ "/usr/share/phpmyadmin/"<br />
Alias /phpmyadmin "/usr/share/phpmyadmin/"<br />
&lt;Directory "/usr/share/phpmyadmin/" &gt;<br />
  Options Indexes FollowSymLinks MultiViews<br />
  AllowOverride None<br />
  Order allow,deny<br />
  Allow from all<br />
  Deny from none<br />
&lt;/Directory&gt;</p>
<p># close and save pico, then enter this to enable the phpmyadmin site<br />
sudo a2ensite phpmyadmin<br />
sudo /etc/init.d/apache2 restart<br />
</code></p>
<h3>Step 7: Install Ruby</h3>
<p>Next we need to install ruby. We&#8217;ll use the aptitude pre-built binaries to save time and make it easier to update in the future, but you may wish to install it from source. We also install the sqlite3 database because it is the default used by Rails 2.X and many test packages, but you can omit if you want.</p>
<p><code>sudo aptitude install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby sqlite3 libsqlite3-ruby1.8 build-essential mysql-client libmysqlclient15-dev postfix<br />
</code></p>
<p>Note that we installed the &#8216;build-essential&#8217; package. This package is necessary for you to install any other software from source (like native msql drivers and phusion passenger). We also install the postfix package, you can just accept the defaults.</p>
<p>Next you will need to set some symlinks so that the libraries will be located when needed.</p>
<p><code>sudo ln -s /usr/bin/ruby1.8 /usr/bin/ruby<br />
sudo ln -s /usr/bin/ri1.8 /usr/bin/ri<br />
sudo ln -s /usr/bin/rdoc1.8 /usr/bin/rdoc<br />
sudo ln -s /usr/bin/irb1.8 /usr/bin/irb<br />
</code></p>
<p>Now, when you should see your ruby package when you check the version from the terminal.</p>
<p><code>karl@ubuntuserver:~$ ruby -v<br />
ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]<br />
</code></p>
<h3>Step 8: Install RubyGems</h3>
<p>RubyGems is a package manager like aptitude that makes is trivial to add/update/delete resources that ruby (and Rails) will need. It&#8217;s also how you will install and update Rails. We are going to install RubyGems from source as the aptitude package is quite out-of-date. RubyGems is a self-updating application, and when installed from aptitude, aptitude will complain and you may accidentally downgrade RubyGems.</p>
<p><code># create a sources directory in your home<br />
mkdir ~/sources<br />
cd ~/sources</p>
<p>#download gem package, see <a href="http://rubyforge.org/projects/rubygems/">rubygems homepage</a> for the latest<br />
wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz</p>
<p># decompress the files and setup rubygems<br />
tar xzvf rubygems-1.2.0.tgz<br />
cd  rubygems-1.2.0<br />
sudo ruby setup.rb</p>
<p># add a symlink<br />
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem</p>
<p>#update rubygems<br />
sudo gem update --system<br />
sudo gem update<br />
</code></p>
<h3>Step 9: Install Ruby on Rails</h3>
<p>All this work, and we are finally here. Too bad installing Rails is so easy. Just this one line.</p>
<p><code>sudo gem install rails </code><br />
and a couple more gems you will probably need&#8230;<br />
<code># install the native (faster) mysql driver<br />
sudo gem install mysql</p>
<p># if you want native (faster) sqlite3 drivers, for production<br />
sudo apt-get install libsqlite3-dev<br />
sudo gem install sqlite3-ruby</code></p>
<p>You can install any more gems you may need at this time with &#8217;sudo gem install <em>package-name</em>&#8216;, but if you are using rails 2.1 or greater, you can now add rubygem requirements to your <em>environment.rb</em> file and use rake to automatically installed gem dependencies.</p>
<h3>Step 10: Install Phusion Passenger</h3>
<p>There are many ways to host a Rails application, but at this time, <a href="http://www.modrails.com">Phusion Passenger</a> gets the nod for the easiest to deploy and our experience has been rock-solid in reliability. These install steps are from the <a href="http://modrails.com/install.html">Passenger website installation instructions</a>:</p>
<p><code>sudo gem install passenger<br />
sudo apt-get install apache2-prefork-dev<br />
sudo passenger-install-apache2-module<br />
# and follow the instructions</p>
<p># after phusion installs, you will see instructions to edit your Apache configuration file<br />
#  to add lines to the end of the file<br />
sudo pico /etc/apache2/apache2.conf</p>
<p># add the lines given in the installation screen, because they can be different for each machine, I can't post the instructions here</p>
<p># restart apache webserver<br />
sudo /etc/init.d/apache2 restart<br />
</code></p>
<p>You will also be given a sample virtual host file to setup your Rails application. At this point you can copy an existing Rails app over to the new server, or follow along for a quick setup of a new Rails app.</p>
<h3>Step 11: Create a Rails Application (optional)</h3>
<p>We are going to create a very quick Rails application to test that our installation is working.</p>
<p><code>cd ~/<br />
rails tester<br />
script/generate scaffold Blog name:string content:text<br />
rake db:migrate RAILS_ENV=production</p>
<p># setup apache<br />
sudo a2dissite default  # we don't need this anymore<br />
sudo pico /etc/apache2/sites-available/tester</p>
<p>#enter the following in pico<br />
&lt;VirtualHost *:80&gt;<br />
  ServerName localhost<br />
  DocumentRoot /home/user_name/tester/public<br />
&lt;/VirtualHost&gt;</p>
<p># activate this site<br />
sudo a2ensite tester<br />
sudo /etc/init.d/apache2 restart<br />
</code></p>
<p>Now you can visit your site by going to http://address_of_server/ and you should see your rails application!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=E1d18rawcQY:OZY3p6yKHok:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=E1d18rawcQY:OZY3p6yKHok:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=E1d18rawcQY:OZY3p6yKHok:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=E1d18rawcQY:OZY3p6yKHok:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=E1d18rawcQY:OZY3p6yKHok:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/DaddyFixesEverything/~4/E1d18rawcQY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.spoolz.com/2008/07/30/ruby-on-rails-ubuntu-server-vm-with-vmplayer/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://blog.spoolz.com/2008/07/30/ruby-on-rails-ubuntu-server-vm-with-vmplayer/</feedburner:origLink></item>
		<item>
		<title>Ruby: Send Email Reminders from iCal Calendar</title>
		<link>http://feedproxy.google.com/~r/DaddyFixesEverything/~3/uT-wRmJJIbo/</link>
		<comments>http://blog.spoolz.com/2008/07/21/ruby-send-email-reminders-from-ical-calendar/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 01:34:07 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[erb]]></category>
		<category><![CDATA[icalendar]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://blog.spoolz.com/?p=17</guid>
		<description><![CDATA[This is going to be long, so hunker down for a good read.
Problem: Our Cub Scout den leader sends email reminders to all the parent about upcoming events. I decided to setup a gCal (google calendar) will all the events so that other parents could just check the calendar as they wish, or subscribe to [...]]]></description>
			<content:encoded><![CDATA[<p>This is going to be long, so hunker down for a good read.</p>
<p><b>Problem:</b> Our Cub Scout den leader sends email reminders to all the parent about upcoming events. I decided to setup a gCal (google calendar) will all the events so that other parents could just check the calendar as they wish, or subscribe to the ical file to integrate with their own calendar. But several of the parents don&#8217;t have calendars (shame, shame) and everyone still liked the idea of receiving email reminders. So I decided to write a ruby script to email reminders automatically two days before the event.</p>
<p><b>Solution:</b> Ruby is a great language to handle this. Especially since there are gems to handle many of the functions we need. Some of the gems we will be using are as follows:</p>
<p><span id="more-17"></span></p>
<ul>
<li><a href="http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/index.html">open-uri</a>: to get the ical file via http</li>
<li><a href="http://www.ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/index.html">net/smtp</a>: to send the email, you could use ActionMailer as well</li>
<li><a href="http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/index.html">erb</a>: email body is in a template.html.erb file for easy editing, erb processes the file</li>
<li><a href="http://www.ruby-doc.org/stdlib/libdoc/yaml/rdoc/index.html">yaml</a>: a list of sent notifications are logged in a yaml file</li>
<li><a href="http://icalendar.rubyforge.org/">icalendar</a>: the superb ical manipulation gem from Jeff Rose</li>
</ul>
<p>All you need to do is setup a cron job to run this script. I chose to run the script at 8pm every evening.</p>
<p>I&#8217;m going to break this script apart by methods for easier commenting. You can download the complete script file and templates to follow along. In the single script file is logging and some formatting methods that don&#8217;t really need explanation here.</p>
<p>The script all assembled with some nice logging: <a href='http://blog.spoolz.com/wp-content/uploads/2008/07/notification_script.rb'>notification_script.rb</a><br />
A sample email template file: <a href='http://blog.spoolz.com/wp-content/uploads/2008/07/mail_templatehtml.erb'>mail_template.html.erb</a><br />
A sample recipient groupt list: <a href='http://blog.spoolz.com/wp-content/uploads/2008/07/group_list.txt'>group_list.txt</a></p>
<h3>Setup and Requires</h3>
<p>First, you are going to need the icalendar gem (<a href="http://icalendar.rubyforge.org/">documentation</a>), which you can install with:</p>
<pre class="brush: ruby">
sudo gem install icalendar
</pre>
<p>For the beginning of our script, we&#8217;ll need a few other libraries to be required, and set a constant or two.</p>
<pre class="brush: ruby">
require &#039;rubygems&#039;
require &#039;open-uri&#039;
require &#039;icalendar&#039;
require &#039;date&#039;
require &#039;net/smtp&#039;
require &#039;erb&#039;
require &#039;yaml&#039;

ICAL_URL = &#039;http://www.google.com/calendar/ical...path_to_your_ical_file&#039;
FROM_EMAIL = &#039;your_email_address@domain.com&#039;
MAIL_TEMPLATE_FILE = &#039;mail_template.html.erb&#039;
SENT_NOTIFICATIONS_FILE = &#039;sent_notifications.yml&#039;
GROUP_LIST_FILE = &#039;group_list.txt&#039;
DAYS_BEFORE_TO_SEND = 2
</pre>
<p>All of these requires should already be installed in your standard ruby library. Following the requires are some constants you need to edit. The ICAL_URL constant is the url that you can look up from google calendars by going to your Calendar Settings, and selecting Calendar Details. You should see the ICAL (green) button that when you click, it shows you the url for the ical file of your calendar. Copy and paste this url into the ICAL_URL constant. You will also want to change the FROM_EMAIL to your email address, or the one you want notifications to be from.</p>
<p>The other constants are the names of the files that should be in the same directory as the script. You can rename them or change the paths as necessary.</p>
<h3>The Main Event</h3>
<p>I like to wrap my main events in a method called &#8216;init()&#8217; and place it near the top of the script file so that it is quick and easy to find. You don&#8217;t have to do this, but supporting methods will have to come <em>before</em> your code.</p>
<pre class="brush: ruby">
def init
  begin
  myFile = open(ICAL_URL).read

  cals = Icalendar.parse(myFile)
  cal = cals.first

  cal.events.each{ |e|
    time_diff = e.dtstart - DateTime.now
    if time_diff &lt; (DAYS_BEFORE_TO_SEND * 24 * 60 * 60) &amp;amp;amp;&amp;amp;amp; time_diff &gt; 0

      if notified?(e.uid)
        #log &#039;    notification previousy sent.&#039;

      else
        send_to = group_list
        msg = ERB.new(File.read( MAIL_TEMPLATE_FILE )).result( binding )

        send_email(&#039;Den 4 Notifications&#039;, &#039;your_email@domain.com&#039;, send_to, e.summary, msg)

        add_notification_to_list(e.uid)
      end
    end
    }

  rescue
    #log the error
  end
end
</pre>
<p>Pretty easy, huh? Let start breaking this down in greater detail:</p>
<h3>Step 1: Read the iCal File</h3>
<p>Read the contents of the ical file at the ICAL_URL location. Using the open-uri library, the content of the ical file is read into a string object.</p>
<h3>Step 2: Parse the iCal File with Icalendar</h3>
<p>The Icalendar gem first requires that we parse the ical file, so that it can create the representative &#8217;calendar&#8217; and &#8216;event&#8217; objects for reading. There is the potential of more than one calendar in the ics file. But in our case, we know there is only one, so we need to get that first &#8216;calendar&#8217; object.</p>
<h3>Step 3: Loop Through the Calendar Events</h3>
<p>We need to look at every calendar &#8216;event&#8217; object in the calendar so that we can look at the start date (e.dtstart) so see if it&#8217;s within the DAYS_BEFORE_TO_SEND.</p>
<h3>Step 4: Previous Notification Sent? Ready Email Template</h3>
<p>The &#8216;notified?&#8217; method will tell us if this event has received previous notification. The e.uid attribute is a unique identifier associated with every event (an event id, if you will). We check that e.uid against a list of saved uid&#8217;s.</p>
<p>Then we can read the MAIL_TEMPLATE_FILE and use erb to process the file, substituting the various object attributes (variables). This makes it easy to change the email template without editing our script file.</p>
<h3>Step 5: Send the Email Message</h3>
<p>A Couple of things happen here that we&#8217;ll discuss in the &#8217;send_email&#8217; method, but suffice it to say that this sends the email to all the addresses in the GROUP_LIST_FILE.</p>
<h3>Step 6: Add Notification to List</h3>
<p>We save a list of the event uids (e.uid) that have been notified so that we don&#8217;t send a notification again.</p>
<p><strong>Pretty spiffy, huh?</strong></p>
<p>Now lets show some of the supporting methods and discuss.</p>
<h3>Method: notified?</h3>
<p>This method reads the SENT_NOTIFICATIONS_FILE yaml file to see if the passed &#8216;uid&#8217; exists in the list of events with previous notification. The loop looks at each item in the &#8216;y_content&#8217; array to see if the &#8216;uid&#8217; is a match. If there is a match, return true (I like the explicitness of using return here). You can see how the yaml file is structured in the &#8216;add_notification_to_list&#8217; method.</p>
<pre class="brush: ruby">
def notified?(uid)
  if File.exist?( SENT_NOTIFICATIONS_FILE )
    File.open( SENT_NOTIFICATIONS_FILE ) { |yf|
      y_content = YAML.load( yf )

      if y_content.is_a? Array
        y_content.each{ |e| return true if e[:uid] == uid }
      end
    }
  end

  return false  #not found
end
</pre>
<h3>Method: group_list</h3>
<p>The GROUP_LIST_FILE is a text file with the address of whom we want to send the notification emails to, separated by a linefeed. You can change this to suit your needs, like comma or pipe separation. It returns the list of email addresses in an array.</p>
<p>If the GROUP_LIST_FILE does not exist or there is an error reading the file, a default email address is returned so that at least someone gets notified. I would normally not do it his way and let the rescue raise an error and halt the script.</p>
<pre class="brush: ruby">
def group_list
  begin
    IO.read( GROUP_LIST_FILE ).split(/\n/)
  rescue
    return Array[&#039;default_email@domain.com&#039;]
  end
end
</pre>
<h3>Method: send_email</h3>
<p>Here we get to use the net/smtp gem to send the email. I chose this because it has fairly low overhead and it actually pretty easy to use. I&#8217;m not sure you can use it to send attachments, but in our case, we are just sending HTML emails.</p>
<p>A <a href="http://blog.jayfields.com/2006/12/ruby-multiline-strings-here-doc-or.html">heredoc</a> is used to create the string for the message header. I&#8217;m not such a fan of heredoc, so this is my one and only time I&#8217;ll use it.</p>
<p>Notice that the &#8216;Content-Type: text/html&#8217; is set so that the receive recognizes this as an HTML email and not plain text. Use &#8216;Content-Type: text/plain&#8217; if you&#8217;re sending a text only email.</p>
<p>You will have to set your SMTP server setting were you see &#8216;mail.my_server.com&#8217;. For more information on this, see the <a href="http://www.ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/index.html">NET::SMTP documentation</a>. Because there are many configurations for this, I didn&#8217;t place constants at the beginning of the script. The <a href="http://www.ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/index.html">NET::SMTP docs</a> pretty much cover it.</p>
<p>I would have liked to send all the messages using BCC, but alas I could find no documentation in NET::SMTP supporting BCC. In my case, everyone know everyone else, so it&#8217;s no big whoop.</p>
<pre class="brush: ruby">
def send_email(from_alias, from, to_array, subject, message)
	msg = &lt;&lt;END_OF_MESSAGE
From: #{from_alias} &lt;#{from}&gt;
To: #{to_array.collect{ |item| &#039;&lt;&#039; + item + &#039;&gt;&#039; }.join(&#039;,&#039;)}
Subject: [CUB SCOUTS]#{subject}
Content-Type: text/html

#{message}
END_OF_MESSAGE

	Net::SMTP.start( &#039;mail.my_server.com&#039;, 25 ) do |smtp|
		smtp.send_message msg, from, to_array
	end
end
</pre>
<h3>Method: add_notification_to_list </h3>
<p>Here we add an event uid to a yaml file and timestamp it. I&#8217;m sure there are a million ways to do this, but I just wanted to play around reading/writing yaml files.</p>
<p>There is one thing I don&#8217;t like about this though&#8230; the entire yaml file is read in, the new event is added to the end, and the resulting yaml replaces the entire existing file. I could not find a reliable way to append a yaml object to an existing yaml file. Well, sort of, but it creates an new array object hash for each append, instead of having all events in one array of hashes. Yeah, yeah, I&#8217;m being picky.</p>
<pre class="brush: ruby">
def add_notification_to_list(uid)
  if File.exists?( SENT_NOTIFICATIONS_FILE )
    y_content = YAML.load( File.open( SENT_NOTIFICATIONS_FILE ) )
  end

  y_content = [] unless y_content.is_a?( Array )

  File.open( SENT_NOTIFICATIONS_FILE, &#039;w+&#039; ) { |yf|
    y_content.concat [ :date =&gt; Time.now, :uid =&gt; &quot;#{uid}&quot; ]
    YAML.dump( y_content, yf )
  }
end
</pre>
<h3>Put it All Together&#8230;</h3>
<p>The script all assembled with some nice logging: <a href='http://blog.spoolz.com/wp-content/uploads/2008/07/notification_script.rb'>notification_script.rb</a><br />
A sample email template file: <a href='http://blog.spoolz.com/wp-content/uploads/2008/07/mail_templatehtml.erb'>mail_template.html.erb</a><br />
A sample recipient groupt list: <a href='http://blog.spoolz.com/wp-content/uploads/2008/07/group_list.txt'>group_list.txt</a></p>
<p>All that&#8217;s left is to put all the files in a directory that has read/write access (for the log file and notification list file) and setup a cron job. Now you have automated notifications from your calendar.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=uT-wRmJJIbo:vfcx80MH9zg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=uT-wRmJJIbo:vfcx80MH9zg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=uT-wRmJJIbo:vfcx80MH9zg:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/DaddyFixesEverything?a=uT-wRmJJIbo:vfcx80MH9zg:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/DaddyFixesEverything?i=uT-wRmJJIbo:vfcx80MH9zg:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/DaddyFixesEverything/~4/uT-wRmJJIbo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.spoolz.com/2008/07/21/ruby-send-email-reminders-from-ical-calendar/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.spoolz.com/2008/07/21/ruby-send-email-reminders-from-ical-calendar/</feedburner:origLink></item>
	</channel>
</rss>
