<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">

  <channel>
    <title>solog.co</title>
    <link>http://solog.co/</link>
    <description>solutions log</description>
    <language>en-us</language>
    <pubDate>Wed, 14 Sep 2011 13:42:52 PDT</pubDate>
    <lastBuildDate>Wed, 14 Sep 2011 13:42:52 PDT</lastBuildDate>

    
    <item>
      <title>Vim Cheat Sheet</title>
      <link>http://solog.co/system/vim-cheat-sheet.html</link>
      <pubDate>Wed, 31 Aug 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/system/vim-cheat-sheet.html</guid>
      <description>&lt;p&gt;This is a small collection of tips and tricks I have
collected for the vim text editor. This is by no means
complete or a tutorial on how to use vim. Just a set of
commands I don't want to forget, but don't use often
enough to burn into memory, yet.&lt;/p&gt;

&lt;p&gt;See the resources section below for a more complete
introduction and a set of in-depth tutorials.&lt;/p&gt;

&lt;h4&gt;Copy and Paste Registers&lt;/h4&gt;

&lt;p&gt;Vim has a clipboard history stored in registers, you can also use these registers to cut and paste items to.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;&lt;span class=&quot;c&quot;&gt;&amp;quot;ad     &amp;quot; cut something to register a&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;quot;ap     &amp;quot; paste something from register a&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;reg&lt;/span&gt;    &lt;span class=&quot;c&quot;&gt;&amp;quot; list registers&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h4&gt;Deleting Lines&lt;/h4&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;g&lt;span class=&quot;sr&quot;&gt;/regexp/&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;d&lt;/span&gt;    : delete &lt;span class=&quot;k&quot;&gt;all&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;lines&lt;/span&gt; that &lt;span class=&quot;k&quot;&gt;match&lt;/span&gt; regexp
&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;v&lt;span class=&quot;sr&quot;&gt;/regexp/&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;d&lt;/span&gt;    &lt;span class=&quot;c&quot;&gt;&amp;quot; delete all lines that do NOT regexp&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;20&lt;/span&gt;d       &lt;span class=&quot;c&quot;&gt;&amp;quot; delete lines 10-20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h4&gt;Buffer Management&lt;/h4&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;ls&lt;/span&gt;             &lt;span class=&quot;c&quot;&gt;&amp;quot; matching list buffers&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;b&lt;/span&gt; [&lt;span class=&quot;k&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;name]   &lt;span class=&quot;c&quot;&gt;&amp;quot; switch to buffer&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;b&lt;/span&gt;#             &lt;span class=&quot;c&quot;&gt;&amp;quot; switch to last buffer&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;bdel&lt;/span&gt; #         &lt;span class=&quot;c&quot;&gt;&amp;quot; delete buffer&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h4&gt;Record Macro&lt;/h4&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;&lt;span class=&quot;k&quot;&gt;qa&lt;/span&gt;              &lt;span class=&quot;c&quot;&gt;&amp;quot; start recording macro in buffer a&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;do stuff&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;q&lt;/span&gt;               &lt;span class=&quot;c&quot;&gt;&amp;quot; end recording&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h4&gt;Playback Macro&lt;/h4&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt; @a
 &lt;span class=&quot;m&quot;&gt;50&lt;/span&gt;@a  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;50&lt;/span&gt; times&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h4&gt;Map System Command to Key Stroke&lt;/h4&gt;

&lt;p&gt;Map ctrl-j d to run system command /tmp/x.py&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;imap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;=&lt;/span&gt;system&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/tmp/x.py&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;cr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h4&gt;Marks&lt;/h4&gt;

&lt;p&gt;Some nifty bits of navigation, create a mark and navigate back&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;vim&quot;&gt;&lt;span class=&quot;k&quot;&gt;ma&lt;/span&gt;    &lt;span class=&quot;c&quot;&gt;&amp;quot; mark spot label it a&lt;/span&gt;
&amp;#39;a    &lt;span class=&quot;c&quot;&gt;&amp;quot; jump to spot&lt;/span&gt;
&lt;span class=&quot;s1&quot;&gt;&amp;#39;&amp;#39;&lt;/span&gt;    &lt;span class=&quot;c&quot;&gt;&amp;quot; jump to last spot you were&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;hr /&gt;

&lt;h3&gt;Additional Resources&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.derekwyatt.org/vim/vim-tutorial-videos/&quot;&gt;Derek Wyatt's Vim Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://jeffrey-way.com/web-dev/vim-an-amuse-bouche/&quot;&gt;Vim: An Amuse-bouche&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://net.tutsplus.com/articles/web-roundups/25-vim-tutorials-screencasts-and-resources/&quot;&gt;25 Tutorial, Screencasts and Resources&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    
    <item>
      <title>Convert Wordpress Data to Jekyll</title>
      <link>http://solog.co/system/convert-wordpress-data-to-jekyll.html</link>
      <pubDate>Fri, 12 Aug 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/system/convert-wordpress-data-to-jekyll.html</guid>
      <description>&lt;p&gt;I recently converted &lt;strong&gt;solog&lt;/strong&gt;, this solutions log, from Wordpress to a Jekyll site. &lt;a href=&quot;https://github.com/mojombo/jekyll/wiki/&quot;&gt;Jekyll&lt;/a&gt; is a static site generator, written in ruby. It is a pretty basic tool which takes a set of files, applies templates and generates a web site. No database, admin site, plug-ins or constant upgrades needed. It is simple, but for a basic website, simple is all I need.&lt;/p&gt;

&lt;p&gt;To convert, I needed to extract the articles out of the Wordpress database and to basic files. I ran into some issues getting the included ruby import scripts to connect to the database, so I simply used MySQL's xml output. However, the output format wasn't easy to work with, so after struggling a bit on reading the data using scala, I switched to ruby's XML-Simple which made it much easier.&lt;/p&gt;

&lt;p&gt;Here are the scripts and procedures I used to convert Wordpress to Jekyll friendly files.&lt;/p&gt;

&lt;h3&gt;First dump database to XML&lt;/h3&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;mysql DB --xml -e &lt;span class=&quot;s2&quot;&gt;&amp;quot;SELECT post_title, post_name, \&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;  post_date, post_content, post_excerpt, ID, guid \&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;  FROM wp_posts WHERE post_status = &amp;#39;publish&amp;#39; AND \&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;  post_type = &amp;#39;post&amp;#39;&amp;quot;&lt;/span&gt; &amp;gt;posts.xml
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This outputs the content in a awkward XML format which all the elements have the same name and only different by attributes, thus the reason it was difficult to work with. Here's a brief segment of the XML to highlight the point.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;xml&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;resultset&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;row&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;field&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;post_title&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;How to Convert XML to JSON &lt;span class=&quot;nt&quot;&gt;&amp;lt;/field&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;field&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;post_name&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;how-to-convert-xml-to-json &lt;span class=&quot;nt&quot;&gt;&amp;lt;/field&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;field&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;post_date&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;2011-05-23 23:16:51 &lt;span class=&quot;nt&quot;&gt;&amp;lt;/field&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;field&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;post_content&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Download lift-json jar from
    ...
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;To parse in ruby, I used the xml-simple library which converts the XML to ruby objects. I initially tried using the built-in REXML library but I ran into the same issues I did with scala, using an xpath query is trickier when dealing with attributes.&lt;/p&gt;

&lt;p&gt;To install the library use: &lt;tt&gt;sudo gem install xml-simple&lt;/tt&gt;&lt;/p&gt;

&lt;h3&gt;Convert XML to Files&lt;/h3&gt;

&lt;p&gt;Here's the ruby script I used to convert the XML of all the posts to individual files.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;c1&quot;&gt;# Read in dump file and output markdown file  with metadata at top&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;xmlsimple&amp;#39;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;XmlSimple&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xml_in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;posts.xml&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;KeyAttr&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;field&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;row&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;field&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;post_title&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;vg&quot;&gt;$title&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;content&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;ID&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;vg&quot;&gt;$id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;content&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;post_name&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;vg&quot;&gt;$postname&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;content&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;post_content&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;vg&quot;&gt;$content&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;content&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;post_date&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;vg&quot;&gt;$date&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;content&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;# write out file&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;vg&quot;&gt;$postname&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;.md&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;myfile&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;w&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;myfile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;---&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;myfile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;layout: post&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;myfile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;title: &amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;vg&quot;&gt;$title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;myfile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;id: &amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;vg&quot;&gt;$id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;myfile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;date: &amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;vg&quot;&gt;$date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    
    &lt;span class=&quot;n&quot;&gt;myfile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;---&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;myfile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;vg&quot;&gt;$content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;myfile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;I then modified here and there to get how I wanted, I only had a dozen or so files I was dealing with, so the script isn't perfect. I'll come back when/if I decide to convert my long standing &lt;a href=&quot;http://mkaz.com/&quot;&gt;mkaz.com&lt;/a&gt; site with its hundreds of posts.&lt;/p&gt;

&lt;p&gt;Hope it helps.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3&gt;Additional Resources&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://rrees.wordpress.com/2009/06/01/semi-static-cmss/&quot;&gt;Semi-static CMSs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://vitobotta.com/migrating-from-wordpress-to-jekyll-part-one-why-I-gave-up-on-wordpress/&quot;&gt;Why I Gave Up on Wordpress&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://hmercer.com/2011/07/why-i-switched-to-jekyll/&quot;&gt;Why I Switched to Jekyll&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    
    <item>
      <title>How to Sort Collections in Scala</title>
      <link>http://solog.co/scala/how-to-sort-collections-in-scala.html</link>
      <pubDate>Tue, 28 Jun 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/scala/how-to-sort-collections-in-scala.html</guid>
      <description>&lt;p&gt;Here is a list of examples sorting different data structures in Scala, Lists and Arrays&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// data structures working with&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;d&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;F&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;B&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;e&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;Using the built-in &lt;tt&gt;sorted&lt;/tt&gt; method&lt;/p&gt;




&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sorted&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;res0&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;java.lang.String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sorted&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;res1&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// NOTE: map object does not have sorted method&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;h3&gt;Case Insensitive Search&lt;/h3&gt;




&lt;p&gt;Use &lt;tt&gt;sortWith&lt;/tt&gt; to create a custom comparison function for sorting case-insensitive.&lt;/p&gt;




&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;cm&quot;&gt;/* sort alphabetical and ignoring case */&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;compfn1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e1&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e2&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;compareToIgnoreCase&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/* sort alphabetical and ignoring case: alternate */&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;compfn2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e1&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e2&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toLowerCase&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toLowerCase&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sortWith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;compfn1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;res2&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;java.lang.String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sortWith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;compfn2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;res3&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;java.lang.String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/* Or you can do so using anonymous function (Thanks Rahul) */&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sortWith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toLowerCase&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toLowerCase&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;res4&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;java.lang.String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;h3&gt;How to Sort a Map by Key or Value&lt;/h3&gt;




&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// sort by key can use sorted&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sorted&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot; = &amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// sort by value&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toList&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sortBy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot; = &amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</description>
    </item>
    
    <item>
      <title>How to use Scala and Lucene to create a basic search application</title>
      <link>http://solog.co/scala/how-to-use-scala-and-lucene-to-create-a-basic-search-application.html</link>
      <pubDate>Sat, 18 Jun 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/scala/how-to-use-scala-and-lucene-to-create-a-basic-search-application.html</guid>
      <description>&lt;p&gt;How to use Scala and Lucene to create a basic search application. One of the powerful benefits of Scala is that it has full access to any Java libraries; giving you a tremendous number of available resources and technology. This example doesn't tap into the full power of Lucene, but highlights how easy it is to incorporate Java libraries into a Scala project.&lt;/p&gt;

&lt;p&gt;This example is based off a Twitter analysis app I've been noodling on; which I am utilizing Lucene. The code below takes a list of tweets from a text file; creates an index that you can search and extract info from.&lt;/p&gt;

