<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dammit Jim! &#187; Programmer</title>
	<atom:link href="http://scott.sherrillmix.com/blog/category/programmer/feed/" rel="self" type="application/rss+xml" />
	<link>http://scott.sherrillmix.com/blog</link>
	<description>I'm a biologist not a...</description>
	<lastBuildDate>Tue, 12 Jan 2010 05:09:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Handy Apply-based R Progress Bars</title>
		<link>http://scott.sherrillmix.com/blog/programmer/handy-apply-based-r-progress-bars/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/handy-apply-based-r-progress-bars/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 05:09:05 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Programmer]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[apply]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[lapply]]></category>
		<category><![CDATA[progress bar]]></category>
		<category><![CDATA[sapply]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=550</guid>
		<description><![CDATA[In a funny congruence with my post on R progress bars, Mark Heckmann just posted about some wrappers for the apply functions in R. He wrote up some functions that imitate sapply, lapply and apply but automatically add a progress bar so you can monitor the progress. They work very nice since you can just [...]]]></description>
			<content:encoded><![CDATA[<p>In a funny congruence with my post on <a href="http://scott.sherrillmix.com/blog/programmer/progress-bars-in-r/">R progress bars</a>, Mark Heckmann just posted about some <a href="http://ryouready.wordpress.com/2010/01/11/progress-bars-in-r-part-ii-a-wrapper-for-apply-functions/">wrappers for the apply functions in R</a>. He wrote up some functions that imitate <code>sapply</code>, <code>lapply</code> and <code>apply</code> but automatically add a progress bar so you can monitor the progress. They work very nice since you can just substitute his <code>apply_pb</code>&#8217;s in place of R&#8217;s standard <code>apply</code>&#8217;s. He says it&#8217;s a bit of a performance drag but after testing a bit it looks like they really shouldn&#8217;t add much overhead at all if there&#8217;s any major calculations inside the loop. Very handy.</p>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/handy-apply-based-r-progress-bars/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Progress Bars in R</title>
		<link>http://scott.sherrillmix.com/blog/programmer/progress-bars-in-r/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/progress-bars-in-r/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 02:42:57 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Programmer]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[bar]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[progress]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=544</guid>
		<description><![CDATA[Recently, I've had a lot of time consuming tasks running in R where it's nice to know how the computer is doing. I usually just output the name of the current iteration or a dot or something but I finally decided I should figure out how to make a nice progress bar in R. It [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I've had a lot of time consuming tasks running in R where it's nice to know how the computer is doing. I usually just output the name of the current iteration or a dot or something but I finally decided I should figure out how to make a nice progress bar in R. It turns out it's really simple since it's already builtin with the <code>txtProgressBar</code> function. So you can do something like:</p>
<div class="syntax_hilite"><span class="langName">R:</span><br /><div id="r-2">
<div class="r"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">numberSteps&lt;-<span style="color: #cc66cc;color:#800000;">10</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">pb &lt;- txtProgressBar<span style="color: #66cc66;">&#40;</span>min = <span style="color: #cc66cc;color:#800000;">0</span>, max = numberSteps, style = <span style="color: #cc66cc;color:#800000;">3</span><span style="color: #66cc66;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a020f0;">for</span><span style="color: #66cc66;">&#40;</span>i <span style="color: #a020f0;">in</span> <span style="color: #cc66cc;color:#800000;">1</span>:numberSteps<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; setTxtProgressBar<span style="color: #66cc66;">&#40;</span>pb, i<span style="color: #66cc66;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; Sys.sleep<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">close<span style="color: #66cc66;">&#40;</span>pb<span style="color: #66cc66;">&#41;</span> </div></li></ol></div>
</div></div><br />
<img src="/res/images/progressBar.png" alt="A text progress bar in R" class="center"/>
<p>That's good enough for me but there's also <code>winProgressBar</code> for a fancy Windows progress bar and <code>tkProgressBar</code> (in the <code>tcltk</code> package) if you really want to get fancy.</p>

]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/progress-bars-in-r/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Syntax highlighting in terminal</title>
		<link>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 04:53:09 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Bash/UNIX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[cat]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[pygmentize]]></category>
		<category><![CDATA[syntax highlighting]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=526</guid>
		<description><![CDATA[
I was just quickly flipping through code on a terminal and got to thinking that it would be pretty handy to be able to syntax highlight when using head or grep without having to open an editor. Luckily, I remembered Pygemtize was pretty handy when syntax highlighting in LaTeX so I wondered if they had [...]]]></description>
			<content:encoded><![CDATA[<img src="/res/images/ccat.png" alt="Syntax highlighted cat" class="right"/>
<p>I was just quickly flipping through code on a terminal and got to thinking that it would be pretty handy to be able to syntax highlight when using <code>head</code> or <code>grep</code> without having to open an editor. Luckily, I remembered <a href="http://pygments.org/">Pygemtize</a> was pretty handy when <a href="http://scott.sherrillmix.com/blog/programmer/displaying-code-in-latex/">syntax highlighting in LaTeX</a> so I wondered if they had an equivalent output for terminal. It turns out they do (in standard or 256 color no less) so in a couple minutes I had a really short script for highlighting code at the terminal saved it to <code>bin/ccat</code> and was ready to go. Pygmentize really is impressive. Here's the script if anyone else is looking to do the same:</p>
<div class="syntax_hilite"><span class="langName">BASH:</span><br /><div id="bash-4">
<div class="bash"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#!/bin/bash#!/bin/bash</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> ! -t <span style="color: #cc66cc;color:#800000;">0</span> <span style="color: #66cc66;">&#93;</span>;then</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">file=</span>/dev/stdin</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">elif</span> <span style="color: #66cc66;">&#91;</span> -f $<span style="color: #cc66cc;color:#800000;">1</span> <span style="color: #66cc66;">&#93;</span>;then</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">file=</span>$<span style="color: #cc66cc;color:#800000;">1</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">else</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"Usage: $0 code.c"</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"or e.g. head code.c|$0"</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">exit</span> <span style="color: #cc66cc;color:#800000;">1</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">fi</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">pygmentize -f terminal -g <span style="color: #0000ff;">$file</span> </div></li></ol></div>
</div></div><br />
<p>It just looks for stdin and if it doesn't find it it looks for a file name or takes direct input. Obviously it requires Pygmentize (which is really <a href="http://pygments.org/download/">easy to install</a> if you already have Python).</p>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tab Indented Standard Input Redirect in Bash</title>
		<link>http://scott.sherrillmix.com/blog/programmer/tab-indented-standard-input-redirect-in-bash/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/tab-indented-standard-input-redirect-in-bash/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 02:52:43 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Bash/UNIX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[EOF]]></category>
		<category><![CDATA[indent]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[standard input]]></category>
		<category><![CDATA[tab]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=502</guid>
		<description><![CDATA[I managed to forget how to redirect standard input (when you want to feed a bunch of lines to a program) in a bash script while still indenting and had to go digging around for it. So I figured I'd make a note here so I don't forget again and for anyone else in the [...]]]></description>
			<content:encoded><![CDATA[<p>I managed to forget how to redirect standard input (when you want to feed a bunch of lines to a program) in a bash script while still indenting and had to go digging around for it. So I figured I'd make a note here so I don't forget again and for anyone else in the same boat. It's just <code>&lt;&lt;-</code> instead of <code>&lt;&lt;</code>. For example if you want to keep indentation within a loop:</p>
<div class="syntax_hilite"><span class="langName">BASH:</span><br /><div id="bash-6">
<div class="bash"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">for</span> i <span style="color: #b1b100;">in</span> <span style="color: #cc66cc;color:#800000;">1</span> <span style="color: #cc66cc;color:#800000;">2</span> <span style="color: #cc66cc;color:#800000;">3</span> <span style="color: #cc66cc;color:#800000;">4</span>;do</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; cat&lt;&lt;-EOF</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; This is loop <span style="color: #0000ff;">$i</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; More advanced stuff could go here</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; EOF</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">done</span> </div></li></ol></div>
</div></div><br />
<p>You can use whatever you want to indicate the end of the input instead of EOF if it floats your boat (as long as you use the same thing both times) but unfortunately <code>&lt;&lt;-</code> doesn't work with spaces for indentation (although I'm a tab man myself).</p>
]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/tab-indented-standard-input-redirect-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Displaying Code in LaTeX</title>
		<link>http://scott.sherrillmix.com/blog/programmer/displaying-code-in-latex/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/displaying-code-in-latex/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 06:28:37 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[syntax highlighting]]></category>
		<category><![CDATA[verbatim]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=437</guid>
		<description><![CDATA[gioby of Bioinfo Blog! (an interesting read by the way) left a comment asking about displaying code in LaTeX documents. I've sort of been cludging around using \hspace's and \textcolor but I've always meant to figure out the right way to do things so this seemed like a good chance to figure out how to [...]]]></description>
			<content:encoded><![CDATA[<p>gioby of <a href='http://bioinfoblog.it/'>Bioinfo Blog!</a> (an interesting read by the way) left a comment asking about displaying code in LaTeX documents. I've sort of been cludging around using <code>\hspace</code>'s and <code>\textcolor</code> but I've always meant to figure out the right way to do things so this seemed like a good chance to figure out how to do it right.</p>

<p>LaTeX tends to ignore white space. This is good when you're writing papers but not so good when you're trying to show code where white space is an essential part (e.g. Python). Luckily there's a builtin <code>verbatim</code> environment in LaTeX that is equivalent to html's <code>&lt;pre&gt;</code>. So something like the following should preserve white space.</p>
<img src="/res/images/latex_verbatim.png" alt="Code in LaTeX using verbatim" class="right"/><pre><code>\begin{verbatim}
for i in range(1, 5):
  print i
else:
  print &quot;The for loop is over&quot;
\end{verbatim}</code></pre>

<p>Unfortunately, you can't use any normal LaTeX commands inside verbatim (since they're displayed <em>verbatim</em>). But luckily there a handy package called <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/">fancyvrb</a> that fixes this (the <a href="http://www.ctan.org/tex-archive/help/Catalogue/entries/color.html">color</a> package is also useful for adding colors). For example, if you wanted to highlight "for" in the above code, you can use the <code>Verbatim</code> (note the capital V) environment from fancyvrb:</p>
<img src="/res/images/latex_fancyvrb.png" alt="Code in LaTeX using fancyvrb" class="right"/>
<pre><code>\newcommand\codeHighlight[1]{\textcolor[rgb]{1,0,0}{\textbf{#1}}}
\begin{Verbatim}[commandchars=\\\{\}]
\codeHighlight{for} i in range(1, 5):
  print i
else:
  print &quot;The for loop is over&quot;
\end{Verbatim}
</code></pre>

<img src="/res/images/latex_pygmentize.png" alt="Code in LaTeX using pygmentize" class="right"/>
<p>If you really want to get fancy, the <a href='http://pygments.org/docs/quickstart/'>Pygments package</a> in Python will output syntax highlighted latex code with a command like: <code>pygmentize -f latex -O full test.py &gt;py.tex</code> The LaTeX it outputs is a bit hard to read but it's not too bad (it helped me figure out the fancyvrb package) and it does make nice syntax highlighted output.</p>

<p>Here's an example LaTeX file with the three examples above and the pdf it generates if you're curious.</p>
<ul>
<li><a href="/res/codeInLatex.tex">codeInLatex.tex</a></li>
<li><a href="/res/codeInLatex.pdf">codeInLatex.pdf</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/displaying-code-in-latex/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
