<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2881497249851644909</id><updated>2012-02-15T23:20:23.568-08:00</updated><category term='linux'/><category term='java'/><category term='mysql'/><category term='programming'/><category term='graphics'/><category term='windows'/><category term='eclipse'/><category term='Perl'/><category term='bash'/><category term='blogging'/><category term='utils'/><category term='bioinformatics'/><category term='avr'/><category term='R'/><category term='c'/><title type='text'>GeekBrainDump</title><subtitle type='html'>This is mainly somewhere for me to dump interesting tidbits of tech info.  Stuff that I may forget but will need again in the future.  For a proper blog, visit my electronics blog (http://www.fangletronics.com) or my wife's pre-school crafty blog (http://www.filthwizardry.com).</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>60</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-7126130135462994370</id><published>2011-12-06T17:45:00.001-08:00</published><updated>2012-01-24T12:52:14.058-08:00</updated><title type='text'>R: Empirical Cumulative Distribution Function</title><content type='html'>There's a handy R built-in function for calculating the &lt;a href="http://en.wikipedia.org/wiki/Empirical_distribution_function"&gt;empirical cdf&lt;/a&gt; called ecdf. &amp;nbsp;I had 40 separate distributions (molecular weight for different series of molecules) and wanted to look at the cdf for this. &amp;nbsp;In R it's really straightforward. &amp;nbsp;Here's an example where we simulate some molecular weight data and plot the CDF for the whole set:&lt;br /&gt;&lt;br /&gt;# create the data&lt;br /&gt;&lt;span style="font-family: inherit;"&gt;R&amp;gt; data &amp;lt;-&amp;nbsp;&lt;span style="line-height: 1.3; text-align: -webkit-left; white-space: pre-wrap;"&gt;data.frame(mw=rnorm(10000, mean=400, sd=50), name=1:10000, group=sample(c('a','b','c','d'), 1000, replace=T))&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: inherit;"&gt;&lt;span style="line-height: 1.3; text-align: -webkit-left; white-space: pre-wrap;"&gt;R&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="line-height: 20px; white-space: pre-wrap;"&gt;mw_cdf &amp;lt;- data.frame(cdf=ecdf(data$mw)(data$mw)*100, mw=data$mw)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; border-collapse: separate;"&gt;&lt;span class="Apple-style-span" style="line-height: 17px; text-align: -webkit-left; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: inherit;"&gt;R&amp;gt; qplot(mw, cdf, data=mw_cdf, geom="step", xlab="Molecular weight", ylab="Total (%)", main="CDF of MW")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: inherit;"&gt;The ecdf() call returns a function (of class "ecdf") which you can call with a MW to calculate the probability of seeing a molecule of this, or smaller, MW in your set.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: inherit;"&gt;The R code above produces the following plot:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-hIquxxh-HQo/TxnKwWTJ87I/AAAAAAAACOo/Lu4ECypyUps/s1600/CDFexample.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="326" src="http://4.bp.blogspot.com/-hIquxxh-HQo/TxnKwWTJ87I/AAAAAAAACOo/Lu4ECypyUps/s400/CDFexample.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;I found this useful for looking at the MW distributions for disparate groups of molecules, both together and separately. &amp;nbsp;If you're going to apply a molecular weight cutoff when analysing a set of molecules, it's good to get an idea of how many you'll be excluding and this provides a very quick way of seeing that information.&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-7126130135462994370?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/7126130135462994370/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2011/12/empirical-cumulative-distribution.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7126130135462994370'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7126130135462994370'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2011/12/empirical-cumulative-distribution.html' title='R: Empirical Cumulative Distribution Function'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-hIquxxh-HQo/TxnKwWTJ87I/AAAAAAAACOo/Lu4ECypyUps/s72-c/CDFexample.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-2272548085420565774</id><published>2011-12-01T16:50:00.001-08:00</published><updated>2011-12-01T16:57:47.248-08:00</updated><title type='text'>Running chrome on multiple displays</title><content type='html'>By display here I mean &lt;b&gt;&lt;i&gt;$DISPLAY&lt;/i&gt;&lt;/b&gt; not multiple monitors. &lt;br /&gt;&lt;br /&gt;I often leave Chrome running at work (on a ton of virtual desktops with a ton of tabs) and then get home and need to log into work (via VPN + NX) in order to check on things. &amp;nbsp;It's frustrated me that if I try to run chrome in the NX session then it appears on my screen at work rather than in the NX session. &amp;nbsp;Well, who would have thought that reading the man page would solve the frustration? &amp;nbsp;This method sets up a new profile, so you loose all &amp;nbsp;your bookmarks and settings, but that's ok for&amp;nbsp;occasional&amp;nbsp;use I think&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;/opt/google/chrome/google-chrome --user-data-dir=&amp;lt;dir&amp;gt;&lt;br /&gt;&lt;/pre&gt;Where &lt;i&gt;&amp;lt;dir&amp;gt;&lt;/i&gt; is a dir of your choosing.  The default for chrome is ~/.config/google-chrome/.  So I've been using ~/.config/google-chrome/nx.Phew, friction resolved.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-2272548085420565774?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/2272548085420565774/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2011/12/running-chrome-on-multiple-displays.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2272548085420565774'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2272548085420565774'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2011/12/running-chrome-on-multiple-displays.html' title='Running chrome on multiple displays'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-3008495427579910982</id><published>2011-10-18T11:59:00.000-07:00</published><updated>2011-10-18T11:59:33.685-07:00</updated><title type='text'>Using linux 'seq' with large numbers</title><content type='html'>Sometimes I deal with quite a lot of data (IMO).  Occasionally this has to be split into smaller files in order to be processed.  I use 'seq' quite a lot for generating program lists to work on these files.  &lt;br /&gt;&lt;br /&gt;I ran into an issue the other day; I wanted to include the line-number offset in the filename of the files I was generating, unfortunately as soon as I hit a million lines the 'seq' numbers started to use scientific notation (i.e. rather than 1000000 seq output 1e+6) - unfortunately, this wasn't compatible with some of the downstream processing.  &lt;br /&gt;&lt;br /&gt;The 'seq' manpage seemed to claims that it accepts printf formatting arguments.  So I tried running 'seq -f "%d" 0 10000 160000000' and 'seq -f "%i" 0 10000 160000000' but neither of these were recognised.   It turns out that seq actually only recognises the printf style &lt;b&gt;floating-point&lt;/b&gt; format... so to get it to work as desired you have to use "%.0f" instead:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&amp;gt; seq -f "%.0f" 1000000 1000000 10000000&lt;br /&gt;1000000 &lt;br /&gt;2000000 &lt;br /&gt;3000000 &lt;br /&gt;4000000 &lt;br /&gt;5000000 &lt;br /&gt;6000000 &lt;br /&gt;7000000 &lt;br /&gt;8000000 &lt;br /&gt;9000000 &lt;br /&gt;10000000 &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-3008495427579910982?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/3008495427579910982/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2011/10/using-linux-seq-with-large-numbers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3008495427579910982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3008495427579910982'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2011/10/using-linux-seq-with-large-numbers.html' title='Using linux &apos;seq&apos; with large numbers'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-2198971026766818065</id><published>2011-09-20T10:22:00.000-07:00</published><updated>2011-09-20T10:22:04.319-07:00</updated><title type='text'>"Rule Engine" Knime node - matching missing values</title><content type='html'>I just spent fifteen minutes trying to work out how to match missing values in the &lt;a href="http://www.knime.org"&gt;Knime &lt;/a&gt;"Rule Engine" node.  It turns out you put the "MISSING" keyword before the column definition.&lt;br /&gt;&lt;br /&gt;So, the rule looks something like this:&lt;br /&gt;&lt;br /&gt;MISSING $species$ =&gt; 'blank'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-2198971026766818065?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/2198971026766818065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2011/09/rule-engine-knime-node-matching-missing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2198971026766818065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2198971026766818065'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2011/09/rule-engine-knime-node-matching-missing.html' title='&quot;Rule Engine&quot; Knime node - matching missing values'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-4528485295966951527</id><published>2011-05-05T09:13:00.000-07:00</published><updated>2011-05-05T09:13:14.072-07:00</updated><title type='text'>R: invalid multibyte string</title><content type='html'>I've just been using R for some string comparison work (pairing the titles from two reference sets where the formatting was quite different).  I bashed my head against the wall for a little while trying to figure out why the analysis was failing with a "invalid mulibyte string 1" error.  &lt;br /&gt;&lt;br /&gt;Ok, the error itself is fairly obvious - the supposedly plain text strings contained some non-ASCII characters.  Finding those characters was the issue.  I tried grep ("[^:print:]" and a few others) and nedit but couldn't see the issue.  Turns out just using &lt;code&gt;less&lt;/code&gt; solved my problems.  The non-ASCII characters are highlighted for all to see (so they're easy to remove using a text editor at that point).&lt;br /&gt;&lt;br /&gt;Oh, and if you're interested I was using stringdot from the &lt;a href="cran.r-project.org/web/packages/kernlab/"&gt;'kernlab'&lt;/a&gt; package to compare the strings.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-4528485295966951527?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/4528485295966951527/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2011/05/r-invalid-multibyte-string.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4528485295966951527'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4528485295966951527'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2011/05/r-invalid-multibyte-string.html' title='R: invalid multibyte string'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-4419797959578795090</id><published>2011-04-06T11:13:00.000-07:00</published><updated>2011-04-06T11:13:58.434-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>View a summary of filetypes in a dir</title><content type='html'>Sometimes I fill up directories with lots of files of lots of types (different extensions).  It's informative to be able to see what the distribution of types is in a dir.  I tend to use this view during project cleanups to identify files that can be deleted or moved/consolidated.  Anyway, here's a quick way of doing it:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;for file in $(ls *.*); do base=$(basename $file); echo ${base##*\.};done | sort | uniq -c | sort -n -r&lt;br /&gt;  37 tsv&lt;br /&gt;  18 pdf&lt;br /&gt;  17 txt&lt;br /&gt;   7 err&lt;br /&gt;   5 log&lt;br /&gt;   5 png&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here I see that there are some log files that can be removed (if no longer needed).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-4419797959578795090?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/4419797959578795090/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2011/04/view-summary-of-filetypes-in-dir.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4419797959578795090'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4419797959578795090'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2011/04/view-summary-of-filetypes-in-dir.html' title='View a summary of filetypes in a dir'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-1686713130318078777</id><published>2011-02-13T22:31:00.000-08:00</published><updated>2011-02-13T22:31:08.979-08:00</updated><title type='text'>Reading stdin from a pipe for command-line R shenanigans</title><content type='html'>I think I rely on command-line tomfoolery a little bit too much.  Today I wanted to pipe some data into R and have the commands to run defined on the command line as well.  This is the kind of thing I do with Perl or bash to get some quick answers and I'd love to add R to the repertoire. &lt;br /&gt;&lt;br /&gt;So, I tried a number of things all of which failed.  This is how I got it to work for me:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&gt; perl -le 'printf "%.4f\t%.4f\n", rand(), rand() for 1 .. 20' \&lt;br /&gt; | R --vanilla --slave -e\&lt;br /&gt; "data=read.delim(pipe('cat /dev/stdin'), header=F);\&lt;br /&gt;  cor.test(data\$V1, data\$V2)"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You have to remember to escape any special characters in the R script (&lt;code&gt;$&lt;/code&gt; in this case).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-1686713130318078777?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/1686713130318078777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2011/02/reading-stdin-from-pipe-for-command.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1686713130318078777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1686713130318078777'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2011/02/reading-stdin-from-pipe-for-command.html' title='Reading stdin from a pipe for command-line R shenanigans'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-6213378778490615694</id><published>2011-01-12T14:51:00.000-08:00</published><updated>2011-01-12T14:51:17.343-08:00</updated><title type='text'>R: using lattice graphs in functions</title><content type='html'>I like the lattice graphics package; it produces nice looking and easy to generate graphs.  However, I was bitten the other day when a function I'd written to generate a load of density plots wasn't creating the output files I was expecting.  They just weren't there at all.  After a little bit of unsuccessful poking around, I gave up and generated them manually (it was a stressful day with tight deadlines).&lt;br /&gt;&lt;br /&gt;I went back to this issue today and it turns out that the lattice functions 'do not create plots'. You have to print the object created from the lattice function in order to see/output the graph.&lt;br /&gt;&lt;br /&gt;This happens automatically on the command line, which is why I was so confused since the code would work fine outside of a function.  If you want your graph to be outputted within a function you have to explicitly print it.&lt;br /&gt;&lt;br /&gt;e.g.:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;function write_density_plot(data, name)&lt;br /&gt;{&lt;br /&gt;    filename = paste(name, '_density_distribution.png', sep="")&lt;br /&gt;    png(filename)&lt;br /&gt;    print(densityplot(data, main=paste(name, 'score distribution'))&lt;br /&gt;    dev.off()&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;filedata = read.delim('myfile', header=T)&lt;br /&gt;write_density_plot(filedata$blorg, 'blorg')&lt;br /&gt;write_density_plot(filedata$blarg, 'blarg')&lt;br /&gt;write_density_plot(filedata$wib, 'wib')&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-6213378778490615694?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/6213378778490615694/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2011/01/r-using-lattice-graphs-in-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/6213378778490615694'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/6213378778490615694'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2011/01/r-using-lattice-graphs-in-functions.html' title='R: using lattice graphs in functions'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-5920990428920824231</id><published>2010-11-28T00:04:00.000-08:00</published><updated>2010-11-28T00:04:56.173-08:00</updated><title type='text'>EMC2, G64 and sharp corners</title><content type='html'>I've cut a number of things on my CNC machine using &lt;a href="http://linuxcnc.org/"&gt;EMC2&lt;/a&gt;.  I've been perplexed by the fact that some of the corners in my test shapes were not sharp, but were rounded off.  &lt;br /&gt;&lt;br /&gt;I've just been designing and cutting some new leadnut holders and found that the hexagonal depression I was cutting was also plagued with these curved corners (not good when you need a hex nut to fit in them).  It turns out this is to do with the G64 command in the &lt;a href="http://en.wikipedia.org/wiki/Gcode"&gt;G-Code&lt;/a&gt; which tells the trajectory planner to sacrifice path following accuracy in order to keep the feed rate up (i.e. cut/round corners).  A good description is available in the EMC2 documentation section covering &lt;a href="http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?TrajectoryControl"&gt;trajectory control&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I manually edited my G-code (this one coming from &lt;a href="http://www.cambam.info/"&gt;CamBam&lt;/a&gt;, but past ones were from &lt;a href="http://www.inkscape.org/"&gt;Inkscape &lt;/a&gt;and &lt;a href="http://code.google.com/p/dxf2gcode/"&gt;dxf2gcode&lt;/a&gt;) so that the G64 command now read "G64 P0.001" and the hexagon cut with much sharper corners.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-5920990428920824231?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/5920990428920824231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/11/emc2-g64-and-sharp-corners.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5920990428920824231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5920990428920824231'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/11/emc2-g64-and-sharp-corners.html' title='EMC2, G64 and sharp corners'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-1567701663193412770</id><published>2010-11-12T13:08:00.000-08:00</published><updated>2010-11-12T13:08:47.412-08:00</updated><title type='text'>Fun with process substitution</title><content type='html'>I was introduced to process substitution recently at work, it's a great way to avoid temporary files for some simple cases.&lt;br /&gt;&lt;br /&gt;For example, say I wanted to know what the column header changes were between two files (same data, different code used to extract them).  The files are tab delimited and I have a script I use (frequently) that prints out the index and name for the headers in an input file - &lt;code&gt;columnHeaders.sh&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;So, if I want to see what's different between two files, in the past I'd create two output files using my &lt;code&gt;columnHeaders.sh&lt;/code&gt; script and then use &lt;code&gt;diff&lt;/code&gt;, &lt;code&gt;kompare&lt;/code&gt; or &lt;code&gt;comm&lt;/code&gt; to compare them.&lt;br /&gt;&lt;br /&gt;You can eliminate the temporary files using a technique called &lt;a href="http://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html"&gt;process substitution&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&amp;gt; diff &lt;(columnHeaders.sh file1) &lt;(columnHeaders.sh file2)&lt;br /&gt;2,3c2,3&lt;br /&gt;&amp;gt; 0 blarg&lt;br /&gt;&amp;gt; 1 blorg&lt;br /&gt;--&lt;br /&gt;&amp;lt; 0 blorg&lt;br /&gt;&amp;lt; 1 blarg&lt;br /&gt;&lt;/pre&gt;In this case we see two columns have been swapped between file1 and file2.&lt;br/&gt;&lt;br/&gt;Take a look at the &lt;a href="http://tldp.org/LDP/abs/html/process-sub.html"&gt;Advanced Bash Scripting Guide&lt;/a&gt; for more examples.&lt;br/&gt;&lt;br/&gt;The &lt;code&gt;columnHeaders.sh&lt;/code&gt; script basically does this (but allows user specified delimiters):&lt;pre class="brush:bash"&gt;&amp;gt; head -1 &amp;lt;input file&amp;gt; | perl -F'\t' -lane 'print $n++,"\t$_" for @F'&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-1567701663193412770?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/1567701663193412770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/11/fun-with-process-substitution.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1567701663193412770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1567701663193412770'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/11/fun-with-process-substitution.html' title='Fun with process substitution'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-2044890548469904372</id><published>2010-09-17T15:49:00.000-07:00</published><updated>2010-09-17T16:11:31.889-07:00</updated><title type='text'>Bash command line parameter parsing (getopts)</title><content type='html'>If I only need a single optional parameter I'll often just check to see if the input positional parameter of interest is set (e.g. script that accepts one required field and one optional field):&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;if [[ ! -n "$2" ]];&lt;br /&gt;then&lt;br /&gt;    echo "I received the second parameter:$2"&lt;br /&gt;fi&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But if you want to do something a bit more complex, &lt;code&gt;getopts&lt;/code&gt; is your friend.&lt;br /&gt;&lt;br /&gt;For example, say you want to have the user input their first name, last name and a "keep my data private" flag you could do something like this:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;while getopts f:l:p flag&lt;br /&gt;do&lt;br /&gt;    case $flag in&lt;br /&gt;        f)&lt;br /&gt;            FIRSTNAME=$OPTARG;;&lt;br /&gt;        l)&lt;br /&gt;            LASTNAME=$OPTARG;;&lt;br /&gt;        p)&lt;br /&gt;            PRIVATE=1;;&lt;br /&gt;        ?)&lt;br /&gt;            echo "$0 -f &amp;lt;first name&amp;gt; -l &amp;lt;last name&amp;gt; -p"&lt;br /&gt;            echo -e "\t-p [flag] keep my data private"&lt;br /&gt;            exit&lt;br /&gt;done&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The &lt;a href="http://ss64.com/bash/getopts.html"&gt;getopts &lt;/a&gt;command is fairly straightforward (&lt;code&gt;man getopts&lt;/code&gt; for more details).  If an option requires an argument then a colon is placed after it's letter designation ('f' and 'l' in the above example). &lt;br /&gt;&lt;br /&gt;You can check for required parameters by looking at which variables were set:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;if [[-z "$FIRSTNAME" || -z "$LASTNAME" ]];&lt;br /&gt;then&lt;br /&gt;    echo "missing required parameter"&lt;br /&gt;fi&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wrap that all up into a neat script with a subroutine that outputs a usage statement and you're home free:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;function usage_and_exit()&lt;br /&gt;{&lt;br /&gt;    echo "$0 -f &amp;lt;first name&amp;gt; -l &amp;lt;last name&amp;gt; -p"&lt;br /&gt;    echo -e "\t-p [flag] keep my data private"&lt;br /&gt;    exit&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;while getopts f:l:p flag&lt;br /&gt;do&lt;br /&gt;    case $flag in&lt;br /&gt;        f)&lt;br /&gt;            FIRSTNAME=$OPTARG;;&lt;br /&gt;        l)&lt;br /&gt;            LASTNAME=$OPTARG;;&lt;br /&gt;        p)&lt;br /&gt;            PRIVATE=1;;&lt;br /&gt;        ?)&lt;br /&gt;            usage_and_exit;;&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;if [[ -z "$FIRSTNAME" || -z "$LASTNAME" ]];&lt;br /&gt;then&lt;br /&gt;    echo "missing a required parameter (firstname and lastname are required)"&lt;br /&gt;    usage_and_exit&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;if [[ $PRIVATE -ne 0 ]];&lt;br /&gt;then&lt;br /&gt;    echo "protecting private data"&lt;br /&gt;fi&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-2044890548469904372?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/2044890548469904372/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/09/bash-command-line-parameter-parsing.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2044890548469904372'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2044890548469904372'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/09/bash-command-line-parameter-parsing.html' title='Bash command line parameter parsing (getopts)'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-1817729594487702987</id><published>2010-08-18T11:41:00.000-07:00</published><updated>2010-08-18T11:52:51.812-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><title type='text'>MySQL: the mystery of unsetable global variables</title><content type='html'>I just tried updating our mysql server to accept very long connections.  I have a ton of jobs running, so I wanted to set the wait_timeout variable (via the mysql shell) to something reasonable for these jobs.  The default of 8 hours is not sufficient in some rare cases so I tried to set the timeout higher:&lt;br /&gt;&lt;pre class="brush:sql"&gt;&lt;br /&gt;mysql&amp;gt; SHOW VARIABLES LIKE 'wait_timeout';&lt;br /&gt;+--------------------------+-------+&lt;br /&gt;| Variable_name            | Value |&lt;br /&gt;+--------------------------+-------+&lt;br /&gt;| wait_timeout             | 28800 |&lt;br /&gt;+--------------------------+-------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&amp;gt; SET GLOBAL wait_timeout=86400;&lt;br /&gt;mysql&amp;gt; SHOW VARIABLES LIKE 'wait_timeout';&lt;br /&gt;+--------------------------+-------+&lt;br /&gt;| Variable_name            | Value |&lt;br /&gt;+--------------------------+-------+&lt;br /&gt;| wait_timeout             | 28800 |&lt;br /&gt;+--------------------------+-------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;What?  Why wasn't it set?&lt;br /&gt;&lt;br /&gt;Well, the reason is that the &lt;tt&gt;SHOW VARIABLES&lt;/tt&gt; command defaults to the session variables.  So, the local session wait_timeout is still 2880, but the global wait_timeout was actually updated correctly:&lt;br /&gt;&lt;pre class="brush:sql"&gt;&lt;br /&gt;mysql&amp;gt; SHOW GLOBAL VARIABLES LIKE 'wait_timeout';&lt;br /&gt;+--------------------------+-------+&lt;br /&gt;| Variable_name            | Value |&lt;br /&gt;+--------------------------+-------+&lt;br /&gt;| wait_timeout             | 86400 |&lt;br /&gt;+--------------------------+-------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-1817729594487702987?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/1817729594487702987/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/08/mysql-mystery-of-unsetable-global.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1817729594487702987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1817729594487702987'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/08/mysql-mystery-of-unsetable-global.html' title='MySQL: the mystery of unsetable global variables'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-8704636685807792405</id><published>2010-07-14T17:15:00.000-07:00</published><updated>2010-07-14T17:41:23.004-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Basic MySQL 'top' command</title><content type='html'>Ever wanted to keep an eye on the running processes in a MySQL database?  How about something that works a little like the &lt;code&gt;top&lt;/code&gt; command, but without &lt;b&gt;any&lt;/b&gt; of the bells and whistles?&lt;br /&gt;&lt;br /&gt;Well, here you go:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&gt; while [[ 1 ]];&lt;br /&gt;do&lt;br /&gt; clear;&lt;br /&gt; mysql -u &amp;lt;username&amp;gt; -p&amp;lt;password&amp;gt; -h &amp;lt;host&amp;gt; -e "show full processlist";&lt;br /&gt; sleep 1;&lt;br /&gt;done&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Remember to replace the &amp;lt;username&amp;gt; &amp;lt;password&amp;gt; and &amp;lt;host&amp;gt; variables with the values for your database.  Also, if you don't like the bounding box on the mysql output, you can have a cleaner output by using redirection instead of the -e flag:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;mysql -u &amp;lt;username&amp;gt; -p&amp;lt;password&amp;gt; -h &amp;lt;host&amp;gt; &amp;lt;&amp;lt;&amp;lt; "show full processlist";&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-8704636685807792405?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/8704636685807792405/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/07/basic-mysql-top-command.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8704636685807792405'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8704636685807792405'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/07/basic-mysql-top-command.html' title='Basic MySQL &apos;top&apos; command'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-3407196918659012861</id><published>2010-06-16T10:49:00.000-07:00</published><updated>2010-07-14T17:41:41.624-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Case insensitive regex in bash</title><content type='html'>By default regexes in [[ ]] are case sensitive.  If you want to match in a case insensitive way you have to set the shell option &lt;code&gt;nocasematch&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;mytext="eXistenZ"&lt;br /&gt;if [[ $mytext =~ existenz ]];&lt;br /&gt;then &lt;br /&gt; echo "yep"&lt;br /&gt;else&lt;br /&gt; echo "nope"&lt;br /&gt;fi&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If you run the above script you should get "nope" as the output.  For case insensitive matching just insert this into the script prior to the regex:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;shopt -s nocasematch;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can unset the &lt;code&gt;nocasematch&lt;/code&gt; shell option using the following: &lt;code&gt;shopt -u nocasematch&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here's a more complete example:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;mytext="eXistenZ"&lt;br /&gt;function testText&lt;br /&gt;{&lt;br /&gt; if [[ $mytext =~ existenz ]];&lt;br /&gt; then &lt;br /&gt;  echo "yep"&lt;br /&gt; else&lt;br /&gt;  echo "nope"&lt;br /&gt; fi;&lt;br /&gt;}&lt;br /&gt;testText&lt;br /&gt;shopt -s nocasematch&lt;br /&gt;testText&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you run that script then the output is:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;nope&lt;br /&gt;yep&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-3407196918659012861?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/3407196918659012861/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/06/case-insensitive-regex-in-bash.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3407196918659012861'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3407196918659012861'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/06/case-insensitive-regex-in-bash.html' title='Case insensitive regex in bash'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-4715563506696152745</id><published>2010-06-13T22:38:00.000-07:00</published><updated>2010-07-14T17:41:47.826-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='R'/><title type='text'>R related links</title><content type='html'>These are just a few R links I think are interesting and worth a further read:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt; &lt;a href="http://www.r-bloggers.com/color-palettes-in-r/"&gt;Colour palettes in R&lt;/a&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://digitheadslabnotebook.blogspot.com/2010/06/using-r-for-introductory-statistics-32.html"&gt;Using R for introductory statistics&lt;/a&gt;&lt;/li&gt; &lt;br /&gt;&lt;li&gt;&lt;a href="http://www.techpolicy.ca/?p=95"&gt;Web-friendly visualisations in R&lt;/a&gt;&lt;/li&gt; &lt;br /&gt;&lt;li&gt;&lt;a href="http://www.statisticsblog.com/2010/06/a-different-way-to-view-probability-densities/"&gt;A different way to view probability densities&lt;/a&gt;&lt;/li&gt; &lt;br /&gt;&lt;li&gt;&lt;a href="http://blog.revolutionanalytics.com/2010/06/thoughts-on-making-data-work.html"&gt;Thoughts on Making Data Work&lt;/a&gt;&lt;/li&gt; &lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;Also of note is Google's announcement (on June 2nd) that they were working with the USPTO to make all granted patents, trademarks and published applications freely available for download - see &lt;a href="http://googlepublicpolicy.blogspot.com/2010/06/free-download-10-terabytes-of-patents.html"&gt;this post&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-4715563506696152745?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/4715563506696152745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/06/r-related-links.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4715563506696152745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4715563506696152745'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/06/r-related-links.html' title='R related links'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-3313795400161631308</id><published>2010-06-01T09:35:00.000-07:00</published><updated>2010-06-01T09:47:31.552-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>I love subshells</title><content type='html'>Sometimes it's the little things in life that give us the greatest pleasures.  I love subshells.  There, I admitted it.&lt;br /&gt;&lt;br /&gt;Say you want to do something with the output of a program but would like to prepend some output/text that also needs to be operated on.  The standard idiom would be to create a file with the prepended output, append your output to this and then operate on the file, but you can remove the intermediate files using a subshell.  Here's a contrived example:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; (echo -e "some\toutput\tto\tappend"; perl -lane 'print join("\t", log($F[0])/log(10), @F[1 .. #$F])' &lt;file&gt;;) | a2ps&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Something else I use subshells for a lot is to launch programs in a different directory without having to &lt;code&gt;cd&lt;/code&gt; there and then back again:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; (cd ~/workspace/; eclipse &amp;)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;like I said; it's the little things.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-3313795400161631308?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/3313795400161631308/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/06/i-love-subshells.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3313795400161631308'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3313795400161631308'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/06/i-love-subshells.html' title='I love subshells'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-5345523660715260802</id><published>2010-05-18T16:28:00.000-07:00</published><updated>2010-05-18T17:54:23.956-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>delete all empty files in a directory</title><content type='html'>Automatically generating files?  Annoyed at all the empty ones?  Here's how to purge them:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; for file in $( ls . ); do if [ ! -s $file ]; then rm -f $file; fi; done&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Of course you could just get over your fear of &lt;tt&gt;&lt;a href="http://linuxcommand.org/man_pages/find1.html"&gt;find&lt;/a&gt;&lt;/tt&gt; and take a look at that man page.  Perfect for a recursive search and delete all in one:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; find . -empty -delete&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;simple, no?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-5345523660715260802?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/5345523660715260802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/05/delete-all-empty-files-in-directory.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5345523660715260802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5345523660715260802'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/05/delete-all-empty-files-in-directory.html' title='delete all empty files in a directory'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-3826973585250854264</id><published>2010-05-14T16:08:00.001-07:00</published><updated>2010-05-14T16:58:55.851-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>escaping quotes in bash variables</title><content type='html'>I often need to escape quotation characters or other special characters that are being piped into a bash process:&lt;br /&gt;&lt;br /&gt;Say you have a mysql table which contains protein names.  Some of these have the &lt;tt&gt;'&lt;/tt&gt; character in them (e.g. "Inosine 5' monophosphate dehydrogenase") and you want to do some bulk processing on these names, you could do something like this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; mysql -u paulbo -N &amp;lt;&amp;lt;&amp;lt; "SELECT name from proteins" | while read protein_name; do mysql -u paulbo -N "SELECT count(*) FROM data INNER JOIN proteins ON data.protein_id = proteins.protein_id where proteins.name = '${protein_name//\'/\\\'}'"; done&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Ah, three backslashes.  Why didn't I think of that?&lt;br /&gt;&lt;br /&gt;And sometimes you just want to output the text with the special characters all converted into something a bit more amenable (like the old and trusted '_').&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; mysql -u paulbo -N &amp;lt;&amp;lt;&amp;lt; "SELECT name from proteins" | while read protein_name; do echo ${protein_name//[-\/\:\'\"\(\) ]/_};done&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-3826973585250854264?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/3826973585250854264/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/05/escapes-in-bash-strings.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3826973585250854264'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3826973585250854264'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/05/escapes-in-bash-strings.html' title='escaping quotes in bash variables'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-7132379090991174622</id><published>2010-05-06T13:40:00.000-07:00</published><updated>2010-05-06T13:45:09.108-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Excluding certain files from a directory listing</title><content type='html'>Ok, well, this will be obvious to anyone who's really read the &lt;code&gt;ls&lt;/code&gt; man page, but I only came across it a couple of days ago.&lt;br /&gt;&lt;br /&gt;Say you have a directory with tons of files in it mostly with a single extension and you want to see what else is in there.  Sure, you can use grep, but you can also use &lt;code&gt;ls&lt;/code&gt;'s inbuilt flat &lt;code&gt;--hide&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; ls -l&lt;br /&gt;arg.txt&lt;br /&gt;blarg.txt&lt;br /&gt;foo.txt&lt;br /&gt;...&lt;br /&gt;interesting.sh&lt;br /&gt;... # and a ton more *.txt files&lt;br /&gt;zlargyblorg.txt&lt;br /&gt;&gt; ls -l --hide=*.txt&lt;br /&gt;interesting.sh&lt;br /&gt;hidden.csv&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Isn't that useful?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-7132379090991174622?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/7132379090991174622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/05/excluding-certain-files-from-directory.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7132379090991174622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7132379090991174622'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/05/excluding-certain-files-from-directory.html' title='Excluding certain files from a directory listing'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-8034287313371265223</id><published>2010-04-30T17:48:00.000-07:00</published><updated>2010-04-30T17:51:53.903-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>batch renaming files with spaces</title><content type='html'>Why do people keep giving me tons of files with spaces in the filename?&lt;br /&gt;&lt;br /&gt;Anyway, here's a good way to get rid of those pesky spaces:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;ls * | while read file; do mv "$file" ${file// /_}; done&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;First I tried using "for file in `ls *`" but of course the whitespaces came back to bite me...  This was also true for the mv command.  You have to quote "$file" in order for the whitespace ridden filename to be recognised as a unit rather than multiple file descriptors.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-8034287313371265223?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/8034287313371265223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/04/batch-renaming-files-with-spaces.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8034287313371265223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8034287313371265223'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/04/batch-renaming-files-with-spaces.html' title='batch renaming files with spaces'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-5933395770071167704</id><published>2010-04-27T17:11:00.000-07:00</published><updated>2010-04-27T17:25:22.819-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>bash array size</title><content type='html'>Strangely this caught me off guard.  If you use &lt;code&gt;${#array[@]}&lt;/code&gt; to get the 'size' of an array, it actually only returns the number of assigned elements in the array.&lt;br /&gt;&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; array[23]=123&lt;br /&gt;&amp;gt; echo ${#array[@]}&lt;br /&gt;1&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Hmm... only 1?  Not 24?&lt;br /&gt;&lt;br /&gt;As far as I can tell, there's no way around this.  Just don't expect this behaviour and fill your arrays wisely.&lt;br /&gt;&lt;br /&gt;While we're on bash arrays, remember that you can change the 'join' character for naive printing of arrays by manipulating the IFS (Internal Field Separator) variable.  Below I also show that the quotation context is important for this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; array[0]=1;array[1]=2;array[2]=3;&lt;br /&gt;&amp;gt; echo ${array[*]}&lt;br /&gt;1 2 3&lt;br /&gt;&amp;gt; echo "${array[*]}"&lt;br /&gt;1 2 3&lt;br /&gt;&amp;gt; IFS=","&lt;br /&gt;&amp;gt; echo ${array[*]}&lt;br /&gt;1 2 3&lt;br /&gt;&amp;gt; echo "${array[*]}"&lt;br /&gt;1,2,3&lt;br /&gt;&amp;gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note: It's best practice to store and then restore the original IFS variable.&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; ORIG_IFS=IFS&lt;br /&gt;... do stuff&lt;br /&gt;&amp;gt; IFS=ORIG_IFS&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-5933395770071167704?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/5933395770071167704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/04/bash-array-size.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5933395770071167704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5933395770071167704'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/04/bash-array-size.html' title='bash array size'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-3208837484908495982</id><published>2010-04-15T16:09:00.001-07:00</published><updated>2010-04-15T16:19:25.908-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Java: Heap Dump on OutOfMemoryError</title><content type='html'>You can request the jvm create a heap dump when an OutOfMemoryError is thrown.  This is handy if you have a process that consumes a ton of RAM and you don't know why.  Set the max heap size to something around 500M (or less.  It needs to be fairly small if you're going to inspect the heap with 'jhat'). Use the -XX:+HeapDumpOnOutOfMemoryError flag to request the heap dump. This will output to java_pid&lt;pid&gt;.hprof by default.  You can set the output filename manually using -XX:HeapDumpPath=&amp;lt;filename&amp;gt;.&lt;br /&gt;&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&gt; java -Xmx100m -XX:+HeapDumpOnOutOfMemoryError -XX:HeadDumpPath=/tmp/dump.hprof com.geekbraindump.MyMemoryHoggingClass&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-3208837484908495982?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/3208837484908495982/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/04/java-heap-dump-on-outofmemoryerror.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3208837484908495982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3208837484908495982'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/04/java-heap-dump-on-outofmemoryerror.html' title='Java: Heap Dump on OutOfMemoryError'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-8525073214488539431</id><published>2010-03-23T10:07:00.000-07:00</published><updated>2010-04-15T16:19:44.904-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='utils'/><title type='text'>Linux: command line cut and paste</title><content type='html'>It's always annoyed me that I have to open up a file in order to cut and paste the contents into a web browser (I use this a lot for capturing information on an internal wiki).  As of 2010-03-23 there are no default command line access utilities for this (on CentOs anyway).&lt;br /&gt;&lt;br /&gt;However, download and install &lt;a href="http://sourceforge.net/projects/xclip/"&gt;xclip &lt;/a&gt;and the clipboard is yours to command.&lt;br /&gt;&lt;br /&gt;xclip allows access to both the PRIMARY (middle mouse button) and SECONDARY (standard copy/paste) selections.&lt;br /&gt;&lt;br /&gt;By default piping into xclip puts the text in the PRIMARY clipboard (middle mousebutton).&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&gt; echo $RANDOM | xclip&lt;br /&gt;&gt; xclip -o&lt;br /&gt;4807&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can define which selection to input to.  Say you want to store text in the SECONDARY selection (accessed using standard cut and paste commands):&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&gt; echo $RANDOM | xclip -sel 'clipboard'&lt;br /&gt;&gt; xclip -o -sel 'clipboard'&lt;br /&gt;4807&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can now use edit-&gt;paste to output the text.  Note that the random number was the same as before.  I guess this is some shell caching mechanism.  For a new random number each time you have to use a new shell:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&gt; (echo $RANDOM) | cat&lt;br /&gt;1297&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-8525073214488539431?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/8525073214488539431/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/03/linux-command-line-cut-and-paste.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8525073214488539431'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8525073214488539431'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/03/linux-command-line-cut-and-paste.html' title='Linux: command line cut and paste'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-3202524771940713628</id><published>2010-02-28T23:58:00.000-08:00</published><updated>2010-03-01T00:05:42.978-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='avr'/><category scheme='http://www.blogger.com/atom/ns#' term='c'/><title type='text'>AVR: storing a 2d array in PROGMEM</title><content type='html'>I've just been fangling with a UV Painter project (row of LEDs to 'paint' on a glow-in-the-dark-wall).  I quickly ran out of RAM when adding patterns to the system and learned how to add variables to the Flash program memory instead.  Pretty simple and very useful:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:c"&gt;&lt;br /&gt;#include &amp;lt;avr/pgmspace.h&amp;gt;&lt;br /&gt;&lt;br /&gt;const uint8_t mCylonScan[10][N_LED] PROGMEM = {&lt;br /&gt;  {255,0,0,0,0,0},&lt;br /&gt;  {0,255,0,0,0,0},&lt;br /&gt;  {0,0,255,0,0,0},&lt;br /&gt;  {0,0,0,255,0,0},&lt;br /&gt;  {0,0,0,0,255,0},&lt;br /&gt;  {0,0,0,0,0,255},&lt;br /&gt;  {0,0,0,0,255,0},&lt;br /&gt;  {0,0,0,255,0,0},&lt;br /&gt;  {0,0,255,0,0,0},&lt;br /&gt;  {0,255,0,0,0,0}&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then to access the data you just do the following (where 'i' and 'j' are loop variables):&lt;br /&gt;&lt;pre class="brush:c"&gt;&lt;br /&gt;data = pgm_read_byte(&amp;(mCylonScan[i][j]));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://www.nongnu.org/avr-libc/user-manual/pgmspace.html"&gt;AVR libc docs&lt;/a&gt; for more details.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-3202524771940713628?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/3202524771940713628/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/02/avr-storing-2d-array-in-progmem.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3202524771940713628'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3202524771940713628'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/02/avr-storing-2d-array-in-progmem.html' title='AVR: storing a 2d array in PROGMEM'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-7941671241542216963</id><published>2010-02-26T15:34:00.000-08:00</published><updated>2010-03-01T00:05:51.430-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Manipulating Bash Strings</title><content type='html'>I'm finding myself looking these up quite a lot, so here's a little cheat sheet of the basics.&lt;br /&gt;&lt;br /&gt;Using the string "ABCDEFG12345" as an example:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; string="ABCDEFG12345"&lt;br /&gt;&amp;gt; echo $string&lt;br /&gt;ABCDEFG12345&lt;br /&gt;&lt;br /&gt;&amp;gt; #Replacement:&lt;br /&gt;&amp;gt; echo ${string/ABC/___}&lt;br /&gt;___DEFG12345&lt;br /&gt;&lt;br /&gt;&amp;gt; #Replacement with character class&lt;br /&gt;&amp;gt; echo ${string/[ABC4]/_}&lt;br /&gt;_BCDEFG12345&lt;br /&gt;&lt;br /&gt;&amp;gt; #Replace all occurrences:&lt;br /&gt;&amp;gt; echo ${string//[ABC4]/_}&lt;br /&gt;___DEFG123_5&lt;br /&gt;&lt;br /&gt;&amp;gt; #Extract from a defined position in the string&lt;br /&gt;&amp;gt; echo ${string:7}&lt;br /&gt;12345&lt;br /&gt;&amp;gt; echo ${string:7:3}&lt;br /&gt;123&lt;br /&gt;&lt;br /&gt;&amp;gt; #substring removal (from the front of the string)&lt;br /&gt;&amp;gt; echo ${string#ABC}&lt;br /&gt;DEFG12345&lt;br /&gt;&amp;gt; echo ${string##ABC} #strips the longest substring match&lt;br /&gt;DEFG12345&lt;br /&gt;&amp;gt; string2="abcABCabc123ABCabc&lt;br /&gt;&amp;gt; echo ${string2#a*C}&lt;br /&gt;abc123ABCabc&lt;br /&gt;&amp;gt; echo ${string2##a*C}&lt;br /&gt;abc&lt;br /&gt;&amp;gt; # use the % sign to match from the end &lt;br /&gt;&amp;gt; # % for shortest and %% for longest substring match&lt;br /&gt;&amp;gt; echo ${string%45}&lt;br /&gt;ABCDEFG123&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-7941671241542216963?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/7941671241542216963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/02/manipulating-bash-strings.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7941671241542216963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7941671241542216963'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/02/manipulating-bash-strings.html' title='Manipulating Bash Strings'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-7129929232237330069</id><published>2010-02-11T10:52:00.000-08:00</published><updated>2011-10-25T11:24:25.936-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bioinformatics'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Use csplit to split SDF files (or contextually split any file)</title><content type='html'>Say you want to split an SDF into individual entities, you could write a Perl script/one-liner (which is what I've been doing for a long time) or you could just use csplit.  Thanks to Pat and Jessen for pointing this one out.&lt;br /&gt;&lt;br /&gt;e.g. say you had an SDF, test_mols.sdf, with 8 molecules in it and you wanted individual mol files:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&amp;gt; csplit -kzsf "test_mols" -b %0d.mol test_mols.sdf /\$\$\$\$/+1 {*}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This would result in 8 files called test_mols00.mol through test_mols07.mol.  Unfortunately these would still contain the SDF delimiter at the end of the file (so, technically these are still SDFs).  That's pretty easy to clean up with something like:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:perl"&gt;&amp;gt; perl -ni -e 'print unless /\$\$\$\$/' *.mol&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://www.manpagez.com/man/1/csplit/"&gt;csplit manpage&lt;/a&gt; for more details.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-7129929232237330069?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/7129929232237330069/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/02/use-csplit-to-split-sdf-files-or.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7129929232237330069'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7129929232237330069'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/02/use-csplit-to-split-sdf-files-or.html' title='Use csplit to split SDF files (or contextually split any file)'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-1087772487191759301</id><published>2010-02-02T14:31:00.001-08:00</published><updated>2010-02-02T14:33:57.056-08:00</updated><title type='text'>autolinkification in bugzilla</title><content type='html'>I often refer to other bugs in a Bugzilla comment.  These are 'autolinkified' by bugzilla.  I've only just learned that you can refer to a comment in a bug as well and have this 'autolinkified'.&lt;br /&gt;&lt;br /&gt;See the Bugzilla &lt;a href="http://www.bugzilla.org/docs/3.2/en/html/hintsandtips.html"&gt;hintandtips &lt;/a&gt;page.&lt;br /&gt;&lt;br /&gt;Short answer:&lt;br /&gt;&lt;br /&gt;Bug autolink:" bug 1234"&lt;br /&gt;Comment autolink:"bug 1234, comment 12"&lt;br /&gt;attachment: autolink" bug 1234, attachment 4"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-1087772487191759301?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/1087772487191759301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/02/autolinkification-in-bugzilla.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1087772487191759301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1087772487191759301'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/02/autolinkification-in-bugzilla.html' title='autolinkification in bugzilla'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-9156891616868623402</id><published>2010-01-29T11:39:00.000-08:00</published><updated>2010-01-29T11:50:02.095-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Regular expressions in bash</title><content type='html'>You can perform regular expression matching on a variable within an extended test command (see the &lt;a href="http://www.gnu.org/software/bash/manual/bashref.html#Conditional-Constructs"&gt;Conditional Constructs&lt;/a&gt; part of the bash manual).&lt;br /&gt;&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;prompt&amp;gt; name=foobar.blarg;if [[ $name =~ foo ]]; echo yep; else echo nope; fi&lt;br /&gt;yep&lt;br /&gt;prompt&amp;gt; name=foobar.blarg;if [[ $name =~ foo[a-c] ]]; echo yep; else echo nope; fi&lt;br /&gt;yep&lt;br /&gt;prompt&amp;gt; name=foobar.blarg;if [[ $name =~ foo[d-z] ]]; echo yep; else echo nope; fi&lt;br /&gt;nope&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-9156891616868623402?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/9156891616868623402/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/regular-expressions-in-bash.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/9156891616868623402'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/9156891616868623402'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/regular-expressions-in-bash.html' title='Regular expressions in bash'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-5804499215922917481</id><published>2010-01-26T16:04:00.001-08:00</published><updated>2010-01-26T16:14:36.145-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Perl'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Convert tab data into HTML tables with a Perl one-liner</title><content type='html'>Quick one-liner for generating a HTML table from tab delimited input.  Either pipe in your data or include the file as a command line argument.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:perl"&gt;&lt;br /&gt;perl -F'\t' -lane 'BEGIN{print "&amp;lt;table border=1 cellpadding=3 cellspacing=0&amp;gt;"}print "&amp;lt;tr&amp;gt;", (map {"&amp;lt;td&amp;gt;$_&amp;lt;/td&amp;gt;"} @F), "&amp;lt;/tr&amp;gt;";END{print "&amp;lt;/table&amp;gt;}'&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The map is in parentheses so that the closing '&amp;lt;tr&amp;gt;' tag is not slurped in as part of it's input array.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-5804499215922917481?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/5804499215922917481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/convert-tab-data-into-html-tables-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5804499215922917481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5804499215922917481'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/convert-tab-data-into-html-tables-with.html' title='Convert tab data into HTML tables with a Perl one-liner'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-3836458614121736725</id><published>2010-01-16T09:51:00.000-08:00</published><updated>2010-01-25T14:39:10.479-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='avr'/><title type='text'>Setting AVR Clock Speed</title><content type='html'>I'm using gcc/WinAVR to program my AVRs and have just been discovering how to program the clock speed.  I'm playing with an ATtiny13 and an ATmega8.  Both of these ship with their clocks set to 1MHz by default but both can be clocked to a higher speed.&lt;br /&gt;&lt;br /&gt;There are a few things to note:&lt;br /&gt;&lt;br /&gt;1. F_CPU is used by the compiler for calculating timings (most obvious example is in the delay.h routines).  Setting it has no effect on the &lt;span style="font-weight:bold;"&gt;actual&lt;/span&gt; clock speed.  This needs to be set to the correct value.&lt;br /&gt;&lt;br /&gt;2. Easiest way (for me) to set the clock speed is to program the relevant fuse bits.  This was different for the two chips I've been using - ATtiny13 and ATmega8).  &lt;span style="font-weight:bold;"&gt;Note&lt;/span&gt;: for fuse bits 1 = unprogrammed and 0 = programmed (this is due to the nature of EEPROM).&lt;br /&gt;&lt;br /&gt;This step is made easy when using the Eclipse avr plugin.  There's a GUI/wizard for setting them in Project-&gt;Properties-&gt;AVR-&gt;AVRDude-&gt;Fuses.  Accessible by selecting the "direct hex values" radio option and then clicking the "start editor" button.&lt;br /&gt;&lt;br /&gt;3. For some MCUs you can dynamically adjust the clock speed in software (I know this is true for the ATtiny13 at least).  However, this has to be done within 4 clock cycles of setting the CLKPCE bit (again, this is for the Atiny13).  See &lt;a href="http://www.avrfreaks.net/index.php?name=PNphpBB2&amp;file=printview&amp;t=74431&amp;start=0"&gt;this forum post&lt;/a&gt; on avrfreaks.net and pg.28 of the datasheet.&lt;br /&gt;&lt;br /&gt;Here's a good overview of setting the clock for the ATmega8: &lt;a href="http://electrons.psychogenic.com/modules/arms/art/14/AVRFusesHOWTOGuide.php"&gt;Electrons - AVR Fuses HOWTO Guide&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-3836458614121736725?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/3836458614121736725/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/setting-avr-clock-speed.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3836458614121736725'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3836458614121736725'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/setting-avr-clock-speed.html' title='Setting AVR Clock Speed'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-8035706965176692591</id><published>2010-01-12T14:36:00.000-08:00</published><updated>2010-01-14T13:54:25.280-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Bash: reading lines from a file</title><content type='html'>I guess I don't do this enough to remember it:&lt;br /&gt;&lt;br /&gt;When reading a file in a for loop in bash, the following idiom will read each work (whitespace delimited):&lt;br /&gt;&lt;pre class="brush:bash"&gt;for word in `cat file.txt`; do echo $word; done&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If you want to grab the whole line then you can do this:&lt;br /&gt;&lt;pre class="brush:bash"&gt;while read line; do echo $line; done &amp;lt; file.txt&lt;/pre&gt;&lt;br /&gt;or&lt;br /&gt;&lt;pre class="brush:bash"&gt;cat file.txt | while read line; do echo $line; done&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-8035706965176692591?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/8035706965176692591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/bash-reading-lines-from-file.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8035706965176692591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8035706965176692591'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/bash-reading-lines-from-file.html' title='Bash: reading lines from a file'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-9205799318961021224</id><published>2010-01-08T10:48:00.001-08:00</published><updated>2010-01-08T11:00:09.025-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Essential Eclipse Keyboard Shortcuts (navigation)</title><content type='html'>There are a few shortcuts I use all the time for navigating in Eclipse and I've just learned a few more useful ones (I was looking for quick ways to jump between editor windows).&lt;br /&gt;&lt;br /&gt;Here's the essential list (IMO):&lt;br /&gt;&lt;br /&gt;Ctrl+E (go to other open editors - opens selection box)&lt;br /&gt;Ctrl+Q (jump to last edit location)&lt;br /&gt;Crtl+O (jump to any member/method/inner-class in the current editor)&lt;br /&gt;Ctrl+shift+T (open any type)&lt;br /&gt;Ctrl+shift+R (open any file)&lt;br /&gt;Ctrl+L (jump to a particular line number)&lt;br /&gt;Ctrl+T (go to a supertype/subtype - multiple presses toggle between super/sub)&lt;br /&gt;Alt+left/right arrow (jump through visited files)&lt;br /&gt;Ctrl+. Ctrl+, (navigate up and down through error/warning locations)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-9205799318961021224?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/9205799318961021224/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/essential-eclipse-keyboard-shortcuts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/9205799318961021224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/9205799318961021224'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/essential-eclipse-keyboard-shortcuts.html' title='Essential Eclipse Keyboard Shortcuts (navigation)'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-8910459082250911408</id><published>2010-01-03T22:34:00.000-08:00</published><updated>2010-01-08T11:00:31.131-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='c'/><title type='text'>C rand() and random() functions</title><content type='html'>There are two primary random functions to be aware of in stdlib.h: random() and rand() the main difference is in the range of values returned by the two functions.&lt;br /&gt;&lt;br /&gt;random() returns a pseudo random number in the range 0 -&gt; 0x7FFFFFFF = 0 -&gt; 1,879,098,192 (RANDOM_MAX).&lt;br /&gt;rand() returns values in the range 0 -&gt; 0x7FFF = 0 -&gt; 28,672 (RAND_MAX).&lt;br /&gt;&lt;br /&gt;I had mistakenly been using one in place of the other in some micro-controller code and had spent some time wondering why it wasn't behaving as expected...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-8910459082250911408?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/8910459082250911408/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/c-rand-and-random-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8910459082250911408'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8910459082250911408'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2010/01/c-rand-and-random-functions.html' title='C rand() and random() functions'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-4307383190137931155</id><published>2009-12-24T10:26:00.001-08:00</published><updated>2010-05-06T13:46:20.019-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='windows'/><title type='text'>updating windows vista file permissions with Icacls</title><content type='html'>I'm not much of a windows guy, but I have a vista machine at home as the main PC.  I recently bought a NAS to backup important files and found that my backup jobs were failing due to file permission issues (there are multiple accounts on the PC).  I wanted to do the equivalent of chmod +r (or even 777) on a few files but didn't want the hassle of using windows explorer to adjust the file perms one at a time (I'd already tried changing permissions for the root folder and applying these to the contained files and sub-dirs, but it didn't work.  I guess it was something to do with the fact that the permissions weren't uniform for the files in the dirs).&lt;br /&gt;&lt;br /&gt;Anyway, it seems you use Icacls for updating file permissions and you can do it recursively with the /T flag.  So for a single file you do this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; Icacls &amp;lt;filename&amp;gt; /grant &amp;lt;user&amp;gt;:&amp;lt;perm&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;e.g.  This grants full control to user 'Paul' on file 'test.txt'&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;c:\&amp;gt; Icacls test.txt /grant Paul:F&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;and for a dir you do this:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;c:\Icacls &amp;lt;dirname&amp;gt; /T /grant &amp;lt;user&amp;gt;:&amp;lt;perm&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;c:\&amp;gt; Icacls c:\testdir /grant Paul:F&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-4307383190137931155?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/4307383190137931155/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/12/updating-windows-vista-file-permissions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4307383190137931155'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4307383190137931155'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/12/updating-windows-vista-file-permissions.html' title='updating windows vista file permissions with Icacls'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-2130569994945093008</id><published>2009-12-21T11:11:00.001-08:00</published><updated>2009-12-21T11:27:30.908-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><title type='text'>Mysql multiple counts on one line (reports)</title><content type='html'>I like to poll the contents of multiple tables over time in order to track the progress of certain processing tasks I do.  I used to perform individual counts for each table and kept doing that out of habit.  There's a much nicer way to do this and have the report in a single result.  I tend to keep track of the elapsed time using the unix_timestamp() function (this returns the number of elapsed seconds since Jan 1st 1970 as an unsigned integer).&lt;br /&gt;&lt;br /&gt;First set up the initial variables (those to compare against - this is time 0)&lt;br /&gt;&lt;pre class="brush:sql"&gt;&lt;br /&gt;PaulBo@test_db:SELECT @time:=UNIX_TIMESTAMP(), @apples:=(SELECT COUNT(*) FROM apples), @oranges:=(SELECT COUNT(*) FROM oranges);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then, let some time pass and poll the tables for changes:&lt;br /&gt;&lt;pre class="brush:sql"&gt;&lt;br /&gt;PaulBo@test_db:SELECT UNIX_TIMESTAMP() - @time as elapsed_time, (SELECT COUNT(*) FROM apples) - @apples as d_apples, (SELECT COUNT(*) FROM oranges) - @oranges as d_oranges;&lt;br /&gt;+--------------+----------+-----------+&lt;br /&gt;| elapsed_time | d_apples | d_oranges |&lt;br /&gt;+--------------+----------+-----------+&lt;br /&gt;|          435 |      230 |     12887 |&lt;br /&gt;+--------------+----------+-----------+&lt;br /&gt;1 row in 1 set (0.00 sec)&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-2130569994945093008?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/2130569994945093008/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/12/mysql-multiple-counts-on-one-line.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2130569994945093008'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2130569994945093008'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/12/mysql-multiple-counts-on-one-line.html' title='Mysql multiple counts on one line (reports)'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-560819057240741004</id><published>2009-12-11T11:23:00.000-08:00</published><updated>2009-12-11T11:34:16.025-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Redirecting the output from a "here document"</title><content type='html'>This had me confused for a few minutes, so I thought I'd post.&lt;br /&gt;&lt;br /&gt;It's common to use "here documents" to simplify input to a program in a script. &lt;br /&gt;&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; cat &amp;lt;&amp;lt;EOF&lt;br /&gt;&amp;gt; This is a random number:&lt;br /&gt;&amp;gt; $RANDOM&lt;br /&gt;&amp;gt; EOF&lt;br /&gt;This is a random number:&lt;br /&gt;9948&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But what if you want to capture the output of this?  The naive attempt would be to redirect after the second EOF, but this is incorrect as the termination string has to be on a line all by itself.&lt;br /&gt;&lt;br /&gt;This is the answer:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; cat &amp;lt;&amp;lt;EOF &amp;gt; /tmp/data.txt&lt;br /&gt;&amp;gt; This is a random number:&lt;br /&gt;&amp;gt; $RANDOM&lt;br /&gt;&amp;gt; EOF&lt;br /&gt;&amp;gt; cat /tmp/data.txt&lt;br /&gt;This is a random number:&lt;br /&gt;24669&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-560819057240741004?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/560819057240741004/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/12/redirecting-output-from-here-document.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/560819057240741004'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/560819057240741004'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/12/redirecting-output-from-here-document.html' title='Redirecting the output from a &quot;here document&quot;'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-6243032520183510511</id><published>2009-12-11T10:22:00.000-08:00</published><updated>2009-12-11T10:43:16.135-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='R'/><title type='text'>samples from large datasets in R</title><content type='html'>I have a dataset I want to plot (say 5,000,000 data-points).  This can be very slow to plot in R, so you want to take a sample of this data instead.  &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Say I have a tab delimited file with two columns, say 'time' and 'count'.  The columns have these as headers.  There are 5M rows and I'd like a simple overview of the count over time.&lt;/div&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;&amp;gt; data = read.delim('filename', header=T) #read in the tsv (tab separated value) data file&lt;br /&gt;&amp;gt; s = length(data$time) # calculate the number of data-points&lt;br /&gt;&amp;gt; n = 1000 # this is my sample size&lt;br /&gt;&amp;gt; N = sort(sample(1:s, n)) #create a set of indices sampled from the vector 1:s&lt;br /&gt;&amp;gt; plot(data$time[N], data$count[N]) # use the indices to sample from the set&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The magic is in the &lt;code&gt;sort(sample(1:s, n))&lt;/code&gt;.  This takes n samples from the space 1 -&gt; s.  Unless a probability vector is provided, each element in the input vector (1:s) has an equal probability of being selected.  We sort the output of sample so that the indices are in the correct order to plot.  Actually I just tried this without the sort and it seems the &lt;code&gt;plot()&lt;/code&gt; function sorts the input vectors anyway.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-6243032520183510511?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/6243032520183510511/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/12/samples-from-large-datasets-in-r.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/6243032520183510511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/6243032520183510511'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/12/samples-from-large-datasets-in-r.html' title='samples from large datasets in R'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-4084028064516546149</id><published>2009-12-03T15:21:00.000-08:00</published><updated>2009-12-11T10:20:54.410-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Infinite loop in bash</title><content type='html'>I needed an infinite loop for polling a database table for a while (killed with Ctrl-C).&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;while [ 1 ];&lt;br /&gt; do mysql -u paul -h test_database -ppass test_paul data_table &lt;&lt;&lt; "show processlist";&lt;br /&gt; sleep 10;&lt;br /&gt;done&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-4084028064516546149?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/4084028064516546149/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/12/infinite-loop-in-bash.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4084028064516546149'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4084028064516546149'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/12/infinite-loop-in-bash.html' title='Infinite loop in bash'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-2600067621310342034</id><published>2009-11-20T09:15:00.001-08:00</published><updated>2009-12-11T10:20:37.603-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Visual Diff</title><content type='html'>I just came across 'kompare'.  It's a great way to track minor differences between plain text files.  Very pretty, side-by-side, visualization of the changes.&lt;br /&gt;&lt;br /&gt;The display uses 3 colours:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Green - new text on the left&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Blue - new text on the right&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Red - changed text/area&lt;/li&gt;&lt;/ol&gt;See the &lt;a href="http://en.wikipedia.org/wiki/Kompare"&gt;wikipedia &lt;/a&gt;page for more details.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://upload.wikimedia.org/wikipedia/commons/b/b0/Kompare.png"&gt;&lt;img style="cursor: pointer; width: 200px; height: 100px;" src="http://upload.wikimedia.org/wikipedia/commons/b/b0/Kompare.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-2600067621310342034?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/2600067621310342034/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/11/visual-diff.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2600067621310342034'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2600067621310342034'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/11/visual-diff.html' title='Visual Diff'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-4591298512308239001</id><published>2009-10-23T11:35:00.000-07:00</published><updated>2009-11-05T14:01:15.600-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Using curl to POST data</title><content type='html'>I wanted to automate some load testing at work, this required sending some post requests to a running server in order to increase the amount of 'work' being done.  I wanted to use 'curl' as it's a linux command line app and so very easy to incorporate in a script.&lt;br /&gt;&lt;br /&gt;Anyway, this is how you post data with curl:&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;curl -d "param1=value1&amp;param2=value2" http://myhost.com/server.cgi&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-4591298512308239001?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/4591298512308239001/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/10/using-curl-to-post-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4591298512308239001'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4591298512308239001'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/10/using-curl-to-post-data.html' title='Using curl to POST data'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-8180391196002124784</id><published>2009-10-02T10:54:00.001-07:00</published><updated>2009-11-05T14:01:00.971-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><title type='text'>Inserting binary values in the mysql shell</title><content type='html'>I needed to insert some dummy values into a table which had a bit field as well as a blob field, both of which are "NOT NULL".  You just need to have the 'b' prefix on the data, like so:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:sql"&gt;&lt;br /&gt;INSERT INTO faketable(blob1, name, bitfield) values(b'001011101', "Beeblebrox", b'1');&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can also print out the binary data in a way that's not going to ruin your terminal using the BIN(), OCT() and HEX() functions:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:sql"&gt;&lt;br /&gt;SELECT name, HEX(blob1), BIN(bitfield) from faketable;&lt;br /&gt;+--------------------+--------------+----------------+&lt;br /&gt;| name               | HEX(blob1) | BIN(bitfield) |&lt;br /&gt;+--------------------+--------------+----------------+&lt;br /&gt;| Beeblebrox         | 005D         | 1              | &lt;br /&gt;+--------------------+--------------+----------------+&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-8180391196002124784?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/8180391196002124784/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/10/inserting-binary-values-in-mysql-shell.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8180391196002124784'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8180391196002124784'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/10/inserting-binary-values-in-mysql-shell.html' title='Inserting binary values in the mysql shell'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-2674636276519211061</id><published>2009-09-14T17:03:00.001-07:00</published><updated>2009-09-15T16:41:53.365-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='R'/><title type='text'>R - percentiles</title><content type='html'>I just needed to find some percentile thresholds and thought that it'd be easy with R.  Well, it is!&lt;br /&gt;&lt;br /&gt;So, load the data&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;data = seq(0,1,0.01);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then you can get quantiles like so:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;quantile(data);&lt;br /&gt;&lt;br /&gt;   0%  25%  50%  75% 100%&lt;br /&gt;0.00 0.25 0.50 0.75 1.00&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;and percentiles by using the vector argument to quantile (in this case I'm looking at the 0th to 1st percentile):&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;   0%  0.1%  0.2%  0.3%  0.4%  0.5%  0.6%  0.7%  0.8%  0.9%    1%&lt;br /&gt;0.000 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.010&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-2674636276519211061?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/2674636276519211061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/09/r-percentiles.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2674636276519211061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/2674636276519211061'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/09/r-percentiles.html' title='R - percentiles'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-1161922147450208598</id><published>2009-09-11T09:13:00.000-07:00</published><updated>2009-09-15T16:41:59.160-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>screen</title><content type='html'>Ever lost a terminal which had an active job running?  Ever wanted to check in on what you'd been doing from home *and* wanted or needed the session history as well?&lt;br /&gt;&lt;br /&gt;'screen' is your friend.  If you're starting work that's important or that you may want to check from another machine it's a real time-saver.  Have a look at the &lt;a href="http://linux.die.net/man/1/screen"&gt;man page&lt;/a&gt; for more details than you can shake a stick at.&lt;br /&gt;&lt;br /&gt;I've only been using it for a little while, so the only caveat I've found so far is that I have to remember to give the sessions a reasonable name before I start them.  Otherwise, if you've got a lot of sessions, it's a time waster trying to find the right one.  The '-t' flag sets the title for the default shell; more importantly the '-S' flag sets the session title.  I've been using the same string for both (will probably set up an alias to deal with the duplication soon).&lt;br /&gt;&lt;br /&gt;e.g. &lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;shell1&amp;gt; screen -t data_loading -S data_loading&lt;br /&gt;shell2&amp;gt; screen -ls&lt;br /&gt;There are screens on:&lt;br /&gt;        21802.data_loading    (Attached)&lt;br /&gt;        20237.pts-10.hamilton   (Attached)&lt;br /&gt;        1376.variance_analysis  (Attached)&lt;br /&gt;        6639.pts-8.hamilton     (Attached)&lt;br /&gt;        9881.cluster_jobs        (Attached)&lt;br /&gt;5 Sockets in /var/run/screen/S-paul.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You can see from the above listing that there are 5 sessions (all currently attached).  There are two listings there with no session title and I have no idea what I'm doing in them... but for the other three it's obvious (at least to me).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-1161922147450208598?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/1161922147450208598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/09/screen.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1161922147450208598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1161922147450208598'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/09/screen.html' title='screen'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-7767605998627969800</id><published>2009-08-31T11:10:00.001-07:00</published><updated>2010-05-06T13:45:55.965-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='blogging'/><title type='text'>Code formatting for blogger</title><content type='html'>I've been meaning to look into this for a while.  I'd like to be able to insert nicely formatted code into posts.&lt;br /&gt;&lt;br /&gt;I found the follwing blog post - &lt;a href="http://codeblog.kello.se/2009/01/07/getting-code-formatting-with-syntax-highlighting-to-work-on-blogger/"&gt;getting-code-formatting-with-syntax-highlighting-to-work-on-blogger&lt;/a&gt; and figured I'd give it a try.&lt;br /&gt;&lt;br /&gt;Unfortunately following the instructions in the above post didn't work for me and I had to waste some time on the project site to find out what to do.  This post on &lt;a href="http://www.puffyandmishu.com/article.php?id=33"&gt;puffyandmishu &lt;/a&gt;was very helpful.  I ended up with the following code in my blogger template:&lt;br /&gt;&lt;br /&gt;1. In the &amp;lt;head&amp;gt; tag:&lt;br /&gt;&lt;pre class="brush:js"&gt;&lt;br /&gt;&amp;lt;script language='javascript' src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js'/&amp;gt;  &lt;br /&gt;&amp;lt;script language='javascript' src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js'/&amp;gt;&lt;br /&gt;&amp;lt;script language='javascript' src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js'/&amp;gt;  &lt;br /&gt;&amp;lt;script language='javascript' src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js'/&amp;gt;&lt;br /&gt;&amp;lt;script language='javascript' src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js'/&amp;gt;&lt;br /&gt;&amp;lt;script language='javascript' src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js'/&amp;gt;&lt;br /&gt;&amp;lt;link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/&amp;gt;&lt;br /&gt;&amp;lt;link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;2. at the bottom of the &amp;lt;body&amp;gt; tag:&lt;br /&gt;&lt;pre class="brush:js"&gt;&lt;br /&gt;&amp;lt;script language='javascript'&amp;gt;  &lt;br /&gt;SyntaxHighlighter.config.bloggerMode = true;&lt;br /&gt;SyntaxHighlighter.all()  &lt;br /&gt;&amp;lt;/script&amp;gt;  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Let's test it out:&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;C - &amp;lt;pre class="brush:c"&amp;gt;&lt;/h3&gt;&lt;br /&gt;&lt;pre name='code' class="brush:c"&gt;&lt;br /&gt;int main(void)&lt;br /&gt;{&lt;br /&gt;    uint8_t i = 0;&lt;br /&gt;    char c = 'a';&lt;br /&gt;    while(1)&lt;br /&gt;    {&lt;br /&gt;        i++;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;h3&gt;Bash - &amp;lt;pre class="brush:bash"&amp;gt;&lt;/h3&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;for i in `ls *.c`;&lt;br /&gt;  do echo $i;&lt;br /&gt;done&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;h3&gt;Sql - &amp;lt;pre class="brush:sql"&amp;gt;&lt;/h3&gt;&lt;br /&gt;&lt;pre class="brush:sql"&gt;&lt;br /&gt;SELECT name FROM mydb.test_table WHERE id IN (1,2,3,4,5);&lt;br /&gt;INSERT INTO mydb.test_table VALUES(1) WHERE name = "test";&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;h3&gt;Java - &amp;lt;pre class="brush:java"&amp;gt;&lt;/h3&gt;&lt;br /&gt;&lt;pre class="brush:java"&gt;&lt;br /&gt;private static final class MyClass extends YourClass implements Cloneable&lt;br /&gt;{&lt;br /&gt;    public int mMyInt = 145;&lt;br /&gt;    private String mString = "blarg";&lt;br /&gt;    protected double mDouble = 23.45;&lt;br /&gt;&lt;br /&gt;    public void main(String[] pArgs) throws Exception&lt;br /&gt;    {&lt;br /&gt;        System.out.println("Hi there");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;h3&gt;Perl - &amp;lt;pre class="brush:perl"&amp;gt;&lt;/h3&gt;&lt;br /&gt;&lt;pre class="brush:perl"&gt;&lt;br /&gt;use warnings;&lt;br /&gt;use strict;&lt;br /&gt;&lt;br /&gt;my $i = 10;&lt;br /&gt;for my $j (0 .. $i)&lt;br /&gt;{&lt;br /&gt;    print "This is line $j.  How lovely!\n";&lt;br /&gt;}&lt;br /&gt;warn "this does nothing.";&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Line wrapping off &amp;lt;pre class="brush: plain; wrap-lines: false"&amp;gt;&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: plain; wrap-lines: false"&gt;&lt;br /&gt;This is an example of a long line that shouldn't wrap.  Dwi eisio ddweud rhiwbeth yn Cymraeg ond dwi wedi anghofio popeth.  How long can we make these bars?&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now lets try it with Perl.&lt;br /&gt;&lt;pre class="brush: perl; wrap-lines: false"&gt;&lt;br /&gt;perl -F'\t' -lane 'print if $h{$F[0]}++;END{print "$_\t$h{$_}" for keys %h}' averyververververlongfilename.tsv&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-7767605998627969800?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/7767605998627969800/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/08/code-formatting-for-blogger.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7767605998627969800'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7767605998627969800'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/08/code-formatting-for-blogger.html' title='Code formatting for blogger'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-8468950442320901962</id><published>2009-08-21T23:43:00.001-07:00</published><updated>2009-08-31T11:18:21.682-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='avr'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>AVR delay_ms</title><content type='html'>When programming the AVR uC you have to remember that the delay_ms and delay_us functions will tie in the whole floating point library unless they are passed constants.  This will always make the code too bloated to fit in anything less that 3K.  So, it's right out for the ATtiny13 (1K Flash memory).  I've been bitten by this twice now and the incidences were far enough appart that it took me 45 mins the second time to trace what was going on...&lt;br /&gt;&lt;br /&gt;I was trying this:&lt;br /&gt;&lt;pre name="code" class="c"&gt;&lt;br /&gt;delay_ms(delay);&lt;br /&gt;if(i==0)&lt;br /&gt;delay--;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;but should have been increasing/decreasing the delay time by wrapping the delay call in a loop of variable length instead.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-8468950442320901962?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/8468950442320901962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/08/avr-delayms.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8468950442320901962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/8468950442320901962'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/08/avr-delayms.html' title='AVR delay_ms'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-4741511518034963187</id><published>2009-08-21T16:20:00.000-07:00</published><updated>2009-08-21T23:48:35.297-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='R'/><title type='text'>Legends in R plots</title><content type='html'>I've just spent about 45 mins trying to get a decent results plot from R.  I wanted to include a legend for clarity and this gave me some trouble.  It turns out the co-ordinate system was using values from the x and y plot rather than pixels... weird.  Happily, for simple plots, there's an easy way to position the legend.   From the R man page:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;The location may also be specified by setting 'x' to a single&lt;br /&gt;keyword from the list '"bottomright"', '"bottom"', '"bottomleft"',&lt;br /&gt;'"left"', '"topleft"', '"top"', '"topright"', '"right"' and&lt;br /&gt;'"center"'. This places the legend on the inside of the plot frame&lt;br /&gt;at the given location.&lt;/blockquote&gt;So, I ended up with something like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;R --vanilla --slave &lt;&lt;&lt;"d=read.table('data1.csv', sep=',', header=F);e=read.table('data2.csv', header=F, sep=',');png('results.png');dh=hist(d\$V2, plot=F);eh=hist(e\$V2, plot=F);xlim=range(dh\$mids, eh\$mids);ylim=range(dh\$counts, eh\$counts);plot(dh, main='', xlab='value', col='orange', xlim=xlim, ylim=ylim);plot(eh, col='lightblue', add=T);legend('topright', legend=c('label1', 'label2'), fill=c('orange', 'lightblue'));q()"&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Pre-calculating the range for the x and y axes (using the range operators) prevents you from cutting off data from one of the plots.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-4741511518034963187?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/4741511518034963187/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/08/legends-in-r.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4741511518034963187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/4741511518034963187'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/08/legends-in-r.html' title='Legends in R plots'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-7067094763303172250</id><published>2009-08-06T14:15:00.001-07:00</published><updated>2009-12-11T10:21:33.460-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>MySQL bash shell one-liners</title><content type='html'>This is a useful thing to know if you're ever trying to use data in files to grab data from a MySQL database:  You can feed in SQL query strings to the mysql client in the bash/shell standard way:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;bash&gt; mysql -u paul -h myhost -pmypass test_paul &lt;&lt;&lt; "SELECT id from a_table where a_name='boo-yah';" &lt;/pre&gt;&lt;br /&gt;Which means that you can put this in a shell script (or Perl script, or whatever).  For example, to print out the addresses associated with a set of names:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;for name in `cat names.list`;&lt;br /&gt;   do address=`mysql -u paul -h myhost -pmypass test_paul &amp;lt;&amp;lt;&amp;lt; "SELECT address from a_table where a_name='$name';"`;     echo "$name -&amp;gt; $address";&lt;br /&gt;   done&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-7067094763303172250?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/7067094763303172250/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/08/mysql-bash-shell-one-liners.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7067094763303172250'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7067094763303172250'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/08/mysql-bash-shell-one-liners.html' title='MySQL bash shell one-liners'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-9183833069114272770</id><published>2009-07-29T15:02:00.001-07:00</published><updated>2009-08-21T23:48:56.146-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Perl'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Perl subroutine references</title><content type='html'>I just found this useful for generating a dispatch/lookup table.  You can create a hash table with the values being references to subroutines.&lt;br /&gt;&lt;br /&gt;Here's a simple example:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;gt; perl -le '$a = sub { 5 * $_[0]};print &amp;amp;{$a}(23);'&lt;br /&gt;&amp;gt; 115&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;A better example is to use this as a look-up table.  Here's another simple example:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;%table = (&lt;br /&gt; "+" =&gt; sub { $_[0] + $_[1] },&lt;br /&gt; "-" =&gt; sub { $_[0] - $_[1] },&lt;br /&gt; "*" =&gt; sub { $_[0] * $_[1] },&lt;br /&gt; "/" =&gt; sub { $_[0] / $_[1] },&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;print &amp;amp;{$table{"+"}}(12,24), "\n";&lt;br /&gt;print &amp;amp;{$table{"-"}}(24,12)), "\n";&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This would output 36 and 12 respectively.  This is very handy for more complex processing and parsing (which is what I'm using it for).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-9183833069114272770?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/9183833069114272770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/07/perl-subroutine-references.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/9183833069114272770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/9183833069114272770'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/07/perl-subroutine-references.html' title='Perl subroutine references'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-1342030190097042945</id><published>2009-07-21T10:09:00.000-07:00</published><updated>2009-07-21T11:10:41.282-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='utils'/><title type='text'>Command line R</title><content type='html'>Sometimes I just want to print out a histogram from a file, or create a simple summary of some numeric data.  It's good to be able to just bash off an R script from the command line to do this for you.&lt;br /&gt;&lt;br /&gt;There are a couple of easy ways to invoke R to run in 'batch' mode (i.e. non-interactive):&lt;br /&gt;1. &lt;code&gt;R CMD BATCH &amp;lt;scriptname&amp;gt;&lt;/code&gt;&lt;br /&gt;2. &lt;code&gt;R --vanilla --slave &amp;lt;scriptname&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;For 1. the output is saved in a file named &amp;lt;scriptname&amp;gt;.Rout, in 2. the output comes to STDOUT - which, for me, is much more useful.&lt;br /&gt;&lt;br /&gt;Also, you can use the standard shell 'tricks' to create quick scripts without having to save a script file:&lt;br /&gt;&lt;br /&gt;e.g. &lt;br /&gt;&lt;br /&gt;1. Create a numeric summary of the input data (in this case for a file with the format - "name,value"):&lt;br /&gt;&lt;code&gt;&lt;br /&gt;R --vanilla --slave &lt;&lt;&lt; "d=read.table('data.scores', sep=',');summary(d);q()"&lt;br /&gt;       V1       &lt;br /&gt; Min.   :1.333  &lt;br /&gt; 1st Qu.:4.037  &lt;br /&gt; Median :4.651  &lt;br /&gt; Mean   :4.634  &lt;br /&gt; 3rd Qu.:5.282  &lt;br /&gt; Max.   :8.000  &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;2. Create a histogram for the data and save to a PNG (don't forget to escape any special shell characters).&lt;br /&gt;&lt;code&gt;&lt;br /&gt; R --vanilla --slave &lt;&lt;&lt; "d=read.table('data.scores', sep=',');png('data.png');hist(d\$V1);q()"&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-1342030190097042945?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/1342030190097042945/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/07/command-line-r.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1342030190097042945'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/1342030190097042945'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/07/command-line-r.html' title='Command line R'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-7456763609926212452</id><published>2009-07-16T16:14:00.001-07:00</published><updated>2009-07-16T16:14:13.726-07:00</updated><title type='text'></title><content type='html'>Never tried SMS blogging before... Worse than Twitter?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-7456763609926212452?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/7456763609926212452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/07/never-tried-sms-blogging-before.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7456763609926212452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7456763609926212452'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/07/never-tried-sms-blogging-before.html' title=''/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-5354634809235039657</id><published>2009-07-15T18:06:00.000-07:00</published><updated>2009-07-17T14:02:24.530-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='graphics'/><category scheme='http://www.blogger.com/atom/ns#' term='utils'/><title type='text'>converting postscript to an image</title><content type='html'>This is something I've meant to learn how to do for ages.  I needed to do this to produce summaries for a shit load of PDFs (containing related molecules) and wanted to have an image of a structure to represent each PDF.  Anyway, I print structures as postscript files, so I needed a way to create a PNG of the first structure for each PDF.&lt;br /&gt;&lt;br /&gt;I saw a few solutions on line which used ghostview to first output a jpeg and then 'mogrify' to cut down the hunormous result to something useful.  It turns out you can just do this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;convert molecule.ps -trim molecule.png&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This creates a png from the ps file.  Blimey!  Really simple!&lt;br /&gt;&lt;br /&gt;The -trim tag is a great addition as well, since a direct conversion results in a lot of extra whitespace.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-5354634809235039657?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/5354634809235039657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/07/converting-postscript-to-image.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5354634809235039657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5354634809235039657'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/07/converting-postscript-to-image.html' title='converting postscript to an image'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-3242740688109067279</id><published>2009-07-15T14:13:00.001-07:00</published><updated>2009-07-17T14:03:00.161-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Perl'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>running command line perl within a bash script</title><content type='html'>Maybe it's just me, but this is something I've struggled with on a couple of occasions.&lt;br /&gt;&lt;br /&gt;Since I can't give any of the examples I'm actually working on, I'll have to use something which is less obviously useful.&lt;br /&gt;&lt;br /&gt;The simple version is to use bash to loop through some files and use Perl to print out the filename (as stored by the bash script):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;for file in `ls *.label`;&lt;br /&gt;   do perl -le "\$a=1;print \"${file} \$a\"";&lt;br /&gt;done&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The important things to make this work are:&lt;br /&gt;1. The double quotes used for the Perl script.  This enables the variable interpretation by bash.&lt;br /&gt;2. Escape sequences for the double quotes used in the Perl script - the double quotes are necessary to make Perl interpret the Perl variables.&lt;br /&gt;3. Escape sequences for the Perl variables - this distinguishes the Perl variables from the bash ones.&lt;br /&gt;&lt;br /&gt;The final script I used was a lot more complicated than this and was used to generate a series of files.  I guess I can put the script in as, with no context, it has little meaning.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;for si in `seq 38 47`;&lt;br /&gt; do perl -F',' -lane "if(@F==4)&lt;br /&gt;   {&lt;br /&gt;      print \"\$F[0]\\t\$h{\$F[0]}:\$F[1],\$F[2]\"&lt;br /&gt;        if \$F[3] == $si and \!\$i{\$F[0]}++;&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      @F=split/\t/;&lt;br /&gt;      \$h{\$F[1]} = \$F[0];&lt;br /&gt;   }" file1 file2 &gt; output_${si}.tsv;&lt;br /&gt;done&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;It would have been nicer just to write a separate Perl script and call that, really.  But there you go.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-3242740688109067279?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/3242740688109067279/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/07/running-command-line-perl-within-bash.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3242740688109067279'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/3242740688109067279'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/07/running-command-line-perl-within-bash.html' title='running command line perl within a bash script'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-766676545388578155</id><published>2009-06-18T10:28:00.000-07:00</published><updated>2009-07-17T14:01:16.479-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>using find to catch up on what's changed</title><content type='html'>I came back from a two week vacation and needed to find out what had been updated/added/changed in that time in some shared project dirs.  "find" was my friend.  The following command gives a list of all files changed within the last two weeks.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;find . -ctime -14&lt;/pre&gt;'-ctime -14' will be true for all files/dirs that have been changed in the last 14*24 hours.  You can alter the behaviour by changing the modifier on the numerical input:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;+n     for greater than n,&lt;br /&gt;-n     for less than n,&lt;br /&gt; n     for exactly n.&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-766676545388578155?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/766676545388578155/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/06/using-find-to-catch-up-on-whats-changed.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/766676545388578155'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/766676545388578155'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/06/using-find-to-catch-up-on-whats-changed.html' title='using find to catch up on what&apos;s changed'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-7720851464044263183</id><published>2009-05-18T15:20:00.000-07:00</published><updated>2009-07-17T14:03:00.161-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='utils'/><title type='text'>jvisualvm instead of kill -3</title><content type='html'>Whenever I need to see what's going on under the hood of a process I issue a kill -3 to get a stack-trace.  Well, I was just introduced to &lt;a href="http://java.sun.com/javase/6/docs/technotes/tools/share/jvisualvm.html"&gt;jvisualvm&lt;/a&gt;!  This is a great way to see what's going on with a running java process.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-7720851464044263183?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/7720851464044263183/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/05/jvisualvm-instead-of-kill-3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7720851464044263183'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7720851464044263183'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/05/jvisualvm-instead-of-kill-3.html' title='jvisualvm instead of kill -3'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-6773857868979518914</id><published>2009-05-18T14:56:00.000-07:00</published><updated>2009-07-17T14:02:12.634-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><title type='text'>Changing the mysql prompt</title><content type='html'>This is such an obvious thing to do, why didn't I do it before?&lt;br /&gt;&lt;br /&gt;I'm constantly jumping into and between multiple databases as multiple users (test, standard, mysql) it becomes a little dangerous and I'm finding myself checking where I am and who I am:&lt;br /&gt;SELECT user();&lt;br /&gt;SELECT database();&lt;br /&gt;&lt;br /&gt;but you can change the standard mysql prompt to display the user and database!  Just edit the my.cnf file and place the following under [mysql]:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;prompt=\\u@\\d:&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now my prompt looks like this:&lt;br /&gt;paul@test:&lt;br /&gt;or&lt;br /&gt;root@main:&lt;br /&gt;&lt;br /&gt;If you don't have permissions to alter the my.cnf directly, then you could change your personal .bashrc (or equivalent) to contain something like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;alias mysql='mysql --prompt="\u@\d:"'&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This has saved me a lot of paranoia (and probably some headaches).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-6773857868979518914?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/6773857868979518914/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/05/changing-mysql-prompt.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/6773857868979518914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/6773857868979518914'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/05/changing-mysql-prompt.html' title='Changing the mysql prompt'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-9147496053056205161</id><published>2009-05-01T21:26:00.000-07:00</published><updated>2010-02-26T14:55:54.196-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>bash substring substitution</title><content type='html'>I just came across this today, it's something that I wish I'd known years ago (I think it just shows that I need to read more manuals), I've been emulating this feature with Perl and regexes or with the basename/dirname commands.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It's very simple; today I wanted to run through a set of files with a particular file extension, do some processing and then print the output to another file named the same as the original but with a different extension.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So, say the files are &lt;name&gt;.tsv (tab delimited) and I want to create a .csv (comma delimited) one from the first two columns, you can do it like this:&lt;/name&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="brush:bash"&gt;&lt;br /&gt;for file in `ls *.tsv`;&lt;br /&gt;  do cut -f1,2 --output-delimiter=, \&lt;br /&gt;  $file &gt; ${file/.tsv/.csv};&lt;br /&gt;done&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;Sweet, eh?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-9147496053056205161?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/9147496053056205161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/05/bash-substing-substitution.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/9147496053056205161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/9147496053056205161'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/05/bash-substing-substitution.html' title='bash substring substitution'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-9064939563029327439</id><published>2009-04-24T13:06:00.000-07:00</published><updated>2009-07-17T14:02:24.530-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='graphics'/><category scheme='http://www.blogger.com/atom/ns#' term='utils'/><title type='text'>Histograms in gnuplot</title><content type='html'>I'm pretty new to gnuplot, but have found it to be a handy tool for simple plots.  &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Today I needed to generate a simple histogram.  Rather than creating a permanent script I've just been piping a string into gnuplot from echo.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre&gt;echo "set terminal png;\&lt;br /&gt; set output 'timings.png';\&lt;br /&gt; set style fill solid 0.5 border -1;\&lt;br /&gt; set xlabel 'chunks';\&lt;br /&gt; set ylabel 'time to complete (m)';\&lt;br /&gt; set key autotitle columnhead;\&lt;br /&gt; set title 'timings on 20 nodes';\&lt;br /&gt; set auto x;\&lt;br /&gt; plot 'timings.tsv' u 2:xticlabels(1) with boxes lt 2;"\&lt;br /&gt; |  gnuplot&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;and out pops a nice histogram (sorry, can't post this example as it's work related).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The input file had column headers and the first column was used as the xlabels (see the xticlabels call above?)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-9064939563029327439?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/9064939563029327439/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/04/histograms-in-gnuplot.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/9064939563029327439'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/9064939563029327439'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/04/histograms-in-gnuplot.html' title='Histograms in gnuplot'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-7249632471011825977</id><published>2009-04-23T10:07:00.001-07:00</published><updated>2009-07-17T14:03:00.161-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Stacktrace from a running process</title><content type='html'>There have been a few &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_0"&gt;occasions&lt;/span&gt; where I've been very confused as to why a process is taking a long time to run (usualy Java processes).  It's often handy to request a stacktrace from the running process; you can do this without terminating it by issuing 'kill -3 &amp;lt;pid&amp;gt;'.   Good, eh?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-7249632471011825977?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/7249632471011825977/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/04/stacktrace-from-running-process.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7249632471011825977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/7249632471011825977'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/04/stacktrace-from-running-process.html' title='Stacktrace from a running process'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-287152567740853472</id><published>2009-04-23T09:38:00.000-07:00</published><updated>2009-07-17T14:01:16.480-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Unix Join with tabs</title><content type='html'>This one had me scratching my head for a while yesterday.  When you use the unix 'join' command with the default separators (whitespace) then you can join tab delimited files, but the output is space delimited.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I tried specifying the join character with -t "\t" or -t '\t' and even the despearate -t\t, but none of that works.  Turns out you have to use an *actual* quoted tab character (which I found through a quick google search, the solution was &lt;a href="http://jjinux.blogspot.com/2008/04/unix-join.html"&gt;here&lt;/a&gt;, thank you JJinuxLand).  &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;You can insert a tab on the command line with the following key combo "ctrl-v &amp;lt;tab&amp;gt;&lt;tab&gt;".&lt;/tab&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Job's a goodun.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-287152567740853472?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/287152567740853472/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/04/unix-join-with-tabs.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/287152567740853472'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/287152567740853472'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/04/unix-join-with-tabs.html' title='Unix Join with tabs'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2881497249851644909.post-5917791117618480286</id><published>2009-04-23T09:34:00.000-07:00</published><updated>2009-04-23T10:39:30.647-07:00</updated><title type='text'>print "Hello World!"</title><content type='html'>Hi,&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I'm intending for this blog to just be a brain export of any useful/interesting or confusing things I come across in the course of my work.  It'll probably contain items on MySQL, relational databases in general, Unix/Linux, Perl, Java, bash, svn, eclipse and the like.  It may also end up having some interesting or surprising biology/biochemistry/bioinformatics items as well.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Paul&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2881497249851644909-5917791117618480286?l=geekbraindump.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://geekbraindump.blogspot.com/feeds/5917791117618480286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://geekbraindump.blogspot.com/2009/04/print-hello-world.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5917791117618480286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2881497249851644909/posts/default/5917791117618480286'/><link rel='alternate' type='text/html' href='http://geekbraindump.blogspot.com/2009/04/print-hello-world.html' title='print &quot;Hello World!&quot;'/><author><name>PaulBo</name><uri>http://www.blogger.com/profile/14617260943732454939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_oN6pPL-C9vc/SWHCQMUcleI/AAAAAAAABP4/i75Xq5f-CwQ/S220/IMG_0018.JPG'/></author><thr:total>0</thr:total></entry></feed>