&lt;p&gt;All code and working demo app available here: &lt;a href=&quot;https://github.com/mkaz/Scala-and-Lucene&quot;&gt;https://github.com/mkaz/Scala-and-Lucene&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Create the Index&lt;/h3&gt;


&lt;p&gt;For this example, the data are simply lines in a file; each line is a tweet to be indexed.
The indexer loops through the file creates a Lucene document from each line and adds it to the index.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;  &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;analyzer&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;StandardAnalyzer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Version&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;LUCENE_CURRENT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 
  &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;directory&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;NIOFSDirectory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;java&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;tmp/lucene&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;writer&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;IndexWriter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;directory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;analyzer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;IndexWriter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MaxFieldLength&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;UNLIMITED&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  
  &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fileLines&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fromFile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;data/tweets.txt&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getLines&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toList&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;fileLines&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; 
      &lt;span class=&quot;n&quot;&gt;writer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;addDocument&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;simpleDoc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
       
  &lt;span class=&quot;cm&quot;&gt;/** Simple Lucene Document */&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;simpleDoc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;doc&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Document&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;doc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;tweet&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Store&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;YES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;ANALYZED&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;TermVector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;YES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;doc&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;h3&gt;Retrieve Popular Terms from Index&lt;/h3&gt;


&lt;p&gt;This example extracts the terms from the index and sorts them based on frequency count. You could use this to see what's popular or common trends.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;allTerms&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;collection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mutable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;HashMap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;, &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]()&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reader&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;IndexReader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;directory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// create map of popular terms&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;terms&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;terms&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;terms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;allTerms&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;terms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;term&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;terms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;docFreq&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;  

    &lt;span class=&quot;c1&quot;&gt;// sort map &lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;allTerms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toList&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sortBy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;: &amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;h3&gt;Search Index&lt;/h3&gt;


&lt;p&gt;An example of a basic search using Lucene's term query.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;searcher&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;IndexSearcher&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;directory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;query&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TermQuery&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;tweet&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; 
    
    &lt;span class=&quot;c1&quot;&gt;// perform search, return top 10&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;docs&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;searcher&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;docs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;scoreDocs&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;docId&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;searcher&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;docId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;doc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;tweet&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This was just an introduction to using Lucene and Scala, showing the ease of leveraging existing Java libraries.  Lucene is a very powerful tool and provides numerous ways to store and query data; a more complex search app would utilize these features more in depth. Here's an example using &lt;a href=&quot;http://blog.fakod.eu/2010/11/02/spatial-lucene-example-in-scala/&quot;&gt;Lucene to perform Spatial Distance Searches&lt;/a&gt; and another example using &lt;a href=&quot;http://sujitpal.blogspot.com/2009/02/summarization-with-lucene.html&quot;&gt;Lucene to create Summarizations&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To learn more about Lucene, you should check out &lt;a href=&quot;http://www.amazon.com/gp/product/1933988177/ref=as_li_ss_tl?ie=UTF8&amp;tag=mkazcom-20&amp;linkCode=as2&amp;camp=217145&amp;creative=399369&amp;creativeASIN=1933988177&quot;&gt;Lucene in Action&lt;/a&gt; or other books available on the subject.&lt;/p&gt;

&lt;p&gt;I hope you found it useful.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>10 Scala One Liners to Impress Your Friends</title>
      <link>http://solog.co/scala/10-scala-one-liners-to-impress-your-friends.html</link>
      <pubDate>Tue, 31 May 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/scala/10-scala-one-liners-to-impress-your-friends.html</guid>
      <description>&lt;p&gt;Here are 10 one-liners which show the power of scala programming, impress your friends and woo women; ok, maybe not. However, these one liners are a good set of examples using functional programming and scala syntax you may not be familiar with. I feel there is no better way to learn than to see real examples.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Updated: June 17, 2011&lt;/b&gt; - I'm amazed at the popularity of this post, glad everyone enjoyed it and to see it duplicated across so many languages. I've included some of the suggestions to shorten up some of my scala examples. Some I intentionally left longer as a way for explaining / understanding what the functions were doing, not necessarily to produce the shortest possible code; so I'll include both.&lt;/p&gt;

&lt;h3&gt;1. Multiple Each Item in a List by 2&lt;/h3&gt;


&lt;p&gt;The &lt;tt&gt;map&lt;/tt&gt; function takes each element in the list and applies it to the corresponding function. In this example, we take each element and multiply it by 2. This will return a list of equivalent size, compare to other examples which use &lt;tt&gt;reduceLeft&lt;/tt&gt; and &lt;tt&gt;foldLeft&lt;/tt&gt;  those functions return only a single value not a list.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br/&gt;




&lt;h3&gt;2. Sum a List of Numbers&lt;/h3&gt;


&lt;p&gt;The most common example using &lt;tt&gt;reduceLeft&lt;/tt&gt; is summing a list of numbers. This example sums the numbers 1 to 1000 using the range function &lt;tt&gt;to&lt;/tt&gt; to create our lit of numbers and reduceLeft iterates and sum together returning a single value. Added simpler example using built-in sum function.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reduceLeft&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br/&gt;




&lt;h3&gt;3. Verify if Exists in a String&lt;/h3&gt;


&lt;p&gt;This example returns a boolean if a word in a list exists in a string. I used this example for checking if a tweet contains a word I'm interested in. I suppose technically it is three lines, but the first two are just setting variables.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wordList&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;scala&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;akka&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;play framework&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;sbt&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;typesafe&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tweet&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;This is an example tweet talking about scala and sbt.&amp;quot;&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wordList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;foldLeft&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tweet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contains&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; 
&lt;span class=&quot;n&quot;&gt;wordList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tweet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contains&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br/&gt;




&lt;h3&gt;4. Read in a File &lt;/h3&gt;


&lt;p&gt;This one-liner might only be impressive if you are coming from a Java background, it is pretty common now to be able to read a file in with one line of  code. Here are two examples of reading in a file, one reads entire file in to a string, the other reads in each line as an entry in a List.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fileText&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fromFile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;data.txt&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mkString&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fileLines&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fromFile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;data.txt&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getLines&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toList&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br/&gt;




&lt;h3&gt;5. Happy Birthday to You!&lt;/h3&gt;


&lt;p&gt;A common one-liner which prints out the Happy Birthday song. This illustrates scala's ternary operator as well as combining &lt;tt&gt;map&lt;/tt&gt; and &lt;tt&gt;foreach&lt;/tt&gt;.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Happy Birthday &amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;dear NAME&amp;quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;to You&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br/&gt;




&lt;h3&gt;6. Filter list of numbers &lt;/h3&gt;


&lt;p&gt;Filter a list of numbers into two categories based on a criteria using &lt;tt&gt;partition&lt;/tt&gt;.This example creates two lists of students based on their test scores.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;passed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;failed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;49&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;58&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;76&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;82&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;88&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;90&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;partition&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;60&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;   
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br/&gt;




&lt;h3&gt;7. Fetch and Parse an XML web service&lt;/h3&gt;


&lt;p&gt;Since XML is a native structure to scala, parsing an XML feed comes with no effort. Here's an example fetching the Twitter search feed.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;results&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;XML&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;http://search.twitter.com/search.atom?&amp;amp;q=scala&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br/&gt;




&lt;h3&gt;8. Find minimum (or maximum) in a List&lt;/h3&gt;


&lt;p&gt;Another couple of examples using &lt;tt&gt;reduceLeft&lt;/tt&gt; to iterate through a list and apply a function. Added simpler examples of the method min/max on the list.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;46&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;98&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reduceLeft&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;min&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;46&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;98&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;min&lt;/span&gt;

&lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;46&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;98&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reduceLeft&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;46&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;98&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br/&gt;




&lt;h3&gt;9. Parallel Processing&lt;/h3&gt;


&lt;p&gt;Scala 2.9 introduced a new collection type called &quot;parallel collections&quot; which utilize multi-core processors when performing bulk operations such as &lt;tt&gt;foreach&lt;/tt&gt;, &lt;tt&gt;map&lt;/tt&gt;, &lt;tt&gt;filter&lt;/tt&gt;, etc...  Here's a &lt;a href=&quot;http://days2010.scala-lang.org/node/138/140&quot;&gt;video of Aleksandar Prokopec explaining parallel collections&lt;/a&gt; at Scala Days 2010.&lt;/p&gt;

&lt;p&gt;This example is not quite a copy-and-paste into the REPL, but it illustrates how to use  parallel collections. Imagine you had a set of data defined in a list &lt;tt&gt;dataList&lt;/tt&gt; and a function &lt;tt&gt;processItem&lt;/tt&gt; which was very cpu intense. The following one-liner would give you parallel processing over the list.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dataList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;par&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;processItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br/&gt;




&lt;h3&gt;10. Sieve of Eratosthenes&lt;/h3&gt;


&lt;p&gt;Ok, this one isn't quite practical and technically is not a one-liner since it relies on a operator being previously defined, but it is still pretty darn cool, even if it is unreadable. &lt;a href=&quot;http://dcsobral.blogspot.com/2010/12/sieve-of-eratosthenes-real-one-scala.html&quot;&gt;Daniel Sobral&lt;/a&gt; created the Sieve of Eratosthenes which is a algorithm used to &lt;a href=&quot;http://mkaz.com/math/primes/prime_numbers.html&quot;&gt;determine if a number is prime&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;foldLeft&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;--&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Requires definition of |&gt; operator, a syntax borrowed from F#. See &lt;a href=&quot;http://stevegilham.blogspot.com/2009/01/pipe-operator-in-scala.html&quot;&gt;Steve Gilham's blog&lt;/a&gt; for an example.&lt;/p&gt;

&lt;br/&gt;



</description>
    </item>
    
    <item>
      <title>Functional Testing with Selenium WebDriver and Scala</title>
      <link>http://solog.co/scala/functional-testing-with-selenium-webdriver-and-scala.html</link>
      <pubDate>Sat, 28 May 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/scala/functional-testing-with-selenium-webdriver-and-scala.html</guid>
      <description>&lt;p&gt;Selenium's WebDriver tools can be used together with Scala, ScalaTest and sbt to create a great functional testing toolkit. This will give you the ability to test in various browsers, use a fast &quot;headless&quot; browser and even test iPhone and Android apps and web sites; though I haven't gotten to mobile testing yet.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://mkaz.com/img/icon_quality.jpg&quot; alt=&quot;100% Quality&quot; title=&quot;100% Quality&quot; border=&quot;0&quot; width=&quot;177&quot; height=&quot;180&quot; align=&quot;right&quot; /&gt; &lt;a href=&quot;http://code.google.com/p/selenium/&quot;&gt;WebDriver&lt;/a&gt; is a set of java libraries providing drivers which pass instructions to the browser allowing you to script control of a web page and verify results. These drivers start up your web browser on your computer and runs the tests; which you can watch as it goes. There are drivers for Firefox, IE, Safari, Chrome and as mentioned above iPhone and Android emulators. One of the great features of controlling a real browser is you can test real user interactions such as AJAX or other complex Javascript.&lt;/p&gt;

&lt;p&gt;Additionally there is an HtmlUnitDriver which does not control a browser, but uses the HtmlUnit library to simulate a browser, allowing these tests to run much faster since you are not waiting for a browser to start and passing data back and forth.&lt;/p&gt;

&lt;p&gt;The benefits I see using the WebDriver framework over regular Selenium tests is (1) faster tests running and (2) the ability to use a full set of programming paradigms around the tests. I find it easier to create scenarios and reusable tests by being able to create classes, extensions and normal programming logic. This is another benefit to using Scala with the &lt;a href=&quot;http://www.ibm.com/developerworks/java/library/j-scala04298/index.html&quot;&gt;power and extensibility of Scala Traits&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So let's jump in to some examples and see what capabilities the tools have.&lt;/p&gt;

&lt;h3&gt;Quick Start&lt;/h3&gt;


