<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <title>byronc bits</title>
    <link>http://byron.theclarkfamily.name/blog</link>
    <description>breaking old technology, one bit at a time</description>
    <pubDate>Wed, 11 Jan 2012 04:59:47 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Scala as a Java REPL</title>
      <link>http://byron.theclarkfamily.name/blog/2011/11/08/scala-as-a-java-repl</link>
      <pubDate>Tue, 08 Nov 2011 21:10:38 MST</pubDate>
      <category><![CDATA[programming]]></category>
      <category><![CDATA[scala]]></category>
      <guid isPermaLink="true">http://byron.theclarkfamily.name/blog/2011/11/08/scala-as-a-java-repl</guid>
      <description>Scala as a Java REPL</description>
      <content:encoded><![CDATA[<p>After years of Python programming, I've been spoiled by always having a <a href="http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop">REPL</a> available when I want to test something out. As I spend more and more time in Java, I find myself missing a REPL. Well, no more. I'm happy to report that I've finally found a REPL I like using to test out libraries when I'm working in Java: the Scala REPL. </p>
<p>Today I needed to send some JMS messages to ActiveMQ. Instead of firing up eclipse, creating a maven project to get the dependencies, and then writing some Java code, I used <a href="https://github.com/harrah/xsbt/wiki">sbt</a> and <a href="http://www.scala-lang.org/">Scala</a> to create a REPL where I could easily send JMS messages.</p>
<h2>Create an sbt project</h2>
<p>The first step is to create an sbt project. This is as simple as creating a directory with a <code>build.sbt</code> file in it. My example <code>build.sbt</code> file pulls in two library dependencies that I want to have available in the REPL.</p>
<div class="pygments_tomorrow-night"><pre><span class="n">name</span> <span class="o">:=</span> <span class="s">&quot;jmstest&quot;</span>

<p><span class="n">scalaVersion</span> <span class="o">:=</span> <span class="s">&quot;2.9.1&quot;</span></p>
<p><span class="n">libraryDependencies</span> <span class="o">++=</span> <span class="nc">Seq</span><span class="o">(</span>
  <span class="s">&quot;org.apache.activemq&quot;</span> <span class="o">%</span> <span class="s">&quot;activemq-core&quot;</span> <span class="o">%</span> <span class="s">&quot;5.5.1&quot;</span><span class="o">,</span>
  <span class="s">&quot;org.slf4j&quot;</span> <span class="o">%</span> <span class="s">&quot;slf4j-simple&quot;</span> <span class="o">%</span> <span class="s">&quot;1.6.4&quot;</span>
<span class="o">)</span>
</pre></div></p>
<h2>Run the REPL</h2>
<p>Running the REPL is as simple as running <code>sbt console</code> from the newly created sbt project. From there, it's off to the races:</p>
<div class="pygments_tomorrow-night"><pre><span class="k">import</span> <span class="nn">javax.jms._</span>
<span class="k">import</span> <span class="nn">org.apache.activemq.ActiveMQConnectionFactory</span>

<p><span class="k">val</span> <span class="n">factory</span> <span class="k">=</span> <span class="k">new</span> <span class="nc">ActiveMQConnectionFactory</span><span class="o">(</span><span class="s">&quot;tcp://localhost:61616&quot;</span><span class="o">)</span>
<span class="k">val</span> <span class="n">connection</span> <span class="k">=</span> <span class="n">factory</span><span class="o">.</span><span class="n">createConnection</span>
<span class="k">val</span> <span class="n">session</span> <span class="k">=</span> <span class="n">connection</span><span class="o">.</span><span class="n">createSession</span><span class="o">(</span><span class="kc">false</span><span class="o">,</span> <span class="nc">Session</span><span class="o">.</span><span class="nc">AUTO_ACKNOWLEDGE</span><span class="o">)</span>
<span class="k">val</span> <span class="n">destination</span> <span class="k">=</span> <span class="n">session</span><span class="o">.</span><span class="n">createTopic</span><span class="o">(</span><span class="s">&quot;jms.test&quot;</span><span class="o">)</span>
<span class="k">val</span> <span class="n">producer</span> <span class="k">=</span> <span class="n">session</span><span class="o">.</span><span class="n">createProducer</span><span class="o">(</span><span class="n">destination</span><span class="o">)</span></p>
<p><span class="k">val</span> <span class="n">message</span> <span class="k">=</span> <span class="n">session</span><span class="o">.</span><span class="n">createMapMessage</span>
<span class="n">message</span><span class="o">.</span><span class="n">setString</span><span class="o">(</span><span class="s">&quot;command&quot;</span><span class="o">,</span> <span class="s">&quot;basic_setup&quot;</span><span class="o">)</span>
<span class="n">message</span><span class="o">.</span><span class="n">setBoolean</span><span class="o">(</span><span class="s">&quot;do_stuff&quot;</span><span class="o">,</span> <span class="kc">false</span><span class="o">)</span>
<span class="n">producer</span><span class="o">.</span><span class="n">send</span><span class="o">(</span><span class="n">message</span><span class="o">)</span>
</pre></div></p>
<p>That's all there is to it. Scala, with the help of sbt, makes a great REPL for testing out Java libraries.</p>]]></content:encoded>
    </item>
    <item>
      <title>Python TUI Programming</title>
      <link>http://byron.theclarkfamily.name/blog/2007/02/14/python-tui-programming</link>
      <pubDate>Wed, 14 Feb 2007 22:16:42 MST</pubDate>
      <category><![CDATA[programming]]></category>
      <guid isPermaLink="true">http://byron.theclarkfamily.name/blog/2007/02/14/python-tui-programming</guid>
      <description>Python TUI Programming</description>
      <content:encoded><![CDATA[<p>I've heard rumblings about <a href="http://excess.org/urwid/">Urwid</a> occasionally;
today I actually had a chance to use it. For those who haven't seen it before,
Urwid is a pure Python library for console user interfaces. It can uses curses
as the backend or speak directly to the terminal emulator. The library isn't
too complex and as long as you can pick colors better than I can the TUIs look
pretty nice. Check it out the next time you don't want to write a GUI.</p>]]></content:encoded>
    </item>
  </channel>
</rss>

