<?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>Honolulu Hacker &#187; Programming</title>
	<atom:link href="http://honoluluhacker.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://honoluluhacker.com</link>
	<description>Tech, Linux, Rails by Holululu-based Kevin English</description>
	<lastBuildDate>Thu, 24 Jun 2010 08:56:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Honolulu Hacker&#8217;s Guide to Lite Weight Backpacking</title>
		<link>http://honoluluhacker.com/2010/06/24/honolulu-hackers-guide-to-lite-weight-backpacking/</link>
		<comments>http://honoluluhacker.com/2010/06/24/honolulu-hackers-guide-to-lite-weight-backpacking/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 08:48:42 +0000</pubDate>
		<dc:creator>kenglish</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://honoluluhacker.com/?p=1143</guid>
		<description><![CDATA[Based on some backpacking experience over the years, I&#8217;ve come up with this list of ways to reduce the weight of your pack. Read and Learn.

Toilet Paper: Anyone who has moved before knows one thing: Books are heavy. Guess what books are made of?&#8230;. PAPER! That&#8217;s right, the same thing that they use to make [...]]]></description>
			<content:encoded><![CDATA[<p>Based on some backpacking experience over the years, I&#8217;ve come up with this list of ways to reduce the weight of your pack. Read and Learn.</p>
<ul>
<li>Toilet Paper: Anyone who has moved before knows one thing: Books are heavy. Guess what books are made of?&#8230;. PAPER! That&#8217;s right, the same thing that they use to make toilet paper. I suggest you lighten your toilet paper load. Next time you go to the bath room, make note of how much toilet paper you need. How many times do you wipe? If you average 3-4 wipes, can use only 2 squares per wipe and can estimate you will be going to the bathroom 2 times a day, do some math, figure out how much mountain money you will REALLY need. If you are a guy, congratulations, you can bring less TP. Don&#8217;t tell the girls this, they may ask you to carry their tent.
    </li>
<li>Deodorant: Seriously? All or some of your backpacking buddies are gonna smell worse than the slums of Manila. Why are you going out our way to smell good? Leave this item at home.</li>
<li>Camera: Skip it. Don&#8217;t worry, one of you buddies will bring a camera especially if you are with a big group. One of them may even carry a tripod, a monopod and so much other camera gear that he is going to need a hip replacement by the age of 35. Don&#8217;t be that guy. Plus, think about it: if you are taking all the picture, you won&#8217;t be in any of them. My wiser older brother once told me: a picture without a person is postcard. If you want pictures of the scenery, just go on flickr and do a search. Chance are pretty good someone else has been there. Make their image your wallpaper. When your co-workers comes, you can brag about what a great trip you had and how much cooler you are than them. Go ahead, gloat away. You&#8217;ve got the wallpaper to back it up.</li>
<li>Tent: So, you hiked all the way out into the woods so you can sleep INDOORS. Forget that. I have seen someone make a very sustainable shelter out of a rain tarp. You just need to be creative. Cavemen didn&#8217;t always make it back to the cave and they didn&#8217;t have REI either. What did they do? If the going gets really rough, you can sneak into your buddy&#8217;s tent.
<li> Water: I don&#8217;t think I need to ask this but what human do you know that will deny another person water?&#8230; and you can always count on others to carry water.
</ul>
<p>This only some of the great ideas that will be present in my new book on backpacking. Please e-mail to preorder it.</p>
]]></content:encoded>
			<wfw:commentRss>http://honoluluhacker.com/2010/06/24/honolulu-hackers-guide-to-lite-weight-backpacking/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Force download of fasta files and aln files with Apache</title>
		<link>http://honoluluhacker.com/2010/01/14/force-download-of-fasta-files-and-aln-files-with-apache/</link>
		<comments>http://honoluluhacker.com/2010/01/14/force-download-of-fasta-files-and-aln-files-with-apache/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 20:11:19 +0000</pubDate>
		<dc:creator>kenglish</dc:creator>
				<category><![CDATA[Bioinformatics]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://honoluluhacker.com/?p=998</guid>
		<description><![CDATA[If you are serving fasta files or alignment files on your server, you may want to force users to download them instead of previewing them in the browser. My application would return the fasta files as Content-Type text/plain. I wanted to force it to application/x-fasta and force download. This is accomplished rather easily in Apache [...]]]></description>
			<content:encoded><![CDATA[<p>If you are serving fasta files or alignment files on your server, you may want to force users to download them instead of previewing them in the browser. My application would return the fasta files as Content-Type text/plain. I wanted to force it to application/x-fasta and force download. This is accomplished rather easily in Apache with the following directive:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">  &lt;<span style="color: #000000; font-weight:bold;">FilesMatch</span> <span style="color: #7f007f;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>(?i:fasta)$&quot;</span>&gt;
    <span style="color: #00007f;">ForceType</span> application/x-fasta
    <span style="color: #00007f;">Header</span> set Content-Disposition attachment
  &lt;/<span style="color: #000000; font-weight:bold;">FilesMatch</span>&gt;
  &lt;<span style="color: #000000; font-weight:bold;">FilesMatch</span> <span style="color: #7f007f;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>(?i:aln)$&quot;</span>&gt;
    <span style="color: #00007f;">ForceType</span> application/x-aln
    <span style="color: #00007f;">Header</span> set Content-Disposition attachment
  &lt;/<span style="color: #000000; font-weight:bold;">FilesMatch</span>&gt;</pre></div></div>

<p>You will have to enable the apache module &#8220;mod_header&#8221; for this to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://honoluluhacker.com/2010/01/14/force-download-of-fasta-files-and-aln-files-with-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Ruby &amp; Hpricot to find lowest mortgage rate in Hawaii</title>
		<link>http://honoluluhacker.com/2009/12/14/using-ruby-hpricot-to-find-lowest-mortgage-rate-in-hawaii/</link>
		<comments>http://honoluluhacker.com/2009/12/14/using-ruby-hpricot-to-find-lowest-mortgage-rate-in-hawaii/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 05:39:27 +0000</pubDate>
		<dc:creator>kenglish</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://honoluluhacker.com/?p=958</guid>
		<description><![CDATA[Each week the Honolulu Board of Realtors publishes a report of Hawaii Mortgage Rates. To find the lowest rate for your category is difficult. A non-programming solution would be to copy it into excel, delete all the rows that you need and then sort by the rate column. This takes too much time so I [...]]]></description>
			<content:encoded><![CDATA[<p>Each week the Honolulu Board of Realtors publishes a report of <a href="http://www.hicentral.com/MortgageRates.asp">Hawaii Mortgage Rates</a>. To find the lowest rate for your category is difficult. A non-programming solution would be to copy it into excel, delete all the rows that you need and then sort by the rate column. This takes too much time so I wrote a ruby script that parses this data. This is also a demonstration of how to use the ruby tool Hpricot, an HTML Parser. You will need to install the Hpricot gem for this to work</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'hpricot'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open-uri'</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#term = '1-YR ARM'</span>
<span style="color:#008000; font-style:italic;">#term = '30-YR Fixed'</span>
term = <span style="color:#996600;">'15-YR Fixed'</span>
&nbsp;
doc = Hpricot.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://www.hicentral.com/MortgageRates.asp&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
&nbsp;
rates = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> 
lender_name = <span style="color:#996600;">&quot;&quot;</span>
&nbsp;
<span style="color:#006600; font-weight:bold;">&#40;</span>doc<span style="color:#006600; font-weight:bold;">/</span><span style="color:#996600;">&quot;table&quot;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#996600;">&quot;table&quot;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#996600;">&quot;tr&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span> row <span style="color:#006600; font-weight:bold;">|</span>
   arr =<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;">&#40;</span>row<span style="color:#006600; font-weight:bold;">/</span><span style="color:#996600;">&quot;td&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span> cell<span style="color:#006600; font-weight:bold;">|</span>  
     arr <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> cell.<span style="color:#9900CC;">inner_html</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
   <span style="color:#9966CC; font-weight:bold;">end</span>
   <span style="color:#9966CC; font-weight:bold;">if</span> arr<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> =~ <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">15</span><span style="color:#006600; font-weight:bold;">-</span>YR Fixed<span style="color:#006600; font-weight:bold;">/</span>
      lender_name = arr<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      arr.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span>lender_name<span style="color:#006600; font-weight:bold;">&#41;</span> 
      lender_name.<span style="color:#CC0066; font-weight:bold;">sub!</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'&lt;br /&gt;'</span>,<span style="color:#996600;">' - '</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
   <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">unless</span> arr<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> =~ <span style="color:#006600; font-weight:bold;">/</span><span style="color:#008000; font-style:italic;">#{term}/</span>
   lender_data =<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span> 
   lender_data<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:lender_name</span><span style="color:#006600; font-weight:bold;">&#93;</span> = lender_name    
   lender_data<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:term</span><span style="color:#006600; font-weight:bold;">&#93;</span> = arr<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> 
   lender_data<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:apr</span><span style="color:#006600; font-weight:bold;">&#93;</span> = arr<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_f</span>
   rates <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> lender_data
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
5.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span> rank <span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Losest Rate ##{rank+1}&quot;</span>
  row = rates.<span style="color:#9900CC;">min</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>a,b<span style="color:#006600; font-weight:bold;">|</span> a<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:apr</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;=&gt;</span> b<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:apr</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> 
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;  Name: #{row[:lender_name]}&quot;</span>  
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;  Term: #{row[:term]}&quot;</span> 
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;  APR: #{row[:apr]}&quot;</span>  
  rates.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span>row<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Here&#8217;s what&#8217;s going on:</p>
<ul>
<li>On line 7 you will notice that I am interested in the 15-Year mortgage rate. You can change this value to get the report for the term you want. </li>
<li>On line 9, the program will download the latest rates from the hicentral.com website and parse the page returning an hpricot doc object.</li>
<li>From line 14 to 30, the program parses each line in the mortgage rate table. The logic is custom to this table. The table is unusual because the lender name is first cell only on the first line (15-YR Fixed) for each lender. To accommodate this, we match the line that has &#8220;15-YR Fixed&#8221; in second position and delete the lender name from the array (lines 19-23). We then assign the data to our summary data structure (lines 25-29)</li>
<li>Finally, we show the top 5 lowest mortgage rates (lines 32-38). To do this we use the Ruby <a href="http://ruby-doc.org/core/classes/Enumerable.html#M003134">max</a> method (line 34). We delete the current max element so it is not counted in the next loop iteration (line 38).
</ul>
<p>Thomas Lecklider has a great tutorial on how to use  <a href="http://hpricot.com/">Hpricot</a> called <a href="http://lecklider.com/posts/4-using-hpricot-to-traverse-and-parse-html">Using Hpricot to Traverse and Parse HTML.</a></p>
<p>Your commends are welcome. Give some refactoring advice if you like. I have wordpress plugin for pre tag so to write ruby code just do:</p>
<p>&lt;pre lang=&quot;ruby&quot;&gt;<br />
puts YEAH<br />
&lt;/pre&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://honoluluhacker.com/2009/12/14/using-ruby-hpricot-to-find-lowest-mortgage-rate-in-hawaii/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A SQL Server file &#8216;basename&#8217; function</title>
		<link>http://honoluluhacker.com/2009/11/24/a-sql-server-file-basename-function/</link>
		<comments>http://honoluluhacker.com/2009/11/24/a-sql-server-file-basename-function/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 03:31:29 +0000</pubDate>
		<dc:creator>kenglish</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://honoluluhacker.com/?p=901</guid>
		<description><![CDATA[Given a file path: /var/www/html/index.html
Returns: index.html
Pretty common, here&#8217;s how you do it:
Perl:

use File::Basename; 
$fullname = &#34;/usr/local/src/perl-5.6.1.tar.gz&#34;; 
$file = basename&#40;$fullname&#41;;

PHP:

$path = &#34;/home/httpd/html/index.php&#34;;
$file = basename&#40;$path&#41;;

Ruby:

path = &#34;/usr/lib/ruby/site_ruby/1.8/rubygems/version.rb&#34;
File.basename path

Python:

import os.path
path =  &#34;/usr/local/bin/python&#34;
os.path.basename&#40;path&#41;

T-SQL (MsSQL Server):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
CREATE FUNCTION &#91;dbo&#93;.&#91;fn_file_basename&#93;
&#40;
	-- Add the parameters for the function here
	@file_path Varchar&#40;255&#41;
&#41;
RETURNS Varchar&#40;255&#41;
AS
BEGIN
    declare @file_basename varchar&#40;255&#41;
    IF charindex&#40;'\', @file_path) [...]]]></description>
			<content:encoded><![CDATA[<p>Given a file path: /var/www/html/index.html<br />
Returns: index.html</p>
<p>Pretty common, here&#8217;s how you do it:</p>
<p><b>Perl:</b></p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Basename</span><span style="color: #339933;">;</span> 
<span style="color: #0000ff;">$fullname</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;/usr/local/src/perl-5.6.1.tar.gz&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #0000ff;">$file</span> <span style="color: #339933;">=</span> basename<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$fullname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><b>PHP:</b></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/home/httpd/html/index.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><b>Ruby:</b></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">path = <span style="color:#996600;">&quot;/usr/lib/ruby/site_ruby/1.8/rubygems/version.rb&quot;</span>
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span> path</pre></div></div>

<p><b>Python:</b></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>
path =  <span style="color: #483d8b;">&quot;/usr/local/bin/python&quot;</span>
<span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">basename</span><span style="color: black;">&#40;</span>path<span style="color: black;">&#41;</span></pre></div></div>

<p><b>T-SQL (MsSQL Server):</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> <span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>fn_file_basename<span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#40;</span>
	<span style="color: #808080; font-style: italic;">-- Add the parameters for the function here</span>
	@file_path Varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
RETURNS Varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">AS</span>
BEGIN
    declare @file_basename varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #993333; font-weight: bold;">IF</span> charindex<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\'</span>, @file_path) != 0 
	   set @file_basename= reverse(substring(reverse(@file_path), 1, charindex('</span>\<span style="color: #ff0000;">', reverse(@file_path))-1))
	else
	   set @file_basename=@file_path
&nbsp;
	return @file_basename
END</span></pre></td></tr></table></div>

<p>My brilliant co-worker figured this out. The magic is done on line 11:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">reverse<span style="color: #66cc66;">&#40;</span>substring<span style="color: #66cc66;">&#40;</span>reverse<span style="color: #66cc66;">&#40;</span>@file_path<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> charindex<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\'</span>, reverse(@file_path))-1))</span></pre></div></div>

<p>It reverses the string, find the first occurance of the character &#8216;\&#8217;, takes the substring to that character and the reverses again. How elegant!</p>
]]></content:encoded>
			<wfw:commentRss>http://honoluluhacker.com/2009/11/24/a-sql-server-file-basename-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove Invalid XML Characters with an SSIS Visual Basic Script</title>
		<link>http://honoluluhacker.com/2009/11/24/remove-invalid-xml-characters-with-a-ssis-visual-basic-script/</link>
		<comments>http://honoluluhacker.com/2009/11/24/remove-invalid-xml-characters-with-a-ssis-visual-basic-script/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 03:05:47 +0000</pubDate>
		<dc:creator>kenglish</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://honoluluhacker.com/?p=895</guid>
		<description><![CDATA[My boss is forcing us to use Microsoft SQL Service Intergration Services for our ETL process. I Googled around for a bit and could not find a good example of how to do this simple task: open an XML file, read the text, replace any invalid characters and write it back out to the same [...]]]></description>
			<content:encoded><![CDATA[<p>My boss is forcing us to use Microsoft SQL Service Intergration Services for our ETL process. I Googled around for a bit and could not find a good example of how to do this simple task: open an XML file, read the text, replace any invalid characters and write it back out to the same file. My VB is very rusty but this works pretty well. The ReadVariable portion  is specific to SSIS but the rest should be generic. Hopefully, the next poor who needs to do this will be able to find this blog entry!</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Text.RegularExpressions
Imports System.<span style="color: #000080;">Object</span>
&nbsp;
&nbsp;
<span style="color: #000080;">Public</span> Class ScriptMain
&nbsp;
    <span style="color: #000080;">Public</span> <span style="color: #000080;">Sub</span> Main()
        Dts.TaskResult = Dts.Results.Success
        <span style="color: #000080;">Dim</span> strPath, strXML <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
        strPath = <span style="color: #000080;">CStr</span>(ReadVariable(<span style="color: #800000;">&quot;User::strFileName&quot;</span>))
        strXML = FileIO.FileSystem.ReadAllText(strPath)
&nbsp;
        <span style="color: #000080;">Dim</span> rgx <span style="color: #000080;">As</span> Regex = <span style="color: #000080;">New</span> Regex(<span style="color: #800000;">&quot;[\x00-\x08\x0B-\x0C\x0E-\x1F]&quot;</span>, RegexOptions.None)
        rgx.Replace(strXML, <span style="color: #800000;">&quot; &quot;</span>)
        FileIO.FileSystem.WriteAllText(strPath, strXML, <span style="color: #000080;">False</span>)
    <span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
    <span style="color: #000080;">Private</span> <span style="color: #000080;">Function</span> ReadVariable(<span style="color: #000080;">ByVal</span> varName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">Object</span>
        <span style="color: #000080;">Dim</span> result <span style="color: #000080;">As</span> <span style="color: #000080;">Object</span>
&nbsp;
        Try
            <span style="color: #000080;">Dim</span> vars <span style="color: #000080;">As</span> Variables
            Dts.VariableDispenser.LockForRead(varName)
            Dts.VariableDispenser.GetVariables(vars)
            Try
                result = vars(varName).Value
            Catch ex <span style="color: #000080;">As</span> Exception
                Throw ex
            Finally
                vars.Unlock()
            <span style="color: #000080;">End</span> Try
        Catch ex <span style="color: #000080;">As</span> Exception
            Throw ex
        <span style="color: #000080;">End</span> Try
&nbsp;
        Return result
    <span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #000080;">End</span> Class</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://honoluluhacker.com/2009/11/24/remove-invalid-xml-characters-with-a-ssis-visual-basic-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install NetBeans jVi plugin</title>
		<link>http://honoluluhacker.com/2009/11/22/install-netbeans-jvi-plugin/</link>
		<comments>http://honoluluhacker.com/2009/11/22/install-netbeans-jvi-plugin/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 21:34:08 +0000</pubDate>
		<dc:creator>kenglish</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://honoluluhacker.com/?p=828</guid>
		<description><![CDATA[NetBeans is the only IDE with a great VI key binding plugin. This was the sole reason I switched to NetBeans as my Ruby/Rails IDE of choice this year. There are 2 vi plugins for Eclipse: one you have to pay for and the other relies on gVIM. The NetBeans Vi plugin is called jVi [...]]]></description>
			<content:encoded><![CDATA[<p>NetBeans is the only IDE with a great VI key binding plugin. This was the sole reason I switched to NetBeans as my Ruby/Rails IDE of choice this year. There are 2 vi plugins for Eclipse: one you have to pay for and the other relies on gVIM. The NetBeans Vi plugin is called <a href="http://jvi.sourceforge.net/">jVi</a> and can be found at <a href="http://jvi.sourceforge.net/">http://jvi.sourceforge.net</a>. There are a few caveats and extra configuration options that you need to set. </p>
<ol>
<li><a href="http://sourceforge.net/projects/jvi/">Download the latest jVi release</a>. Unzip the file in your home directory. This will create the directory nbvi-1.2.6.</li>
<li>In the Netbeans menu bar, select Tools | Plugins. Click on the Downloaded tab.</li>
<li>Press the &#8220;Add Plugin&#8221; button. Browse to the nbvi-1.2.6 directory and select the two file: org-netbeans-modules-jvi.nbm and com-raelity-jvi.nbm. You should now have 2 plugins availabe in the downloaded list: jVi Key Bindings and jVi Core.</li>
<li>Click Install and then click through the installation process. NetBeans will need to restart.</li>
<li>After NetBeans has restarted, from the menu bar, select Tools | Options. Click on the last tab which should be jVi Config. </li>
<li>Select the &#8220;Buffer Modifications&#8221; panel in the jVi Config screen. </li>
<li>Make sure the &#8216;expandtab&#8217; value is checked. </li>
<li>Change the value of  &#8217;shiftwidth&#8217; to 2. </li>
<li>Change the value of  &#8216;tabstop&#8217; to 2.</li>
</ol>
<p>The last option for setting the tabstop and expandtab are pretty important. If you don&#8217;t use these, jVi will insert tabs into your Ruby files. This could cause your co-workers to complain about you ruining the formatting in the project. </p>
<p>Congratuations, jVi is now setup in NetBeans. Enjoy. </p>
<p><em>This blog entry was written for NetBeans 6.7 and with jVi version 1.2.6.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://honoluluhacker.com/2009/11/22/install-netbeans-jvi-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Parsing Emboss Water output with Ruby</title>
		<link>http://honoluluhacker.com/2009/11/20/parsing-emboss-water-output-with-ruby/</link>
		<comments>http://honoluluhacker.com/2009/11/20/parsing-emboss-water-output-with-ruby/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 18:29:14 +0000</pubDate>
		<dc:creator>kenglish</dc:creator>
				<category><![CDATA[Bioinformatics]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://honoluluhacker.com/?p=812</guid>
		<description><![CDATA[First, you will need to install the emboss suite on your computer:

sudo apt-get install emboss emboss-lib

If don&#8217;t already have the BioRuby installed, you will need that too:

sudo gem install bio --no-ri --no-rdoc

Your first ruby script calling Emboss Water from Ruby:

1
2
3
4
5
require 'rubygems'
require 'bio'
test_filename =ARGV.shift
target_filename =ARGV.shift
result = Bio::EMBOSS.run&#40;'water', '-asequence', test_filename, '-bsequence', target_filename&#41;

Unforntunately, there is not a nice [...]]]></description>
			<content:encoded><![CDATA[<p>First, you will need to install the emboss suite on your computer:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> emboss emboss-lib</pre></div></div>

<p>If don&#8217;t already have the <a href="http://bioruby.org/">BioRuby</a> installed, you will need that too:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> bio <span style="color: #660033;">--no-ri</span> <span style="color: #660033;">--no-rdoc</span></pre></div></div>

<p>Your first ruby script calling Emboss Water from Ruby:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'bio'</span>
test_filename =ARGV.<span style="color:#9900CC;">shift</span>
target_filename =ARGV.<span style="color:#9900CC;">shift</span>
result = <span style="color:#6666ff; font-weight:bold;">Bio::EMBOSS</span>.<span style="color:#9900CC;">run</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'water'</span>, <span style="color:#996600;">'-asequence'</span>, test_filename, <span style="color:#996600;">'-bsequence'</span>, target_filename<span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>Unforntunately, there is not a nice report result class in BioRuby for Emboss Water so you will have to parse the output yourself. Here&#8217;s an example script that finds percent similarity:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'bio'</span>
test_filename =ARGV.<span style="color:#9900CC;">shift</span>
target_filename =ARGV.<span style="color:#9900CC;">shift</span>
result = <span style="color:#6666ff; font-weight:bold;">Bio::EMBOSS</span>.<span style="color:#9900CC;">run</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'water'</span>, <span style="color:#996600;">'-asequence'</span>, test_filename, <span style="color:#996600;">'-bsequence'</span>, target_filename<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;"># result now has the text output of water...</span>
<span style="color:#008000; font-style:italic;"># Here's an example of looping through each line of the result to get the similary:</span>
&nbsp;
test_seq = <span style="color:#996600;">&quot;&quot;</span>
target_seq = <span style="color:#996600;">&quot;&quot;</span>
similarity = <span style="color:#996600;">''</span>
&nbsp;
&nbsp;
result.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span> line <span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#008000; font-style:italic;"># This mean</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> line =~ <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#008000; font-style:italic;"># Aligned_sequences/</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Seq '#{test_seq}' has similarity to Seq '#{target_seq}' of #{similarity}&quot;</span>  <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#006600; font-weight:bold;">&#40;</span>test_seq == <span style="color:#996600;">&quot;&quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>target_seq == <span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    test_seq = <span style="color:#996600;">&quot;&quot;</span>
    target_seq = <span style="color:#996600;">&quot;&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#008000; font-style:italic;"># Get sequence numbers </span>
  <span style="color:#9966CC; font-weight:bold;">if</span> line =~ <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#008000; font-style:italic;"># (\d+): (\d+)/</span>
     test_seq  = $<span style="color:#006666;">2</span> <span style="color:#9966CC; font-weight:bold;">if</span> $<span style="color:#006666;">1</span> == <span style="color:#996600;">'1'</span>
     target_seq = $<span style="color:#006666;">2</span> <span style="color:#9966CC; font-weight:bold;">if</span> $<span style="color:#006666;">1</span> == <span style="color:#996600;">'2'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#008000; font-style:italic;"># parse similarity</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> line =~ <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#008000; font-style:italic;"># Similarity:.*\((.*)%\)/</span>
    similarity  = $<span style="color:#006666;">1</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Seq '#{test_seq}' has similarity to Seq '#{target_seq}' of #{similarity}&quot;</span></pre></div></div>

<p>Place this in a file called water.rb and run it with <a href="http://github.com/kenglishhi/ics632/blob/master/ics675/emboss/fastas/frags.fasta">frags.fasta</a> and <a href="http://github.com/kenglishhi/ics632/blob/master/ics675/emboss/fastas/frags1.fasta">frags1.fasta</a> and the above script will output this.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ruby water.rb fastas<span style="color: #000000; font-weight: bold;">/</span>frags1.fasta frags.fasta 
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'1'</span> of <span style="color: #000000;">100.0</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'2'</span> of <span style="color: #000000;">96.6</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'3'</span> of <span style="color: #000000;">64.3</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'4'</span> of <span style="color: #000000;">97.9</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'5'</span> of <span style="color: #000000;">96.9</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'6'</span> of <span style="color: #000000;">94.1</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'7'</span> of <span style="color: #000000;">62.5</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'8'</span> of <span style="color: #000000;">61.1</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'9'</span> of <span style="color: #000000;">62.5</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'10'</span> of <span style="color: #000000;">57.1</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'11'</span> of <span style="color: #000000;">57.4</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'12'</span> of <span style="color: #000000;">97.8</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'13'</span> of <span style="color: #000000;">50.0</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'14'</span> of <span style="color: #000000;">62.5</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'15'</span> of <span style="color: #000000;">97.9</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'16'</span> of <span style="color: #000000;">62.5</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'17'</span> of <span style="color: #000000;">59.1</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'18'</span> of <span style="color: #000000;">55.9</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'19'</span> of <span style="color: #000000;">61.9</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'20'</span> of <span style="color: #000000;">60.0</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'21'</span> of <span style="color: #000000;">56.4</span>
Seq <span style="color: #ff0000;">'1'</span> has similarity to Seq <span style="color: #ff0000;">'22'</span> of <span style="color: #000000;">56.2</span></pre></div></div>

<p>Water is the worse name for a program, EVER. Because it is impossible to Google&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://honoluluhacker.com/2009/11/20/parsing-emboss-water-output-with-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Defining Class methods in a Module</title>
		<link>http://honoluluhacker.com/2009/11/20/defining-class-methods-in-a-module/</link>
		<comments>http://honoluluhacker.com/2009/11/20/defining-class-methods-in-a-module/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 18:09:44 +0000</pubDate>
		<dc:creator>kenglish</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://honoluluhacker.com/?p=791</guid>
		<description><![CDATA[The code should speak for itself. Make sense?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module Loveable
  module ClassMethods
    def give_hug
    end
  end
  def self.included&#40;base&#41;
    base.extend&#40;ClassMethods&#41;
  end
end
&#160;
class Person
  include Loveable
&#160;
  give_hug
&#160;
end

I fuzzy as to why a certain Rails genius would suggest it is better to do it this [...]]]></description>
			<content:encoded><![CDATA[<p>The code should speak for itself. Make sense?</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> Loveable
  <span style="color:#9966CC; font-weight:bold;">module</span> ClassMethods
    <span style="color:#9966CC; font-weight:bold;">def</span> give_hug
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">included</span><span style="color:#006600; font-weight:bold;">&#40;</span>base<span style="color:#006600; font-weight:bold;">&#41;</span>
    base.<span style="color:#9900CC;">extend</span><span style="color:#006600; font-weight:bold;">&#40;</span>ClassMethods<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Person
  <span style="color:#9966CC; font-weight:bold;">include</span> Loveable
&nbsp;
  give_hug
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>I fuzzy as to why a certain Rails genius would suggest it is better to do it this way<br />
(see line 7):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> Loveable
  <span style="color:#9966CC; font-weight:bold;">module</span> ClassMethods
    <span style="color:#9966CC; font-weight:bold;">def</span> give_hug
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">included</span><span style="color:#006600; font-weight:bold;">&#40;</span>base<span style="color:#006600; font-weight:bold;">&#41;</span>
    base.<span style="color:#9900CC;">send</span> <span style="color:#ff3333; font-weight:bold;">:extend</span>, ClassMethods
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Person
  <span style="color:#9966CC; font-weight:bold;">include</span> Loveable
&nbsp;
  give_hug
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Feel free to comment&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://honoluluhacker.com/2009/11/20/defining-class-methods-in-a-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install thoughtbot shoulda and rcov (the right way)</title>
		<link>http://honoluluhacker.com/2009/11/19/install-shoulda-and-rcov-the-right-way/</link>
		<comments>http://honoluluhacker.com/2009/11/19/install-shoulda-and-rcov-the-right-way/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 01:46:24 +0000</pubDate>
		<dc:creator>kenglish</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://honoluluhacker.com/?p=770</guid>
		<description><![CDATA[Install rcov &#038; ruby-prof  (rcov-0.9.6 &#038; ruby-prof-0.7.3 at the time of this writing).

sudo gem install ruby-prof rcov --no-ri --no-rdoc

Update your test/test_helper.rb, add:

require 'shoulda/rails'

Install Thoughbot&#8217;s Shoulda gem (shoulda-2.10.2 at the time of this writing). Make sure you have added GemCutter as one of your ruby gem sources. 

sudo gem install shoulda --no-ri --no-rdoc

Edit your applicaitons [...]]]></description>
			<content:encoded><![CDATA[<p>Install rcov &#038; ruby-prof  (rcov-0.9.6 &#038; ruby-prof-0.7.3 at the time of this writing).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> ruby-prof rcov <span style="color: #660033;">--no-ri</span> <span style="color: #660033;">--no-rdoc</span></pre></div></div>

<p>Update your test/test_helper.rb, add:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'shoulda/rails'</span></pre></div></div>

<p>Install Thoughbot&#8217;s Shoulda gem (shoulda-2.10.2 at the time of this writing). Make sure you have added <a href="http://gemcutter.org/">GemCutter</a> as one of your ruby gem sources. </p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> shoulda <span style="color: #660033;">--no-ri</span> <span style="color: #660033;">--no-rdoc</span></pre></div></div>

<p>Edit your applicaitons main Rakefile and add:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">'config'</span>, <span style="color:#996600;">'boot'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rake'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rake/testtask'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rake/rdoctask'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'tasks/rails'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'shoulda/tasks'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> run_coverage<span style="color:#006600; font-weight:bold;">&#40;</span>files<span style="color:#006600; font-weight:bold;">&#41;</span>
  rm_f <span style="color:#996600;">&quot;coverage&quot;</span>
  rm_f <span style="color:#996600;">&quot;coverage.data&quot;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># turn the files we want to run into a  string</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> files.<span style="color:#9900CC;">length</span> == <span style="color:#006666;">0</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;No files were specified for testing&quot;</span>
    <span style="color:#0000FF; font-weight:bold;">return</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  files = files.<span style="color:#9900CC;">join</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>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">if</span> PLATFORM =~ <span style="color:#006600; font-weight:bold;">/</span>darwin<span style="color:#006600; font-weight:bold;">/</span>
    exclude = <span style="color:#996600;">'--exclude &quot;gems/*&quot;'</span>
  <span style="color:#9966CC; font-weight:bold;">else</span>
    exclude = <span style="color:#996600;">'--exclude &quot;rubygems/*&quot;'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  rcov = <span style="color:#996600;">&quot;rcov --rails -Ilib:test --sort coverage --text-report #{exclude}  --aggregate coverage.data&quot;</span>
  cmd = <span style="color:#996600;">&quot;#{rcov} #{files}&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> cmd
  sh cmd
<span style="color:#9966CC; font-weight:bold;">end</span>
namespace <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Measures unit, functional, and integration test coverage&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:coverage</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run_coverage <span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;test/**/*.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  namespace <span style="color:#ff3333; font-weight:bold;">:coverage</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    desc <span style="color:#996600;">&quot;Runs coverage on unit tests&quot;</span>
    task <span style="color:#ff3333; font-weight:bold;">:units</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      run_coverage <span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;test/unit/**/*.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    desc <span style="color:#996600;">&quot;Runs coverage on functional tests&quot;</span>
    task <span style="color:#ff3333; font-weight:bold;">:functionals</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      run_coverage <span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;test/functional/**/*.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    desc <span style="color:#996600;">&quot;Runs coverage on integration tests&quot;</span>
    task <span style="color:#ff3333; font-weight:bold;">:integration</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      run_coverage <span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;test/integration/**/*.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Checkout your new coverage rake tasks:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">rake <span style="color:#006600; font-weight:bold;">-</span>T <span style="color:#006600; font-weight:bold;">|</span> grep cov</pre></div></div>

<p>Should show you:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">rake test:coverage                        <span style="color:#008000; font-style:italic;"># Measures unit, functional, and integration test coverage</span>
rake test:coverage:functionals            <span style="color:#008000; font-style:italic;"># Runs coverage on functional tests</span>
rake test:coverage:integration            <span style="color:#008000; font-style:italic;"># Runs coverage on integration tests</span>
rake test:coverage:units                  <span style="color:#008000; font-style:italic;"># Runs coverage on unit tests</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://honoluluhacker.com/2009/11/19/install-shoulda-and-rcov-the-right-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Already some haters of Google Closure</title>
		<link>http://honoluluhacker.com/2009/11/15/already-some-haters-of-google-closure/</link>
		<comments>http://honoluluhacker.com/2009/11/15/already-some-haters-of-google-closure/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 22:30:06 +0000</pubDate>
		<dc:creator>kenglish</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://honoluluhacker.com/?p=765</guid>
		<description><![CDATA[I saw this article on Sitepoint about Google Closure: How not to write JavaScript. The author claims that Closure is just Java programmers trying to make Javascript like Java. Having spent a lot of time doing ExtJS over the past few months, I&#8217;ve grown rather fond of Javascript. I would say the worst part about [...]]]></description>
			<content:encoded><![CDATA[<p>I saw this article on Sitepoint about <a href="http://www.sitepoint.com/blogs/2009/11/12/google-closure-how-not-to-write-javascript/#">Google Closure: How not to write JavaScript</a>. The author claims that Closure is just Java programmers trying to make Javascript like Java. Having spent a lot of time doing ExtJS over the past few months, I&#8217;ve grown rather fond of Javascript. I would say the worst part about it is the scoping problems. </p>
]]></content:encoded>
			<wfw:commentRss>http://honoluluhacker.com/2009/11/15/already-some-haters-of-google-closure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