&lt;ol&gt;
    &lt;li&gt;Install Scala: &lt;a href=&quot;http://www.scala-lang.org/&quot;&gt;http://www.scala-lang.org/&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;Install SBT: &lt;a href=&quot;http://code.google.com/p/simple-build-tool/&quot;&gt;http://code.google.com/p/simple-build-tool/&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;Check out my scaft test framework from github: git://github.com/mkaz/scaft.git&lt;/li&gt;
    &lt;li&gt;Run tests&lt;/li&gt;
&lt;/ol&gt;




&lt;div id=&quot;divider&quot;&gt;&lt;/div&gt;




&lt;h3&gt;How to Run Tests with SBT&lt;/h3&gt;


&lt;p&gt;Start sbt&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sbt
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Run all tests&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt; &amp;gt; &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Run a single test&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt; &amp;gt; &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;-only GoogleSearch 
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;div id=&quot;divider&quot;&gt;&lt;/div&gt;




&lt;h3&gt;Developing Tests&lt;/h3&gt;


&lt;p&gt;Here's an example of a basic test, which will fetch the Google homepage and verify the title is correct.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.scalatest.FlatSpec&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.openqa.selenium._&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.openqa.selenium.htmlunit._&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;GoogleSearch&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;FlatSpec&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
 
  &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HtmlUnitDriver&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;http://www.google.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// verify we retrieved the page and have the title&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;&amp;quot;Google&amp;quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;have the proper title&amp;quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getTitle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Google&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;To verify specific elements exist on the page, you can select them in various ways, by html tag, class, id, form name and even using by using XPath queries. You'll want to bookmark the &lt;a href=&quot;http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html&quot;&gt;Web Driver API&lt;/a&gt; for reference.&lt;/p&gt;

&lt;p&gt;Here's an example using Google again, which will find the query input field by name, type in a query, submit and verify we received ten results and the term is in the the results set.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;GoogleSearch&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;FlatSpec&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
 
  &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HtmlUnitDriver&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;http://www.google.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// verify we retrieved the page and have the title&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;&amp;quot;Google&amp;quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;have the proper title&amp;quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getTitle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Google&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;be able to perform a query&amp;quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// do a search and confirm results&lt;/span&gt;
  
    &lt;span class=&quot;c1&quot;&gt;// get form element&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inputElement&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;findElement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;By&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;q&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// type in search query&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;inputElement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendKeys&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;vizsla puppies&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  
    &lt;span class=&quot;c1&quot;&gt;// submit form - can be done from any form element &lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// you dont need to locate the submit button&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;inputElement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;submit&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;   
  
  &lt;span class=&quot;c1&quot;&gt;// after a page submit, the driver object will be &lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// on the next page, so now we can test results&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;have ten results&amp;quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// find result set block&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;resultSet&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;findElementById&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;rso&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;// count # of results&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lis&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;resultSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;findElements&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;By&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tagName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;li&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  
  &lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;have term in result set&amp;quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;firstResult&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;findElement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;By&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xpath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;//*[@id=&amp;#39;rso&amp;#39;]/li[1]/h3&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;firstResult&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getText&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;contains&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;vizsla puppies&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;div id=&quot;divider&quot;&gt;&lt;/div&gt;




&lt;h3&gt;Using Firefox Driver for Ajax&lt;/h3&gt;


&lt;p&gt;Here's an ajax interactive example using Google Maps. The test will go to Google Maps, perform a search and verify the results, which are returned via ajax.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;cm&quot;&gt;/**&lt;/span&gt;
&lt;span class=&quot;cm&quot;&gt;  * Test of Google Maps - Firefox Driver&lt;/span&gt;
&lt;span class=&quot;cm&quot;&gt;  * verify map search and ajax result&lt;/span&gt;
&lt;span class=&quot;cm&quot;&gt;  */&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;GoogleMaps&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;FlatSpec&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
 
  &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;FirefoxDriver&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;http://maps.google.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// verify we retrieve the page and have the title&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;&amp;quot;Google Maps&amp;quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;have the proper title&amp;quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getTitle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Google Maps&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;be able to perform a query&amp;quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  
    &lt;span class=&quot;c1&quot;&gt;// get form element&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inputElement&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;findElement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;By&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;q&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// type in search query&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;inputElement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendKeys&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;San Francisco&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  
    &lt;span class=&quot;c1&quot;&gt;// submit form&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;inputElement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;submit&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// find span with place title&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;have the proper location title&amp;quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;titleElement&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;findElement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;By&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xpath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;//span[@class=&amp;#39;pp-place-title&amp;#39;]/span&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;titleElement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getText&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;San Francisco, CA&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;div id=&quot;divider&quot;&gt;&lt;/div&gt;




&lt;h3&gt;Additional Resources&lt;/h3&gt;


&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://www.scalatest.org/&quot;&gt;ScalaTest&lt;/a&gt; - The tests are written using ScalaTest, which supports several different ways to create tests.&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://watir.com/&quot;&gt;Watir&lt;/a&gt;, a similar functional test tool using Ruby&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://geb.codehaus.org/&quot;&gt;Geb&lt;/a&gt;, another similar functinoal test tool using Groovy&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    
    <item>
      <title>Using Scala with JDBC to connect to MySQL</title>
      <link>http://solog.co/scala/using-scala-with-jdbc-to-connect-to-mysql.html</link>
      <pubDate>Fri, 27 May 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/scala/using-scala-with-jdbc-to-connect-to-mysql.html</guid>
      <description>&lt;p&gt;A howto on connecting Scala to a MySQL database using JDBC. There are a number of database libraries for Scala, but I ran into a problem getting most of them to work. I attempted to use scala.dbc, scala.dbc2, Scala Query and Querulous but either they aren't supported, have a very limited featured set or abstracts SQL to a weird pseudo language.&lt;/p&gt;

&lt;p&gt;The Play Framework has a new database library called &lt;a href=&quot;http://scala.playframework.org/documentation/scala-0.9/anorm&quot;&gt;ANorm&lt;/a&gt; which tries to keep the interface to basic SQL but with a slight improved scala interface. The jury is still out for me, only used on one project minimally so far. Also, I've only seen it work within a Play app, does not look like it can be extracted out too easily.&lt;/p&gt;

&lt;p&gt;So I ended up going with basic Java JDBC connection and it turns out to be a fairly easy solution.&lt;/p&gt;

&lt;p&gt;Here is the code for accessing a database using Scala and JDBC. You need to change the connection string parameters and modify the query for your database. This example was geared towards MySQL, but any Java JDBC driver should work the same with Scala.&lt;/p&gt;

&lt;h3&gt;Basic Query&lt;/h3&gt;




&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;java.sql.&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Connection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DriverManager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ResultSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Change to Your Database Config&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn_str&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;jdbc:mysql://localhost:3306/DBNAME?user=DBUSER&amp;amp;password=DBPWD&amp;quot;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Load the driver &lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;classOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;com.mysql.jdbc.Driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Setup the connection&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DriverManager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getConnection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn_str&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Configure to be Read Only&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;statement&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;createStatement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;ResultSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;TYPE_FORWARD_ONLY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ResultSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CONCUR_READ_ONLY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Execute Query&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rs&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;executeQuery&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;SELECT quote FROM quotes LIMIT 5&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Iterate Over ResultSet&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;quote&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt;  
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;You will need to download the mysql-connector jar. &lt;a href=&quot;http://www.mysql.com/downloads/connector/j/&quot;&gt;Download the mysql connector jar from here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or if you are using maven, the pom snippets to load the mysql connector, you'll need to check what the latest version is.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;xml&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;mysql&lt;span class=&quot;nt&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;mysql-connector-java&lt;span class=&quot;nt&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;5.1.12&lt;span class=&quot;nt&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;To run the example, save the following to a file (query_test.scala) and run using, the following specifying the classpath to the connector jar:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;scala -cp mysql-connector-java-5.1.12.jar:. query_test.scala &lt;/code&gt;&lt;/p&gt;

&lt;br/&gt;




&lt;h3&gt;Insert, Update and Delete&lt;/h3&gt;


&lt;p&gt;To perform an insert, update or delete you need to create an updatable statement object. The execute command is slightly different and you will most likely want to use some sort of parameters. Here's an example doing an insert using jdbc and scala with parameters.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// create database connection&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dbc&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;jdbc:mysql://localhost:3306/DBNAME?user=DBUSER&amp;amp;password=DBPWD&amp;quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;classOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;com.mysql.jdbc.Driver&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DriverManager&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getConnection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dbc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;statement&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;createStatement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;ResultSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;TYPE_FORWARD_ONLY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ResultSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CONCUR_UPDATABLE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// do database insert&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prep&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prepareStatement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;INSERT INTO quotes (quote, author) VALUES (?, ?) &amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;prep&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Nothing great was ever achieved without enthusiasm.&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;prep&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Ralph Waldo Emerson&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;prep&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;executeUpdate&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</description>
    </item>
    
    <item>
      <title>Git Snippets</title>
      <link>http://solog.co/system/create-new-remote-git-repository.html</link>
      <pubDate>Tue, 24 May 2011 20:42:23 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/system/create-new-remote-git-repository.html</guid>
      <description>&lt;h2&gt;Create New Remote Git Repository&lt;/h2&gt;

&lt;p&gt; This solution is how to create a remote git repository and push your local files.&lt;/p&gt;

&lt;h4&gt;Remote Server&lt;/h4&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt; &lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /opt/git
 mkdir MYPROJ.git
 &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;MYPROJ.git
 git --bare init
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h4&gt;Local&lt;/h4&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt; &lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /MYPROJ
 git init
 git add *
 git commit -a -m &lt;span class=&quot;s1&quot;&gt;&amp;#39;my initial commit&amp;#39;&lt;/span&gt;
 git remote add origin ssh://SERVER/opt/git/MYPROJ.git
 git push origin master
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Git Basics&lt;/h2&gt;

&lt;h4&gt;Revert Your Changes to Repository Version&lt;/h4&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt; &lt;span class=&quot;c&quot;&gt;# single file change&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout FILENAME

    &lt;span class=&quot;c&quot;&gt;# revert all changes&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout -f
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</description>
    </item>
    
    <item>
      <title>Using Regular Expressions in Scala</title>
      <link>http://solog.co/scala/using-regular-expressions-in-scala.html</link>
      <pubDate>Tue, 24 May 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/scala/using-regular-expressions-in-scala.html</guid>
      <description>&lt;p&gt;The easiest way of creating a regular expression in scala is by simply applying the &lt;tt&gt;.r&lt;/tt&gt; method to a string. This creates a regular expression object, which then can be used to match and/or replace. See &lt;a href=&quot;http://www.scala-lang.org/api/current/scala/util/matching/Regex.html&quot;&gt;Regex API&lt;/a&gt; for available methods.&lt;/p&gt;

&lt;h3&gt;Regular Expression - Linkify a string&lt;/h3&gt;


&lt;p&gt;This regular expression will find a URL in a string and autolink it, replacing it with an HTML version of the link.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;linked&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Some text. http://mkaz.com/ and a link&amp;quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;regexUrl&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;&amp;quot;&amp;quot;http:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&amp;amp;\?\/.=]+&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;linked&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;regexUrl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;replaceAllIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linked&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;&amp;lt;a href=\&amp;quot;$0\&amp;quot;&amp;gt;$0&amp;lt;/a&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br/&gt;




&lt;h3&gt;Regular Expression - check if there is a match&lt;/h3&gt;


&lt;p&gt;Here is a function I wrote to return a flag if the string matched a word list, I needed a case insensitive match otherwise I could have simply used &lt;tt&gt;contains&lt;/tt&gt;. I'm not sure if my solution is the most efficient way of doing this one, feels a bit ugly to me, but it works. I'm open for improvements.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;existsFlag&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rtn&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
   &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;words&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;dress&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;choir&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;youtube&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;words&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;word&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rx&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;(?i)&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;word&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// (?i) is used for case insensitive&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;rx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;findFirstMatchIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;match&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; 
        &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Some&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;thing&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rtn&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; 
        &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// I dont want to do anything with this case&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;rtn&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</description>
    </item>
    
    <item>
      <title>How to read a file in Scala</title>
      <link>http://solog.co/scala/how-to-read-a-file-in-scala.html</link>
      <pubDate>Tue, 24 May 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/scala/how-to-read-a-file-in-scala.html</guid>
      <description>

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fromFile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;file.txt&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getLines&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
 
&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</description>
    </item>
    
    <item>
      <title>Delete Duplicate Records from Table</title>
      <link>http://solog.co/mysql/delete-duplicate-records-from-table.html</link>
      <pubDate>Tue, 24 May 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/mysql/delete-duplicate-records-from-table.html</guid>
      <description>

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;mysql&quot;&gt;&lt;span class=&quot;k&quot;&gt;DELETE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;table1&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;USING&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;table1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;table1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vtable&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;table1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vtable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
     &lt;span class=&quot;k&quot;&gt;AND&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;table1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vtable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</description>
    </item>
    
    <item>
      <title>Date Calculations in Scala</title>
      <link>http://solog.co/scala/date-calculations-in-scala.html</link>
      <pubDate>Tue, 24 May 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/scala/date-calculations-in-scala.html</guid>
      <description>&lt;p&gt;A couple of solutions for formatting and calculating dates. These examples use the joda library, included with Play by default.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.joda.time.DateTime&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.joda.time.format.DateTimeFormatter&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.joda.time.format.DateTimeFormat&lt;/span&gt;
 
&lt;span class=&quot;c1&quot;&gt;// create new date, yr, mon, day, hr, min, sec, ms&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myDate&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DateTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2010&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 
 
&lt;span class=&quot;c1&quot;&gt;// date calculations&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oneMonthLater&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myDate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plusMonths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;twoMonthsBefore&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myDate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;minusMonths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;twoDaysLater&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myDate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;minusDays&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// accepts negative values&lt;/span&gt;
 
&lt;span class=&quot;c1&quot;&gt;// formatting&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myDate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;yyyy-MM-dd&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
 
&lt;span class=&quot;nc&quot;&gt;DateTimeFormatter&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ISODateTimeFormat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dateTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
 
&lt;span class=&quot;n&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myDate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;See &lt;a href=&quot;http://joda-time.sourceforge.net/apidocs/index.html&quot;&gt;API&lt;/a&gt; for additional info. Plus &lt;a href=&quot;http://joda-time.sourceforge.net/userguide.html&quot;&gt;User Guide&lt;/a&gt; and documentation for &lt;a href=&quot;http://joda-time.sourceforge.net/field.html&quot;&gt;Field Accessors&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>How to Convert XML to JSON</title>
      <link>http://solog.co/scala/how-to-convert-xml-to-json.html</link>
      <pubDate>Mon, 23 May 2011 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/scala/how-to-convert-xml-to-json.html</guid>
      <description>&lt;p&gt;Download lift-json jar from &lt;a href=&quot;http://scala-tools.org/repo-releases/net/liftweb/&quot;&gt;http://scala-tools.org/repo-releases/net/liftweb/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Be sure to grab the proper library for your Scala version, at time of this post the latest was located at &lt;a href=&quot;http://scala-tools.org/repo-releases/net/liftweb/lift-json_2.8.1/2.3-RC5/&quot;&gt;http://scala-tools.org/repo-releases/net/liftweb/lift-json_2.8.1/2.3-RC5/&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;scala&quot;&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;net.liftweb.json._&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;net.liftweb.json.JsonAST._&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xml&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;XML&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loadFile&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;quotie.xml&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Printer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pretty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Xml&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toJson&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)))&lt;/span&gt;   
 
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;out_file&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;java&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;FileOutputStream&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;quotie.json&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;out_stream&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;java&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;PrintStream&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out_file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
 
&lt;span class=&quot;n&quot;&gt;out_stream&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;out_stream&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



</description>
    </item>
    
    <item>
      <title>How to use HTML5 local storage</title>
      <link>http://solog.co/webdev/how-to-use-html5-local-storage.html</link>
      <pubDate>Sun, 07 Nov 2010 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/webdev/how-to-use-html5-local-storage.html</guid>
      <description>&lt;p&gt;A quick example on how to use HTML5 local storage, I was surprised on how easy it is to use. HTML5 introduces two new methods of storing local information on a user's browser, &lt;strong&gt;localStorage&lt;/strong&gt; and &lt;strong&gt;sessionStorage&lt;/strong&gt;. They are both used the same way, however localStorage persists while sessionStorage, as you would imagine only lasts as long as the browser's session.&lt;/p&gt;

&lt;p&gt;Previously the only way to store data on a local desktop was to use cookies, which are limited in how much you can store. So the typical usage became storing a unique identifier for a user in the cookie, and using that to query a remote server to retrieve any data for that user. With local storage, you can avoid some back and forth, speed up the experience and possibly provide better security. More on that later, lets jump into the code.&lt;/p&gt;

&lt;p&gt;There are two basic methods, one for setting an item in storage and one for getting that item, they are:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// store item&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;item_key&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;value I am storing&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// retrieve item&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;item_key&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;That's it.&lt;/p&gt;

&lt;p&gt;The storage saves values as strings, so if you want to store a different type of data object, such as an array or javascript object. You will need to JSONify, here's an example storing an array.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;listdata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// store array back to localstorage&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;list_data_key&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;nx&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listdata&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// retrieve jsonified stored data and convert&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;storedData&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;listData&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;storedData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;listdata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;storedData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;There are a few other helper functions that you will probably use:&lt;/p&gt;

&lt;p&gt;Remove Single Key: &lt;code&gt;localStorage.removeItem(&quot;item_key&quot;);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Clear All Local Storage: &lt;code&gt; localStorage.clear() &lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Check if localStorage is supported:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;localStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
  &lt;span class=&quot;c1&quot;&gt;// yes!&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Those are the basics of local storage.&lt;/p&gt;

&lt;p&gt;Local storage is very similar to cookies in that the data is shared across all pages on the same domain. You'll have to weigh browser compatibility if you plan to use it, localStorage and sessionStorage are supported by Firefox 3.5, Safari 4.0, and IE8. Check &lt;a href=&quot;http://quirksmode.org&quot;&gt;quirksmode.org&lt;/a&gt; for details.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3&gt;Application Usage&lt;/h3&gt;

&lt;p&gt;One area that localStorage can be particularly useful is stand-alone HTML page apps. This is what initially prompted my looking into localStorage, I wanted to build a simple checklist. There are so many existing To Do List apps on the web and phone, but none allow importing and I had a file with a 100+ items in it, which I wanted to work through. Nothing permanent, but needed to check them off and store progress over a few days. I could've easier fired up Excel and sucked them in there, but that's not real fun.&lt;/p&gt;

&lt;p&gt;So I created a simple stand-alone web page app, which will keep track of the items from session to session. You can download and check out this app here, &lt;a href=&quot;/webdev/html5_localstorage.html&quot;&gt;HTML5 Local Storage Checklist&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Over the years, I've seen a few other stand-alone HTML page apps that could use this, such as &lt;a href=&quot;http://tiddlywiki.org/&quot;&gt;TiddlyWiki&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A huge draw back is this only works on one computer and one browser, you can't switch browsers or access remotely. So your app usage must take that in mind.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;
As I mentioned above, security might be another interesting area to utilize local storage. I work at BabyCenter, and there are a couple of applications and tools we have shied away from which required storing personal health information. You enter a new world of regulations if you store a user's health information, Hello &lt;a href=&quot;http://www.hhs.gov/ocr/privacy/&quot;&gt;HIPAA&lt;/a&gt;. However, you could utilize local storage to keep that information on the user's machine and never store.&lt;/p&gt;

&lt;p&gt;You still have the issues of persisting the data for long term and across multiple machines, ability to back up and restore, but might be an interesting possibility.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Data URI Scheme, a great replacement of sprite maps</title>
      <link>http://solog.co/webdev/data-uri-scheme-a-replacement-of-sprite-maps.html</link>
      <pubDate>Wed, 30 Jun 2010 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/webdev/data-uri-scheme-a-replacement-of-sprite-maps.html</guid>
      <description>&lt;p&gt;One of my colleagues recently forwarded this slide presentation about Mobile Web Performance that he saw at the Velocity Conference. I'm leading a large mobile web project at our company, which conveniently enough, we were just discussing the need for sprite maps to reduce the number of requests.&lt;/p&gt;

&lt;p&gt;So taking one of my engineer's suggestion and the above presentation I learned about &lt;em&gt;Data URI Scheme&lt;/em&gt;, which is a way to use encoded data sent to the browser as text instead of a separate file, such as an image file.&lt;/p&gt;

&lt;p&gt;Here's an example of a simple red square:&lt;/p&gt;

&lt;pre&gt;
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF/wAAAAAAQaMSAwAAABJJREFUeNpiYBgFo2AwAIAAAwACigABtnCV2AAAAABJRU5ErkJggg==
&lt;/pre&gt;


&lt;p&gt;You can display directly by putting that in an IMG tag:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF/wAAAAAAQaMSAwAAABJJREFUeNpiYBgFo2AwAIAAAwACigABtnCV2AAAAABJRU5ErkJggg==&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;In a browser, it shows like so (no external file needed):  &lt;img src=&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF/wAAAAAAQaMSAwAAABJJREFUeNpiYBgFo2AwAIAAAwACigABtnCV2AAAAABJRU5ErkJggg==&quot;/&gt;&lt;/p&gt;

&lt;p&gt;You should see a &quot;red square&quot; image above, assuming you are using Firefox, Safari or Chrome. Unfortunately, IE7 does not work; IE8 claims some support, but I did not have any luck with my testing.&lt;/p&gt;

&lt;p&gt;So once again our cool new fancy technique can't be used because of browser support, right? Wrong, IE is a fraction of the mobile web market. It is dominated by webkit browsers, which do support it. Particularly nice since mobile is an area where every requests makes a difference, considering the spotty networks and under powered phones (compared to a desktop browser)&lt;/p&gt;

&lt;h3&gt;Using with CSS&lt;/h3&gt;

&lt;p&gt;Now, you don't necessarily want to include the data in an HTML file, because you won't get the benefit of &lt;strong&gt;caching&lt;/strong&gt;. Here's an example of the Data URI Scheme used within CSS:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;css&quot;&gt;&lt;span class=&quot;nc&quot;&gt;.red_square&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;background&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;url(&amp;#39;data:image/png;base64,[encoding]&amp;#39;)&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Replacing [encoding] with the large string, no line breaks or spaces, but keep the quotes. Than any where you want to use that image,  just reference the CSS;&lt;/p&gt;

&lt;pre&gt;&amp;lt;div class=&quot;red_square&quot;/&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;


&lt;p&gt;You can collect up similar and common items that you might of previously put in a sprite map in a single css file. If you use a &lt;a href=&quot;http://en.wikipedia.org/wiki/Content_delivery_network&quot;&gt;CDN&lt;/a&gt;, such as Akamai, or even just using the browser cache, you'll end of delivering multiple images in a single request which can be cached.&lt;/p&gt;

&lt;p&gt;Using the Data URI Scheme it is easy to update a single image, which in a sprite map could be tricky. Also it simplifies the reference of the images without requiring a more complex coordinate selection of images which is typically done in &lt;a href=&quot;http://www.alistapart.com/articles/sprites&quot;&gt;CSS sprites&lt;/a&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3&gt;How to Create Base64 Encoding&lt;/h3&gt;

&lt;p&gt;There are a few ways to encode a file to base64, there is a unix program aptly called *base64** which is what I use; I installed using MacPorts, on Ubuntu you can  install with a simple apt-get. If those don't work for you, you can try an online base64 generator.&lt;/p&gt;

&lt;p&gt;To encode:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;base64 red_square.png
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;It will spit out the encoded string, you'll have to remove any line breaks that get included. If you are on a Mac, there a couple of nice clipboard unix tools that make it even easier. You can pipe output into pbcopy which will place the output in your clipboard buffer. Ready to be pasted in.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;base64 red_square.png | pbcopy
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The base64 utility can also decode a string back to the original file. To do that save the encoded string to a file such as encoded.txt and run base64 with the --decode parameter, like so&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;base64 --decode encoded.txt &amp;gt;red_square_decoded.png
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This makes it easy to &quot;recover&quot; the original images if all you had was the CSS files.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;I think this is a great technique to reduce complexity for accessing images and provide greater performance to our mobile users. We've already started implementing across our mobile sites.&lt;/p&gt;

&lt;h4&gt;Further Reading&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://www.slideshare.net/firt/mobile-web-high-performance&quot; title=&quot;&quot;&gt;Mobile Web Performance&lt;/a&gt; presentation by Maximiliano Firtman&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Data_URI_scheme&quot;&gt;Data URI Scheme&lt;/a&gt; (Wikipedia)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://www.fourmilab.ch/webtools/base64/&quot;&gt;Base64 Unix Utility&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://www.mobilefish.com/services/base64/base64.php&quot;&gt;Online Base64 Generator&lt;/a&gt; (MobileFish)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    
    <item>
      <title>Xterm Colors</title>
      <link>http://solog.co/system/xterm-colors.html</link>
      <pubDate>Sun, 04 Apr 2010 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/system/xterm-colors.html</guid>
      <description>&lt;p&gt;An update to my previous xterm colors page, removed duplicates and fixed issues with two word colors. These colors are from the command &quot;showrgb&quot; and can be used for various X11 things. The primary spot I use them is for coloring the foreground/background in xterm.&lt;/p&gt;

&lt;p&gt;Example:
&lt;code&gt; xterm -fg LightGoldenrod1 -bg CornflowerBlue&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can View Source or use Firebug or Color Picker to get RGB values.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3&gt;XTerm RGB Colors&lt;/h3&gt;

&lt;p&gt; &lt;style type=&quot;text/css&quot;&gt;
  .box {&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;width: 90px; 
height: 80px;
min-width:90px;
float:left;
margin:25px;
line-height: 0.4em !important;
text-align:center;
font-family: Verdana, sans-serif;
font-size: 10px;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;}
  .cbox { width: 60px; height: 60px; border: 1px solid black; margin-left: 10px;}
&lt;/style&gt;&lt;/p&gt;

&lt;div class=&quot;clearfix&quot;&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(240, 248, 255)'&gt;&lt;/div&gt;&lt;br/&gt;AliceBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(250, 235, 215)'&gt;&lt;/div&gt;&lt;br/&gt;AntiqueWhite&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 239, 219)'&gt;&lt;/div&gt;&lt;br/&gt;AntiqueWhite1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 223, 204)'&gt;&lt;/div&gt;&lt;br/&gt;AntiqueWhite2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 192, 176)'&gt;&lt;/div&gt;&lt;br/&gt;AntiqueWhite3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 131, 120)'&gt;&lt;/div&gt;&lt;br/&gt;AntiqueWhite4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 235, 205)'&gt;&lt;/div&gt;&lt;br/&gt;BlanchedAlmond&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(138, 43, 226)'&gt;&lt;/div&gt;&lt;br/&gt;BlueViolet&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(95, 158, 160)'&gt;&lt;/div&gt;&lt;br/&gt;CadetBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(152, 245, 255)'&gt;&lt;/div&gt;&lt;br/&gt;CadetBlue1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(142, 229, 238)'&gt;&lt;/div&gt;&lt;br/&gt;CadetBlue2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(122, 197, 205)'&gt;&lt;/div&gt;&lt;br/&gt;CadetBlue3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(83, 134, 139)'&gt;&lt;/div&gt;&lt;br/&gt;CadetBlue4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(100, 149, 237)'&gt;&lt;/div&gt;&lt;br/&gt;CornflowerBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 0, 139)'&gt;&lt;/div&gt;&lt;br/&gt;DarkBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 139, 139)'&gt;&lt;/div&gt;&lt;br/&gt;DarkCyan&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(184, 134, 11)'&gt;&lt;/div&gt;&lt;br/&gt;DarkGoldenrod&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 185, 15)'&gt;&lt;/div&gt;&lt;br/&gt;DarkGoldenrod1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 173, 14)'&gt;&lt;/div&gt;&lt;br/&gt;DarkGoldenrod2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 149, 12)'&gt;&lt;/div&gt;&lt;br/&gt;DarkGoldenrod3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 101, 8)'&gt;&lt;/div&gt;&lt;br/&gt;DarkGoldenrod4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(169, 169, 169)'&gt;&lt;/div&gt;&lt;br/&gt;DarkGray&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 100, 0)'&gt;&lt;/div&gt;&lt;br/&gt;DarkGreen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(189, 183, 107)'&gt;&lt;/div&gt;&lt;br/&gt;DarkKhaki&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 0, 139)'&gt;&lt;/div&gt;&lt;br/&gt;DarkMagenta&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(85, 107, 47)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOliveGreen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(202, 255, 112)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOliveGreen1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(188, 238, 104)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOliveGreen2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(162, 205, 90)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOliveGreen3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(110, 139, 61)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOliveGreen4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 140, 0)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOrange&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 127, 0)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOrange1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 118, 0)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOrange2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 102, 0)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOrange3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 69, 0)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOrange4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(153, 50, 204)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOrchid&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(191, 62, 255)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOrchid1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(178, 58, 238)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOrchid2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(154, 50, 205)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOrchid3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(104, 34, 139)'&gt;&lt;/div&gt;&lt;br/&gt;DarkOrchid4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 0, 0)'&gt;&lt;/div&gt;&lt;br/&gt;DarkRed&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(233, 150, 122)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSalmon&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(143, 188, 143)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSeaGreen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(193, 255, 193)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSeaGreen1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(180, 238, 180)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSeaGreen2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(155, 205, 155)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSeaGreen3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(105, 139, 105)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSeaGreen4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(72, 61, 139)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSlateBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(151, 255, 255)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSlateGray1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(141, 238, 238)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSlateGray2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(121, 205, 205)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSlateGray3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(82, 139, 139)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSlateGray4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(47, 79, 79)'&gt;&lt;/div&gt;&lt;br/&gt;DarkSlateGrey&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 206, 209)'&gt;&lt;/div&gt;&lt;br/&gt;DarkTurquoise&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(148, 0, 211)'&gt;&lt;/div&gt;&lt;br/&gt;DarkViolet&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 20, 147)'&gt;&lt;/div&gt;&lt;br/&gt;DeepPink1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 18, 137)'&gt;&lt;/div&gt;&lt;br/&gt;DeepPink2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 16, 118)'&gt;&lt;/div&gt;&lt;br/&gt;DeepPink3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 10, 80)'&gt;&lt;/div&gt;&lt;br/&gt;DeepPink4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 191, 255)'&gt;&lt;/div&gt;&lt;br/&gt;DeepSkyBlue1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 178, 238)'&gt;&lt;/div&gt;&lt;br/&gt;DeepSkyBlue2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 154, 205)'&gt;&lt;/div&gt;&lt;br/&gt;DeepSkyBlue3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 104, 139)'&gt;&lt;/div&gt;&lt;br/&gt;DeepSkyBlue4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(30, 144, 255)'&gt;&lt;/div&gt;&lt;br/&gt;DodgerBlue1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(28, 134, 238)'&gt;&lt;/div&gt;&lt;br/&gt;DodgerBlue2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(24, 116, 205)'&gt;&lt;/div&gt;&lt;br/&gt;DodgerBlue3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(16, 78, 139)'&gt;&lt;/div&gt;&lt;br/&gt;DodgerBlue4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 250, 240)'&gt;&lt;/div&gt;&lt;br/&gt;FloralWhite&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(34, 139, 34)'&gt;&lt;/div&gt;&lt;br/&gt;ForestGreen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(248, 248, 255)'&gt;&lt;/div&gt;&lt;br/&gt;GhostWhite&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(173, 255, 47)'&gt;&lt;/div&gt;&lt;br/&gt;GreenYellow&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 105, 180)'&gt;&lt;/div&gt;&lt;br/&gt;HotPink&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 110, 180)'&gt;&lt;/div&gt;&lt;br/&gt;HotPink1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 106, 167)'&gt;&lt;/div&gt;&lt;br/&gt;HotPink2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 96, 144)'&gt;&lt;/div&gt;&lt;br/&gt;HotPink3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 58, 98)'&gt;&lt;/div&gt;&lt;br/&gt;HotPink4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 92, 92)'&gt;&lt;/div&gt;&lt;br/&gt;IndianRed&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 106, 106)'&gt;&lt;/div&gt;&lt;br/&gt;IndianRed1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 99, 99)'&gt;&lt;/div&gt;&lt;br/&gt;IndianRed2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 85, 85)'&gt;&lt;/div&gt;&lt;br/&gt;IndianRed3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 58, 58)'&gt;&lt;/div&gt;&lt;br/&gt;IndianRed4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 240, 245)'&gt;&lt;/div&gt;&lt;br/&gt;LavenderBlush1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 224, 229)'&gt;&lt;/div&gt;&lt;br/&gt;LavenderBlush2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 193, 197)'&gt;&lt;/div&gt;&lt;br/&gt;LavenderBlush3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 131, 134)'&gt;&lt;/div&gt;&lt;br/&gt;LavenderBlush4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(124, 252, 0)'&gt;&lt;/div&gt;&lt;br/&gt;LawnGreen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 250, 205)'&gt;&lt;/div&gt;&lt;br/&gt;LemonChiffon1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 233, 191)'&gt;&lt;/div&gt;&lt;br/&gt;LemonChiffon2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 201, 165)'&gt;&lt;/div&gt;&lt;br/&gt;LemonChiffon3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 137, 112)'&gt;&lt;/div&gt;&lt;br/&gt;LemonChiffon4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(173, 216, 230)'&gt;&lt;/div&gt;&lt;br/&gt;LightBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(191, 239, 255)'&gt;&lt;/div&gt;&lt;br/&gt;LightBlue1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(178, 223, 238)'&gt;&lt;/div&gt;&lt;br/&gt;LightBlue2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(154, 192, 205)'&gt;&lt;/div&gt;&lt;br/&gt;LightBlue3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(104, 131, 139)'&gt;&lt;/div&gt;&lt;br/&gt;LightBlue4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(240, 128, 128)'&gt;&lt;/div&gt;&lt;br/&gt;LightCoral&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(224, 255, 255)'&gt;&lt;/div&gt;&lt;br/&gt;LightCyan1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(209, 238, 238)'&gt;&lt;/div&gt;&lt;br/&gt;LightCyan2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(180, 205, 205)'&gt;&lt;/div&gt;&lt;br/&gt;LightCyan3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(122, 139, 139)'&gt;&lt;/div&gt;&lt;br/&gt;LightCyan4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 221, 130)'&gt;&lt;/div&gt;&lt;br/&gt;LightGoldenrod&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 236, 139)'&gt;&lt;/div&gt;&lt;br/&gt;LightGoldenrod1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 220, 130)'&gt;&lt;/div&gt;&lt;br/&gt;LightGoldenrod2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 190, 112)'&gt;&lt;/div&gt;&lt;br/&gt;LightGoldenrod3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 129, 76)'&gt;&lt;/div&gt;&lt;br/&gt;LightGoldenrod4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(250, 250, 210)'&gt;&lt;/div&gt;&lt;br/&gt;LightGoldenrodYellow&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(211, 211, 211)'&gt;&lt;/div&gt;&lt;br/&gt;LightGray&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(144, 238, 144)'&gt;&lt;/div&gt;&lt;br/&gt;LightGreen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 182, 193)'&gt;&lt;/div&gt;&lt;br/&gt;LightPink&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 174, 185)'&gt;&lt;/div&gt;&lt;br/&gt;LightPink1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 162, 173)'&gt;&lt;/div&gt;&lt;br/&gt;LightPink2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 140, 149)'&gt;&lt;/div&gt;&lt;br/&gt;LightPink3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 95, 101)'&gt;&lt;/div&gt;&lt;br/&gt;LightPink4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 160, 122)'&gt;&lt;/div&gt;&lt;br/&gt;LightSalmon1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 149, 114)'&gt;&lt;/div&gt;&lt;br/&gt;LightSalmon2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 129, 98)'&gt;&lt;/div&gt;&lt;br/&gt;LightSalmon3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 87, 66)'&gt;&lt;/div&gt;&lt;br/&gt;LightSalmon4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(32, 178, 170)'&gt;&lt;/div&gt;&lt;br/&gt;LightSeaGreen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(135, 206, 250)'&gt;&lt;/div&gt;&lt;br/&gt;LightSkyBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(176, 226, 255)'&gt;&lt;/div&gt;&lt;br/&gt;LightSkyBlue1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(164, 211, 238)'&gt;&lt;/div&gt;&lt;br/&gt;LightSkyBlue2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(141, 182, 205)'&gt;&lt;/div&gt;&lt;br/&gt;LightSkyBlue3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(96, 123, 139)'&gt;&lt;/div&gt;&lt;br/&gt;LightSkyBlue4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(132, 112, 255)'&gt;&lt;/div&gt;&lt;br/&gt;LightSlateBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(119, 136, 153)'&gt;&lt;/div&gt;&lt;br/&gt;LightSlateGrey&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(176, 196, 222)'&gt;&lt;/div&gt;&lt;br/&gt;LightSteelBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(202, 225, 255)'&gt;&lt;/div&gt;&lt;br/&gt;LightSteelBlue1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(188, 210, 238)'&gt;&lt;/div&gt;&lt;br/&gt;LightSteelBlue2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(162, 181, 205)'&gt;&lt;/div&gt;&lt;br/&gt;LightSteelBlue3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(110, 123, 139)'&gt;&lt;/div&gt;&lt;br/&gt;LightSteelBlue4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 255, 224)'&gt;&lt;/div&gt;&lt;br/&gt;LightYellow1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 238, 209)'&gt;&lt;/div&gt;&lt;br/&gt;LightYellow2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 205, 180)'&gt;&lt;/div&gt;&lt;br/&gt;LightYellow3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 139, 122)'&gt;&lt;/div&gt;&lt;br/&gt;LightYellow4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(50, 205, 50)'&gt;&lt;/div&gt;&lt;br/&gt;LimeGreen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(186, 85, 211)'&gt;&lt;/div&gt;&lt;br/&gt;MediumOrchid&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(224, 102, 255)'&gt;&lt;/div&gt;&lt;br/&gt;MediumOrchid1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(209, 95, 238)'&gt;&lt;/div&gt;&lt;br/&gt;MediumOrchid2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(180, 82, 205)'&gt;&lt;/div&gt;&lt;br/&gt;MediumOrchid3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(122, 55, 139)'&gt;&lt;/div&gt;&lt;br/&gt;MediumOrchid4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(147, 112, 219)'&gt;&lt;/div&gt;&lt;br/&gt;MediumPurple&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(171, 130, 255)'&gt;&lt;/div&gt;&lt;br/&gt;MediumPurple1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(159, 121, 238)'&gt;&lt;/div&gt;&lt;br/&gt;MediumPurple2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(137, 104, 205)'&gt;&lt;/div&gt;&lt;br/&gt;MediumPurple3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(93, 71, 139)'&gt;&lt;/div&gt;&lt;br/&gt;MediumPurple4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(60, 179, 113)'&gt;&lt;/div&gt;&lt;br/&gt;MediumSeaGreen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(123, 104, 238)'&gt;&lt;/div&gt;&lt;br/&gt;MediumSlateBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 250, 154)'&gt;&lt;/div&gt;&lt;br/&gt;MediumSpringGreen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(72, 209, 204)'&gt;&lt;/div&gt;&lt;br/&gt;MediumTurquoise&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(199, 21, 133)'&gt;&lt;/div&gt;&lt;br/&gt;MediumVioletRed&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(25, 25, 112)'&gt;&lt;/div&gt;&lt;br/&gt;MidnightBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(245, 255, 250)'&gt;&lt;/div&gt;&lt;br/&gt;MintCream&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 228, 225)'&gt;&lt;/div&gt;&lt;br/&gt;MistyRose1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 213, 210)'&gt;&lt;/div&gt;&lt;br/&gt;MistyRose2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 183, 181)'&gt;&lt;/div&gt;&lt;br/&gt;MistyRose3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 125, 123)'&gt;&lt;/div&gt;&lt;br/&gt;MistyRose4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 222, 173)'&gt;&lt;/div&gt;&lt;br/&gt;NavajoWhite1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 207, 161)'&gt;&lt;/div&gt;&lt;br/&gt;NavajoWhite2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 179, 139)'&gt;&lt;/div&gt;&lt;br/&gt;NavajoWhite3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 121, 94)'&gt;&lt;/div&gt;&lt;br/&gt;NavajoWhite4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 0, 128)'&gt;&lt;/div&gt;&lt;br/&gt;NavyBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(253, 245, 230)'&gt;&lt;/div&gt;&lt;br/&gt;OldLace&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(107, 142, 35)'&gt;&lt;/div&gt;&lt;br/&gt;OliveDrab&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(192, 255, 62)'&gt;&lt;/div&gt;&lt;br/&gt;OliveDrab1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(179, 238, 58)'&gt;&lt;/div&gt;&lt;br/&gt;OliveDrab2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(154, 205, 50)'&gt;&lt;/div&gt;&lt;br/&gt;OliveDrab3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(105, 139, 34)'&gt;&lt;/div&gt;&lt;br/&gt;OliveDrab4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 69, 0)'&gt;&lt;/div&gt;&lt;br/&gt;OrangeRed1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 64, 0)'&gt;&lt;/div&gt;&lt;br/&gt;OrangeRed2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 55, 0)'&gt;&lt;/div&gt;&lt;br/&gt;OrangeRed3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 37, 0)'&gt;&lt;/div&gt;&lt;br/&gt;OrangeRed4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 232, 170)'&gt;&lt;/div&gt;&lt;br/&gt;PaleGoldenrod&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(152, 251, 152)'&gt;&lt;/div&gt;&lt;br/&gt;PaleGreen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(154, 255, 154)'&gt;&lt;/div&gt;&lt;br/&gt;PaleGreen1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(124, 205, 124)'&gt;&lt;/div&gt;&lt;br/&gt;PaleGreen3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(84, 139, 84)'&gt;&lt;/div&gt;&lt;br/&gt;PaleGreen4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(175, 238, 238)'&gt;&lt;/div&gt;&lt;br/&gt;PaleTurquoise&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(187, 255, 255)'&gt;&lt;/div&gt;&lt;br/&gt;PaleTurquoise1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(174, 238, 238)'&gt;&lt;/div&gt;&lt;br/&gt;PaleTurquoise2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(150, 205, 205)'&gt;&lt;/div&gt;&lt;br/&gt;PaleTurquoise3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(102, 139, 139)'&gt;&lt;/div&gt;&lt;br/&gt;PaleTurquoise4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(219, 112, 147)'&gt;&lt;/div&gt;&lt;br/&gt;PaleVioletRed&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 130, 171)'&gt;&lt;/div&gt;&lt;br/&gt;PaleVioletRed1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 121, 159)'&gt;&lt;/div&gt;&lt;br/&gt;PaleVioletRed2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 104, 137)'&gt;&lt;/div&gt;&lt;br/&gt;PaleVioletRed3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 71, 93)'&gt;&lt;/div&gt;&lt;br/&gt;PaleVioletRed4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 239, 213)'&gt;&lt;/div&gt;&lt;br/&gt;PapayaWhip&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 218, 185)'&gt;&lt;/div&gt;&lt;br/&gt;PeachPuff1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 203, 173)'&gt;&lt;/div&gt;&lt;br/&gt;PeachPuff2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 175, 149)'&gt;&lt;/div&gt;&lt;br/&gt;PeachPuff3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 119, 101)'&gt;&lt;/div&gt;&lt;br/&gt;PeachPuff4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(176, 224, 230)'&gt;&lt;/div&gt;&lt;br/&gt;PowderBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(188, 143, 143)'&gt;&lt;/div&gt;&lt;br/&gt;RosyBrown&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 193, 193)'&gt;&lt;/div&gt;&lt;br/&gt;RosyBrown1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 180, 180)'&gt;&lt;/div&gt;&lt;br/&gt;RosyBrown2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 155, 155)'&gt;&lt;/div&gt;&lt;br/&gt;RosyBrown3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 105, 105)'&gt;&lt;/div&gt;&lt;br/&gt;RosyBrown4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(65, 105, 225)'&gt;&lt;/div&gt;&lt;br/&gt;RoyalBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(72, 118, 255)'&gt;&lt;/div&gt;&lt;br/&gt;RoyalBlue1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(67, 110, 238)'&gt;&lt;/div&gt;&lt;br/&gt;RoyalBlue2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(58, 95, 205)'&gt;&lt;/div&gt;&lt;br/&gt;RoyalBlue3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(39, 64, 139)'&gt;&lt;/div&gt;&lt;br/&gt;RoyalBlue4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(244, 164, 96)'&gt;&lt;/div&gt;&lt;br/&gt;SandyBrown&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(84, 255, 159)'&gt;&lt;/div&gt;&lt;br/&gt;SeaGreen1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(78, 238, 148)'&gt;&lt;/div&gt;&lt;br/&gt;SeaGreen2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(67, 205, 128)'&gt;&lt;/div&gt;&lt;br/&gt;SeaGreen3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(46, 139, 87)'&gt;&lt;/div&gt;&lt;br/&gt;SeaGreen4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(135, 206, 235)'&gt;&lt;/div&gt;&lt;br/&gt;SkyBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(135, 206, 255)'&gt;&lt;/div&gt;&lt;br/&gt;SkyBlue1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(126, 192, 238)'&gt;&lt;/div&gt;&lt;br/&gt;SkyBlue2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(108, 166, 205)'&gt;&lt;/div&gt;&lt;br/&gt;SkyBlue3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(74, 112, 139)'&gt;&lt;/div&gt;&lt;br/&gt;SkyBlue4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(106, 90, 205)'&gt;&lt;/div&gt;&lt;br/&gt;SlateBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(131, 111, 255)'&gt;&lt;/div&gt;&lt;br/&gt;SlateBlue1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(122, 103, 238)'&gt;&lt;/div&gt;&lt;br/&gt;SlateBlue2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(105, 89, 205)'&gt;&lt;/div&gt;&lt;br/&gt;SlateBlue3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(71, 60, 139)'&gt;&lt;/div&gt;&lt;br/&gt;SlateBlue4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(198, 226, 255)'&gt;&lt;/div&gt;&lt;br/&gt;SlateGray1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(185, 211, 238)'&gt;&lt;/div&gt;&lt;br/&gt;SlateGray2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(159, 182, 205)'&gt;&lt;/div&gt;&lt;br/&gt;SlateGray3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(108, 123, 139)'&gt;&lt;/div&gt;&lt;br/&gt;SlateGray4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(112, 128, 144)'&gt;&lt;/div&gt;&lt;br/&gt;SlateGrey&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 255, 127)'&gt;&lt;/div&gt;&lt;br/&gt;SpringGreen1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 238, 118)'&gt;&lt;/div&gt;&lt;br/&gt;SpringGreen2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 205, 102)'&gt;&lt;/div&gt;&lt;br/&gt;SpringGreen3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 139, 69)'&gt;&lt;/div&gt;&lt;br/&gt;SpringGreen4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(70, 130, 180)'&gt;&lt;/div&gt;&lt;br/&gt;SteelBlue&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(99, 184, 255)'&gt;&lt;/div&gt;&lt;br/&gt;SteelBlue1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(92, 172, 238)'&gt;&lt;/div&gt;&lt;br/&gt;SteelBlue2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(79, 148, 205)'&gt;&lt;/div&gt;&lt;br/&gt;SteelBlue3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(54, 100, 139)'&gt;&lt;/div&gt;&lt;br/&gt;SteelBlue4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(208, 32, 144)'&gt;&lt;/div&gt;&lt;br/&gt;VioletRed&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 62, 150)'&gt;&lt;/div&gt;&lt;br/&gt;VioletRed1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 58, 140)'&gt;&lt;/div&gt;&lt;br/&gt;VioletRed2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 50, 120)'&gt;&lt;/div&gt;&lt;br/&gt;VioletRed3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 34, 82)'&gt;&lt;/div&gt;&lt;br/&gt;VioletRed4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(127, 255, 212)'&gt;&lt;/div&gt;&lt;br/&gt;aquamarine1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(118, 238, 198)'&gt;&lt;/div&gt;&lt;br/&gt;aquamarine2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(102, 205, 170)'&gt;&lt;/div&gt;&lt;br/&gt;aquamarine3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(69, 139, 116)'&gt;&lt;/div&gt;&lt;br/&gt;aquamarine4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(240, 255, 255)'&gt;&lt;/div&gt;&lt;br/&gt;azure1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(224, 238, 238)'&gt;&lt;/div&gt;&lt;br/&gt;azure2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(193, 205, 205)'&gt;&lt;/div&gt;&lt;br/&gt;azure3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(131, 139, 139)'&gt;&lt;/div&gt;&lt;br/&gt;azure4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(245, 245, 220)'&gt;&lt;/div&gt;&lt;br/&gt;beige&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 228, 196)'&gt;&lt;/div&gt;&lt;br/&gt;bisque1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 213, 183)'&gt;&lt;/div&gt;&lt;br/&gt;bisque2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 183, 158)'&gt;&lt;/div&gt;&lt;br/&gt;bisque3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 125, 107)'&gt;&lt;/div&gt;&lt;br/&gt;bisque4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 0, 255)'&gt;&lt;/div&gt;&lt;br/&gt;blue1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 0, 238)'&gt;&lt;/div&gt;&lt;br/&gt;blue2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 0, 205)'&gt;&lt;/div&gt;&lt;br/&gt;blue3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(165, 42, 42)'&gt;&lt;/div&gt;&lt;br/&gt;brown&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 64, 64)'&gt;&lt;/div&gt;&lt;br/&gt;brown1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 59, 59)'&gt;&lt;/div&gt;&lt;br/&gt;brown2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 51, 51)'&gt;&lt;/div&gt;&lt;br/&gt;brown3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 35, 35)'&gt;&lt;/div&gt;&lt;br/&gt;brown4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(222, 184, 135)'&gt;&lt;/div&gt;&lt;br/&gt;burlywood&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 211, 155)'&gt;&lt;/div&gt;&lt;br/&gt;burlywood1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 197, 145)'&gt;&lt;/div&gt;&lt;br/&gt;burlywood2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 170, 125)'&gt;&lt;/div&gt;&lt;br/&gt;burlywood3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 115, 85)'&gt;&lt;/div&gt;&lt;br/&gt;burlywood4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(127, 255, 0)'&gt;&lt;/div&gt;&lt;br/&gt;chartreuse1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(118, 238, 0)'&gt;&lt;/div&gt;&lt;br/&gt;chartreuse2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(102, 205, 0)'&gt;&lt;/div&gt;&lt;br/&gt;chartreuse3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(69, 139, 0)'&gt;&lt;/div&gt;&lt;br/&gt;chartreuse4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(210, 105, 30)'&gt;&lt;/div&gt;&lt;br/&gt;chocolate&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 127, 36)'&gt;&lt;/div&gt;&lt;br/&gt;chocolate1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 118, 33)'&gt;&lt;/div&gt;&lt;br/&gt;chocolate2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 102, 29)'&gt;&lt;/div&gt;&lt;br/&gt;chocolate3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 69, 19)'&gt;&lt;/div&gt;&lt;br/&gt;chocolate4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 127, 80)'&gt;&lt;/div&gt;&lt;br/&gt;coral&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 114, 86)'&gt;&lt;/div&gt;&lt;br/&gt;coral1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 106, 80)'&gt;&lt;/div&gt;&lt;br/&gt;coral2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 91, 69)'&gt;&lt;/div&gt;&lt;br/&gt;coral3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 62, 47)'&gt;&lt;/div&gt;&lt;br/&gt;coral4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 248, 220)'&gt;&lt;/div&gt;&lt;br/&gt;cornsilk1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 232, 205)'&gt;&lt;/div&gt;&lt;br/&gt;cornsilk2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 200, 177)'&gt;&lt;/div&gt;&lt;br/&gt;cornsilk3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 136, 120)'&gt;&lt;/div&gt;&lt;br/&gt;cornsilk4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 255, 255)'&gt;&lt;/div&gt;&lt;br/&gt;cyan1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 238, 238)'&gt;&lt;/div&gt;&lt;br/&gt;cyan2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 205, 205)'&gt;&lt;/div&gt;&lt;br/&gt;cyan3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(178, 34, 34)'&gt;&lt;/div&gt;&lt;br/&gt;firebrick&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 48, 48)'&gt;&lt;/div&gt;&lt;br/&gt;firebrick1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 44, 44)'&gt;&lt;/div&gt;&lt;br/&gt;firebrick2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 38, 38)'&gt;&lt;/div&gt;&lt;br/&gt;firebrick3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 26, 26)'&gt;&lt;/div&gt;&lt;br/&gt;firebrick4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(220, 220, 220)'&gt;&lt;/div&gt;&lt;br/&gt;gainsboro&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 215, 0)'&gt;&lt;/div&gt;&lt;br/&gt;gold1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 201, 0)'&gt;&lt;/div&gt;&lt;br/&gt;gold2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 173, 0)'&gt;&lt;/div&gt;&lt;br/&gt;gold3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 117, 0)'&gt;&lt;/div&gt;&lt;br/&gt;gold4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(218, 165, 32)'&gt;&lt;/div&gt;&lt;br/&gt;goldenrod&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 193, 37)'&gt;&lt;/div&gt;&lt;br/&gt;goldenrod1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 180, 34)'&gt;&lt;/div&gt;&lt;br/&gt;goldenrod2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 155, 29)'&gt;&lt;/div&gt;&lt;br/&gt;goldenrod3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 105, 20)'&gt;&lt;/div&gt;&lt;br/&gt;goldenrod4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 255, 0)'&gt;&lt;/div&gt;&lt;br/&gt;green1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 238, 0)'&gt;&lt;/div&gt;&lt;br/&gt;green2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 205, 0)'&gt;&lt;/div&gt;&lt;br/&gt;green3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 139, 0)'&gt;&lt;/div&gt;&lt;br/&gt;green4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(190, 190, 190)'&gt;&lt;/div&gt;&lt;br/&gt;grey&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 0, 0)'&gt;&lt;/div&gt;&lt;br/&gt;grey0&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(26, 26, 26)'&gt;&lt;/div&gt;&lt;br/&gt;grey10&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(51, 51, 51)'&gt;&lt;/div&gt;&lt;br/&gt;grey20&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(77, 77, 77)'&gt;&lt;/div&gt;&lt;br/&gt;grey30&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(102, 102, 102)'&gt;&lt;/div&gt;&lt;br/&gt;grey40&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(127, 127, 127)'&gt;&lt;/div&gt;&lt;br/&gt;grey50&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(153, 153, 153)'&gt;&lt;/div&gt;&lt;br/&gt;grey60&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(179, 179, 179)'&gt;&lt;/div&gt;&lt;br/&gt;grey70&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(204, 204, 204)'&gt;&lt;/div&gt;&lt;br/&gt;grey80&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(229, 229, 229)'&gt;&lt;/div&gt;&lt;br/&gt;grey90&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 255, 255)'&gt;&lt;/div&gt;&lt;br/&gt;grey100&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(240, 255, 240)'&gt;&lt;/div&gt;&lt;br/&gt;honeydew1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(224, 238, 224)'&gt;&lt;/div&gt;&lt;br/&gt;honeydew2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(193, 205, 193)'&gt;&lt;/div&gt;&lt;br/&gt;honeydew3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(131, 139, 131)'&gt;&lt;/div&gt;&lt;br/&gt;honeydew4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 255, 240)'&gt;&lt;/div&gt;&lt;br/&gt;ivory1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 238, 224)'&gt;&lt;/div&gt;&lt;br/&gt;ivory2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 205, 193)'&gt;&lt;/div&gt;&lt;br/&gt;ivory3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 139, 131)'&gt;&lt;/div&gt;&lt;br/&gt;ivory4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(240, 230, 140)'&gt;&lt;/div&gt;&lt;br/&gt;khaki&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 246, 143)'&gt;&lt;/div&gt;&lt;br/&gt;khaki1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 230, 133)'&gt;&lt;/div&gt;&lt;br/&gt;khaki2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 198, 115)'&gt;&lt;/div&gt;&lt;br/&gt;khaki3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 134, 78)'&gt;&lt;/div&gt;&lt;br/&gt;khaki4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(230, 230, 250)'&gt;&lt;/div&gt;&lt;br/&gt;lavender&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(250, 240, 230)'&gt;&lt;/div&gt;&lt;br/&gt;linen&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 0, 255)'&gt;&lt;/div&gt;&lt;br/&gt;magenta1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 0, 238)'&gt;&lt;/div&gt;&lt;br/&gt;magenta2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 0, 205)'&gt;&lt;/div&gt;&lt;br/&gt;magenta3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(176, 48, 96)'&gt;&lt;/div&gt;&lt;br/&gt;maroon&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 52, 179)'&gt;&lt;/div&gt;&lt;br/&gt;maroon1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 48, 167)'&gt;&lt;/div&gt;&lt;br/&gt;maroon2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 41, 144)'&gt;&lt;/div&gt;&lt;br/&gt;maroon3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 28, 98)'&gt;&lt;/div&gt;&lt;br/&gt;maroon4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 228, 181)'&gt;&lt;/div&gt;&lt;br/&gt;moccasin&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 165, 0)'&gt;&lt;/div&gt;&lt;br/&gt;orange1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 154, 0)'&gt;&lt;/div&gt;&lt;br/&gt;orange2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 133, 0)'&gt;&lt;/div&gt;&lt;br/&gt;orange3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 90, 0)'&gt;&lt;/div&gt;&lt;br/&gt;orange4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(218, 112, 214)'&gt;&lt;/div&gt;&lt;br/&gt;orchid&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 131, 250)'&gt;&lt;/div&gt;&lt;br/&gt;orchid1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 122, 233)'&gt;&lt;/div&gt;&lt;br/&gt;orchid2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 105, 201)'&gt;&lt;/div&gt;&lt;br/&gt;orchid3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 71, 137)'&gt;&lt;/div&gt;&lt;br/&gt;orchid4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 192, 203)'&gt;&lt;/div&gt;&lt;br/&gt;pink&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 181, 197)'&gt;&lt;/div&gt;&lt;br/&gt;pink1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 169, 184)'&gt;&lt;/div&gt;&lt;br/&gt;pink2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 145, 158)'&gt;&lt;/div&gt;&lt;br/&gt;pink3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 99, 108)'&gt;&lt;/div&gt;&lt;br/&gt;pink4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(221, 160, 221)'&gt;&lt;/div&gt;&lt;br/&gt;plum&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 187, 255)'&gt;&lt;/div&gt;&lt;br/&gt;plum1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 174, 238)'&gt;&lt;/div&gt;&lt;br/&gt;plum2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 150, 205)'&gt;&lt;/div&gt;&lt;br/&gt;plum3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 102, 139)'&gt;&lt;/div&gt;&lt;br/&gt;plum4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(160, 32, 240)'&gt;&lt;/div&gt;&lt;br/&gt;purple&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(155, 48, 255)'&gt;&lt;/div&gt;&lt;br/&gt;purple1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(145, 44, 238)'&gt;&lt;/div&gt;&lt;br/&gt;purple2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(125, 38, 205)'&gt;&lt;/div&gt;&lt;br/&gt;purple3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(85, 26, 139)'&gt;&lt;/div&gt;&lt;br/&gt;purple4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 0, 0)'&gt;&lt;/div&gt;&lt;br/&gt;red1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 0, 0)'&gt;&lt;/div&gt;&lt;br/&gt;red2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 0, 0)'&gt;&lt;/div&gt;&lt;br/&gt;red3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(250, 128, 114)'&gt;&lt;/div&gt;&lt;br/&gt;salmon&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 140, 105)'&gt;&lt;/div&gt;&lt;br/&gt;salmon1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 130, 98)'&gt;&lt;/div&gt;&lt;br/&gt;salmon2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 112, 84)'&gt;&lt;/div&gt;&lt;br/&gt;salmon3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 76, 57)'&gt;&lt;/div&gt;&lt;br/&gt;salmon4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 245, 238)'&gt;&lt;/div&gt;&lt;br/&gt;seashell1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 229, 222)'&gt;&lt;/div&gt;&lt;br/&gt;seashell2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 197, 191)'&gt;&lt;/div&gt;&lt;br/&gt;seashell3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 134, 130)'&gt;&lt;/div&gt;&lt;br/&gt;seashell4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(160, 82, 45)'&gt;&lt;/div&gt;&lt;br/&gt;sienna&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 130, 71)'&gt;&lt;/div&gt;&lt;br/&gt;sienna1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 121, 66)'&gt;&lt;/div&gt;&lt;br/&gt;sienna2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 104, 57)'&gt;&lt;/div&gt;&lt;br/&gt;sienna3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 71, 38)'&gt;&lt;/div&gt;&lt;br/&gt;sienna4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 250, 250)'&gt;&lt;/div&gt;&lt;br/&gt;snow1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 233, 233)'&gt;&lt;/div&gt;&lt;br/&gt;snow2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 201, 201)'&gt;&lt;/div&gt;&lt;br/&gt;snow3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 137, 137)'&gt;&lt;/div&gt;&lt;br/&gt;snow4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(210, 180, 140)'&gt;&lt;/div&gt;&lt;br/&gt;tan&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 165, 79)'&gt;&lt;/div&gt;&lt;br/&gt;tan1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 154, 73)'&gt;&lt;/div&gt;&lt;br/&gt;tan2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 133, 63)'&gt;&lt;/div&gt;&lt;br/&gt;tan3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 90, 43)'&gt;&lt;/div&gt;&lt;br/&gt;tan4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(216, 191, 216)'&gt;&lt;/div&gt;&lt;br/&gt;thistle&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 225, 255)'&gt;&lt;/div&gt;&lt;br/&gt;thistle1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 210, 238)'&gt;&lt;/div&gt;&lt;br/&gt;thistle2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 181, 205)'&gt;&lt;/div&gt;&lt;br/&gt;thistle3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 123, 139)'&gt;&lt;/div&gt;&lt;br/&gt;thistle4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 99, 71)'&gt;&lt;/div&gt;&lt;br/&gt;tomato1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 92, 66)'&gt;&lt;/div&gt;&lt;br/&gt;tomato2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 79, 57)'&gt;&lt;/div&gt;&lt;br/&gt;tomato3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 54, 38)'&gt;&lt;/div&gt;&lt;br/&gt;tomato4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(64, 224, 208)'&gt;&lt;/div&gt;&lt;br/&gt;turquoise&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 245, 255)'&gt;&lt;/div&gt;&lt;br/&gt;turquoise1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 229, 238)'&gt;&lt;/div&gt;&lt;br/&gt;turquoise2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 197, 205)'&gt;&lt;/div&gt;&lt;br/&gt;turquoise3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(0, 134, 139)'&gt;&lt;/div&gt;&lt;br/&gt;turquoise4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 130, 238)'&gt;&lt;/div&gt;&lt;br/&gt;violet&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(245, 222, 179)'&gt;&lt;/div&gt;&lt;br/&gt;wheat&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 231, 186)'&gt;&lt;/div&gt;&lt;br/&gt;wheat1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 216, 174)'&gt;&lt;/div&gt;&lt;br/&gt;wheat2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 186, 150)'&gt;&lt;/div&gt;&lt;br/&gt;wheat3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 126, 102)'&gt;&lt;/div&gt;&lt;br/&gt;wheat4&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(255, 255, 0)'&gt;&lt;/div&gt;&lt;br/&gt;yellow1&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(238, 238, 0)'&gt;&lt;/div&gt;&lt;br/&gt;yellow2&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(205, 205, 0)'&gt;&lt;/div&gt;&lt;br/&gt;yellow3&lt;/div&gt;
&lt;div class='box'&gt;&lt;div class='cbox' style='background-color: rgb(139, 139, 0)'&gt;&lt;/div&gt;&lt;br/&gt;yellow4&lt;/div&gt;

&lt;/div&gt;

</description>
    </item>
    
    <item>
      <title>UNIX Directory Commands</title>
      <link>http://solog.co/system/unix-directory-commands.html</link>
      <pubDate>Sat, 28 Jul 2007 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/system/unix-directory-commands.html</guid>
      <description>&lt;p&gt;Ok, I've posted way too much about the iPhone, I think a few people might actually be reading and subscribing to my blog. I'm actually getting comments too. Time to nip that in the bud with a post about obscure unix commands.&lt;/p&gt;

&lt;p&gt;I was reading a tutorial on setting up an IMAP server and the guy was using the &lt;b&gt;pushd&lt;/b&gt; and &lt;b&gt;popd&lt;/b&gt; commands. What I love about unix is there are obscure commands on your system that do all sorts of things that you never knew about it.&lt;/p&gt;

&lt;p&gt;The commands pushd, popd and dirs are commands which help track and change directories.
The basics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;b&gt;pushd&lt;/b&gt; will push a directory onto a stack,&lt;/li&gt;
&lt;li&gt;&lt;b&gt;popd&lt;/b&gt; will pop a directory off the stack,&lt;/li&gt;
&lt;li&gt;&lt;b&gt;dirs&lt;/b&gt; will list the directories in the stack&lt;/li&gt;
&lt;/ul&gt;


&lt;hr /&gt;

&lt;p&gt;When pushing and popping things on and off the stack, the commands will also change your current directory. Here's an example, moving around while debugging web stuff:&lt;/p&gt;

&lt;p&gt;First I want to add the directories to my stack:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pushd&lt;/span&gt; /opt/sites/htdocs
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pushd&lt;/span&gt; /var/log/httpd
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pushd&lt;/span&gt; /etc/httpd
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;You will notice as you push something on the stack, your current directory will also change to what you just pushed on. To see what is on your directory stack:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dirs&lt;/span&gt; -v
0 /etc/httpd
1 /var/log/httpd
2 /opt/sites/htdocs
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Now to move around if you use pushd without any arguments it will swap the top two items in the stack changing your directory to what is now the top item.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pushd&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pwd&lt;/span&gt;
/var/log/httpd
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;You can also use pushd +N and it will change to that position in the stack.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dirs&lt;/span&gt; -v
0 /var/log/httpd
1 /etc/httpd
2 /opt/sites/htdocs
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pushd&lt;/span&gt; +2
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pwd&lt;/span&gt;
/opt/sites/htdocs
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dirs&lt;/span&gt; -v
0 /opt/sites/htdocs
1 /var/log/httpd
2 /etc/httpd
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Use popd to remove items from the list. It supports the same +N syntax, or with no arguments will remove the top item and change your directory to the next. Use &lt;b&gt;dirs -c&lt;/b&gt; to clear the directory stack.&lt;/p&gt;

&lt;p&gt;I need to play around with them more, it seems useful but I haven't quite incorporated it into my repertoire yet.&lt;/p&gt;

&lt;h4&gt;Reference&lt;/h4&gt;

&lt;p&gt;Here are online man page reference for the commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ss64.com/bash/pushd.html&quot;&gt;pushd man page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ss64.com/bash/popd.html&quot;&gt;popd man page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.ss64.com/bash/dirs.html&quot;&gt;dirs man page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    
    <item>
      <title>How to Fix Double Posting</title>
      <link>http://solog.co/webdev/how-to-fix-double-posting.html</link>
      <pubDate>Tue, 03 Jul 2007 00:00:00 PDT</pubDate>
      <author>Marcus Kazmiercak </author>
      <guid>http://solog.co/webdev/how-to-fix-double-posting.html</guid>
      <description>&lt;p&gt;You see the following on order forms all the time&lt;/p&gt;

&lt;blockquote&gt;&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;&quot;press the button only once or we may charge you double&quot;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;/blockquote&gt;

&lt;p&gt;This is just laziness on the developers, there are a few easy techniques to avoid double processing a form. Plus if you have ever watched my mother-in-law use a computer, there is a fine line between clicking once and double (or even triple) clicking.&lt;/p&gt;

&lt;p&gt;Here's one way to solve double posting. The process is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate a unique key for every HTML form&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When processing the form insert the unique key into a transaction database table&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For the transaction table, create a UNIQUE INDEX on the key field&lt;/li&gt;
&lt;li&gt;So when inserting the key, if there is a duplicate key it will fail&lt;/li&gt;
&lt;li&gt;If insert fails, don't reprocess form&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A clean up batch job can run daily to delete items from table to kept tidy&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;hr /&gt;

&lt;h3&gt;Example Code in PHP&lt;/h3&gt;

&lt;p&gt;Here's some example code using this technique in PHP&lt;/p&gt;

&lt;p&gt;First you need to setup your transactions table:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;mysql&quot;&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;transactions&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;transaction_key&lt;/span&gt;   &lt;span class=&quot;kt&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;UNIQUE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;INDEX&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;uki&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;transaction_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;A PHP function to get a unique id, abstracted in case you want to change it later, we use smarty functions at work, so this was created as a smarty tag:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;&lt;span class=&quot;x&quot;&gt;function get_transaction_key() {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    return uniqid(&amp;#39;&amp;#39;, true);&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The main function which checks if the key has been used before:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;&lt;span class=&quot;x&quot;&gt;function check_transaction_key($key) {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    $return_value = db_insert(&amp;quot; INSERT INTO transactions (transaction_key) VALUES (&amp;#39;$key&amp;#39;) &amp;quot;);&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    if ($return_value === false) { return false; }&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    else { return true; }&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Your PHP+HTML Template Script:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;&lt;span class=&quot;x&quot;&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;txn_key&amp;quot; value=&amp;quot;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;get_transcaction_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;cp&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;span class=&quot;x&quot;&gt;&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    ... extra form stuff...&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Your PHP Form Process Script:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;&lt;span class=&quot;x&quot;&gt;if (check_transaction_key($_REQUEST[&amp;#39;txn_key&amp;#39;])) {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;      ... continue processing form ...&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;else {&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;  // duplicate entry, dont insert&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;NOTE: The sample code above should &lt;b&gt;not&lt;/b&gt; be considered best practices.  Your PHP+HTML should be in a nice template and you should scrub all your submitted variables before doing anything with them.&lt;/p&gt;

&lt;p&gt;Next up: The annoying &lt;em&gt;please do not include spaces&lt;/em&gt; in credit card fields&lt;/p&gt;
</description>
    </item>
    

  </channel> 
</rss>