<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Chris Lowis</title>
 
 <link href="http://blog.chrislowis.co.uk/" />
 <updated>2012-05-11T21:43:38+01:00</updated>
 <id>http://blog.chrislowis.co.uk/</id>
 <author>
   <name>Chris Lowis</name>
   <email>chris.lowis@gmail.com</email>
 </author>

 
 <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/ChrisLowis" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="chrislowis" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
   <title>Ruby Manor 2011</title>
   <link href="http://blog.chrislowis.co.uk/2011/11/20/ruby-manor-2011.html" />
   <updated>2011-11-20T00:00:00+00:00</updated>
   <id>http://blog.chrislowis.co.uk/2011/11/20/ruby-manor-2011</id>
   <content type="html">&lt;p&gt;
The third &lt;a href="http://rubymanor.org/3/"&gt;Ruby Manor&lt;/a&gt; conference happened in London a few weeks ago. I
thought I'd give my reflections on the event in the old-fashioned blog
post style.
&lt;/p&gt;

&lt;div id="outline-container-1" class="outline-3"&gt;
&lt;h3 id="sec-1"&gt;Philosophy &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1"&gt;


&lt;p&gt;
Ruby Manor is run according to a certain philosophy. Some of it was
&lt;a href="https://groups.google.com/d/topic/ruby-manor/zxepNy-VLHE/discussion"&gt;explained upfront&lt;/a&gt; by James, Murray and Tom (this year's organising
team), and some of it is implicit - drawn largely from the way
previous Manors and the monthly LRUG meetings are run. Ruby Manor &lt;a href="http://interblah.net/ruby-manor-is-not-an-unconference"&gt;is not an unconference&lt;/a&gt;, it doesn't have keynote speakers, swag, dinners
or t-shirts. It costs less than £15. The speakers and topics are
chosen by the attendees and &lt;a href="http://vestibule.rubymanor.org/champs"&gt;contribution to the process is encouraged&lt;/a&gt;.
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-2" class="outline-3"&gt;
&lt;h3 id="sec-2"&gt;Organisation &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-2"&gt;


&lt;p&gt;
Before last year's conference, speakers proposed their talks on a
mailing list. We asked questions, and the organising team selected the
final list of presentations. This year, this system was enhanced and
formalised as &lt;a href="http:vestibule.rubymanor.org"&gt;Vestibule&lt;/a&gt; - a simple web application designed to
encourage and facilitate engagement with the organisation of the
conference. The most interesting section is the short &lt;a href="http://vestibule.rubymanor.org/motivation"&gt;motivations&lt;/a&gt;
given by the attendees for participating. Quite soon after the site
launched a number of talks were &lt;a href="http://vestibule.rubymanor.org/proposals"&gt;proposed&lt;/a&gt;. As an example, consider the
(ultimately unsuccessful) talk &lt;a href="http://vestibule.rubymanor.org/proposals/16"&gt;I proposed&lt;/a&gt;. I gave an outline of the
talk I wanted to give and asked for feedback and suggestions. I was
encouraged by the level of support and worked further to add more
information to the proposal based on the feedback. About 3 weeks
before the event, the proposals were open to the vote and whittled
down to a final &lt;a href="http://vestibule.rubymanor.org/selections"&gt;selection&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Vestibule used a points-based "karma" system to &lt;a href="http://vestibule.rubymanor.org/champs"&gt;rank the participants&lt;/a&gt;
on their level of engagement. I'm not entirely sure what impact the
score had, but I believe tickets were made available in batches to
those with the highest scores first. James Adam &lt;a href="http://interblah.net/early-bird-tickets"&gt;talks more about the philosophy of conference ticketing&lt;/a&gt; on his blog.
&lt;/p&gt;
&lt;p&gt;
I found the Vestibule system quite addictive - it was something I
found myself checking each day, especially as new features were rolled
out as the process went along. I'd be interested to see some analysis
of the level of engagement too - did it demonstrate a &lt;a href="http://en.wikipedia.org/wiki/Pareto_principle"&gt;typical split&lt;/a&gt; in
engagement between active and passive, or did the presence of rewards
encourage increased engagement?
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-3" class="outline-3"&gt;
&lt;h3 id="sec-3"&gt;Venue &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-3"&gt;


&lt;p&gt;
The venue this year was the University of Westminster building on New
Cavendish street. The lecture-theatre used had a raked seating
arrangement with a large projector which meant that everyone got a
good view of the talks. The venue was close to a large number of
places to grab lunch and coffee during the breaks. I'm not sure what
the WIFI was like as I didn't take a laptop, but I don't think people
had too many problems. There was very little space at the back of the
room which meant that you had to be in your seats in time for the
talks and were essentially captive for the duration of the sessions,
but the individual talks were of equal length which made shuffling
around easy.
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-4" class="outline-3"&gt;
&lt;h3 id="sec-4"&gt;Lunch &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-4"&gt;




&lt;img src="/images/lunch.jpg" width="600" alt="Ruby Manor Machine Learning Lunch"&gt;&lt;/img&gt;

&lt;p&gt;
I experimented with organising "Birds of a Feather" lunches this
year. The idea is to have lunch with people who share a common
interest, and is organised by having people sign up to lunch-time
groups on the day. Although I got a good-sized group of people
together for a "machine-learning" themed lunch, I don't think many
other topics formed. In retrospect I think it would have been good to
organise lunch "champions" in advance to lead a group around a
particular topic. Also as the conference was Ruby focussed, I guess
people found it easy to find others with at least Ruby as a common
interest.
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-5" class="outline-3"&gt;
&lt;h3 id="sec-5"&gt;The Talks &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-5"&gt;


&lt;p&gt;
&lt;a href="http://lanyrd.com/2011/ru3y-manor/schedule/"&gt;The talks&lt;/a&gt; were universally of a very high standard. There wasn't a
single one that I didn't get something out of, and a couple were among
the best I've ever seen at any conference. Keep an eye on the &lt;a href="http://rubymanor.org"&gt;Ruby Manor&lt;/a&gt; website for the videos when they're released. For me the real
standouts were:
&lt;/p&gt;

&lt;/div&gt;

&lt;div id="outline-container-5-1" class="outline-4"&gt;
&lt;h4 id="sec-5-1"&gt;Programming with Nothing by Tom Stuart &lt;/h4&gt;
&lt;div class="outline-text-4" id="text-5-1"&gt;


&lt;p&gt;
&lt;a href="http://experthuman.com/"&gt;Tom&lt;/a&gt; introduced us to the &lt;a href="http://en.wikipedia.org/wiki/Lambda_calculus"&gt;Lambda Calculus&lt;/a&gt; by considering what is
possible in Ruby if we strip the language right back to basics. He
implemented a solution to the FizzBuzz problem using just Ruby's
&lt;code&gt;Proc&lt;/code&gt; object and the methods &lt;code&gt;Proc.new&lt;/code&gt; and &lt;code&gt;Proc#call&lt;/code&gt;. What started
out as a curiosity turned into a discourse on the nature of
computation and the power of functional programming. It ended with a
roar of approval when the final code was run! The slides were superb,
the delivery style was quirky enough to be at home at a Ruby
conference but had a real depth - there's no surprise to learn Tom
used to lecture Computer Science topics at Cambridge! A real treat.
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-5-2" class="outline-4"&gt;
&lt;h4 id="sec-5-2"&gt;A Random Walk by Ben Griffiths &lt;/h4&gt;
&lt;div class="outline-text-4" id="text-5-2"&gt;


&lt;p&gt;
I really enjoyed &lt;a href="http://www.techbelly.com/"&gt;Ben Griffiths&lt;/a&gt;'s talk on Randomness. He gave a
grab-bag selection of slides on such topics as Monte Carlo analysis,
Simulated Annealing and a thought experiment on what it would be like
to have a CI system that deployed to your production environment
randomly. Ben organised his talk as one "idea" per slide, illustrated
with occasional Ruby code, and then randomised the order just to keep
himself and us on our toes. A fun idea and one that would have tripped
up most speakers, I think. Not Ben though, he's a fantastic speaker
and one I always enjoy seeing.
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-5-3" class="outline-4"&gt;
&lt;h4 id="sec-5-3"&gt;The Joy of Text by Sean O'Halpin &lt;/h4&gt;
&lt;div class="outline-text-4" id="text-5-3"&gt;


&lt;p&gt;
I was looking forward to this talk - sitting next to Sean &lt;a href="http://bbc.co.uk/rd"&gt;at work&lt;/a&gt;,
I've seen it come together slowly off the back of a lot of
research. Sean talked about text encodings, his &lt;a href="http://github.com/seanohalpin/ffi-ncurses"&gt;ffi-ncurses&lt;/a&gt; library
and the history of terminal interfaces. He attempted to explain some
of the problems we programmers face everyday when we work with text
and text-based interfaces. It was a talk which covered a lot of
ground, and hid a lot of depth and knowledge of the subject under a
veneer of amusing anecdotes and useful tips. I hope the content of the
talk makes it out in a longer form (a series of blog articles would be
great, if you're reading, Sean!) as there's a lot of very useful
content for us all to learn in there.
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-6" class="outline-3"&gt;
&lt;h3 id="sec-6"&gt;Conclusion &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-6"&gt;


&lt;p&gt;
I hope this post has given you some feel for how great again the Ruby Manor
conference was this year, and has encouraged you to seek out the
slides and videos when they appear (it looks like the &lt;a href="http://lanyrd.com/2011/ru3y-manor/schedule/"&gt;lanyrd page&lt;/a&gt;
might be a good place to find everything together). It was a
conference as much about the people and the community as it was the
talks and the programming language. An experiment in self-organisation
which showed how difficult it is to get people to step out of the
comfort zone and contribute to the shaping of their community, but
also what can be achieved when a few of them do so.
&lt;/p&gt;
&lt;p&gt;
Thanks to Murray, James, Tom and all the champs who contributed to
this year's event. Well done all!
&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/OOL9YtRTDbQ" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Great radio interviews</title>
   <link href="http://blog.chrislowis.co.uk/2011/05/18/great-radio-podcast-interviews.html" />
   <updated>2011-05-18T00:00:00+01:00</updated>
   <id>http://blog.chrislowis.co.uk/2011/05/18/great-radio-podcast-interviews</id>
   <content type="html">&lt;p&gt;
I'm a big fan of radio, and one format I particularly enjoy is the
long-form interview. Here are some of the interviews I've really
enjoyed in recent months, available as podcasts or downloads, and some
reasons why you might enjoy them too.
&lt;/p&gt;

&lt;div id="outline-container-1" class="outline-3"&gt;
&lt;h3 id="sec-1"&gt;&lt;a href="http://5by5.tv/pipeline/49"&gt;Philip Elmer-Dewitt interviewed by Dan Benjamin on The Pipeline&lt;/a&gt; &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1"&gt;


&lt;p&gt;
I'm a fan of Dan Benjamin's 5by5 radio network. I'm less keen on the
wide ranging discussion-show formats but when he conducts one-on-one
interviews with people he obviously respects his interviewing style
really brings out the best in his guests.
&lt;/p&gt;


&lt;a href="http://www.flickr.com/photos/imh/3297961043/" title="Radio Daze by Ian Hayhurst, on Flickr"&gt;&lt;img src="http://farm4.static.flickr.com/3317/3297961043_1ab2a0f94b_m.jpg" width="240" height="160" alt="Radio Daze"&gt;&lt;/a&gt;

&lt;p&gt;
In this interview with &lt;a href="http://en.wikipedia.org/wiki/Philip_Elmer-DeWitt"&gt;Philip Elmer-Dewitt&lt;/a&gt; they discuss the long
career of this prolific ex-Time writer. Elmer-Dewitt is remarkably
self-effacing, but I was inspired by the tale of his transition from
technical writer/programmer to eventually Science Editor of Time
magazine. The day-to-day accounts of his working life and tales of the discipline
he's cultivated are truly fascinating. There's a lot of wisdom in this
interview!
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-2" class="outline-3"&gt;
&lt;h3 id="sec-2"&gt;&lt;a href="http://www.bbc.co.uk/radio4/features/desert-island-discs/castaway/d8176a1c#b00p068y"&gt;Morrissey interviewed by Kirsty Young on Desert Island Discs&lt;/a&gt; &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-2"&gt;


&lt;p&gt;
The recently-launched Desert Island Discs archive website has made
hundreds of interviews from the long-running Radio 4 show's archive
available to "download and keep". Throwing in some of my favourite
band's names into the search box led to this gem from 2009.
&lt;/p&gt;
&lt;p&gt;
Kirsty Young asks pointed, revealing questions often as simple
statements to be refuted ("You're not traditionally romantic") but
Morrissey is more willing to engage than usual ("I think I am"). He
talks freely about his childhood, the cult of celebrity, why four
years of the Smiths over-shadows the rest of his career and along the
way gets chance to play some great records from The Ramones, Iggy &amp;amp;
The Stooges and The Velvet Underground.
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-3" class="outline-3"&gt;
&lt;h3 id="sec-3"&gt;&lt;a href="http://www.maximumfun.org/sound-young-america/ian-mackaye-fugazi-minor-threat-and-evens-interview-sound-young-america "&gt;Ian Mackaye interviewed by Jesse Thorn on the Sound of Young America&lt;/a&gt;&lt;/h3&gt;
&lt;div class="outline-text-3" id="text-3"&gt;


&lt;p&gt;
I'd not heard of this show before Dan Benjamin interviewed Jesse Thorn
on The Pipeline. It appears to be very popular across the Atlantic,
being syndicated widely via NPR. As I clicked through the
back-catalogue of shows I came across this interview with Ian Mackaye,
guitarist in one of my favourite bands, Fugazi, and head of Dischord
records.
&lt;/p&gt;
&lt;p&gt;
In the interview Mackaye talks more about his personal philosophy
rather than the music - what it's like to run a business with
principles, how it feels to inspire an entire youth movement and the
passion he has for the Washington DC community. Mackaye is a great
talker with conviction and experience; he rarely gives interviews so
this was a real treat.
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-4" class="outline-3"&gt;
&lt;h3 id="sec-4"&gt;&lt;a href="http://twit.tv/floss136"&gt;Carsten Dominik interviewed by Randal Schwartz on FLOSS Weekly&lt;/a&gt; &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-4"&gt;


&lt;p&gt;
I'm not quite the regular listener I once was to FLOSS weekly. Randal
Schwartz is a knowledgeable and competent interviewer, but he doesn't
have the easy-on-the ears style of former co-host Leo Laport. I still
tune in when the topic or guest looks interesting though, and did so
for this interview with Carsten Dominik, creator of &lt;code&gt;org-mode&lt;/code&gt; for
Emacs. I spend a good portion of my working life inside the venerable
old editor, and organise my thoughts and projects using org-mode.
&lt;/p&gt;
&lt;p&gt;
Org is on the surface a simple, useful piece of software, as Dominik
makes clear its inception was certainly a case of scratching a
personal itch, but its the community that has driven the development
of its vast array of other features. Listening to Dominik's passion and
theories on community management in open source software was very
motivating, and the fact that he developed the software alongside a
busy scientific life must say something about the power of org-mode as
a time management tool!
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-5" class="outline-3"&gt;
&lt;h3 id="sec-5"&gt;&lt;a href="http://freakonomicsradio.com/growing-up-buffett.html"&gt;Peter Buffet interviewed by Stephen Dubner on Freakonomics Radio&lt;/a&gt; &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-5"&gt;


&lt;p&gt;
It's difficult to find radio programming that is not scared of numbers
or the statistics behind news stories. Stephen Dubner has made a
career out of asking the kind of questions that others seldom do, or
at the very least presenting the research that others are doing to his
audience in a compelling way. He's recently started a radio show too,
and some of the episodes are interesting interviews. In this episode
he talks to Peter Buffet - composer, musician and youngest son of
Warren Buffet.
&lt;/p&gt;
&lt;p&gt;
As you can expect, the topic of his famous father is never far away,
but it was the discussion about his early family life that I enjoyed,
and the conviction Peter Buffet had to follow his own path. It was an
enjoyable interview, Dubner let his guest speak without the clever
verbal tricks of some of his other episodes.
&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/SLG3aZw8joA" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Joining BBC Research and Development</title>
   <link href="http://blog.chrislowis.co.uk/2011/04/06/joining-bbc-rd.html" />
   <updated>2011-04-06T00:00:00+01:00</updated>
   <id>http://blog.chrislowis.co.uk/2011/04/06/joining-bbc-rd</id>
   <content type="html">&lt;p&gt;
A couple of months ago I joined the &lt;a href="http://www.bbc.co.uk/blogs/researchanddevelopment/prototyping/"&gt;Prototyping team&lt;/a&gt; in &lt;a href="http://bbc.co.uk/rd"&gt;BBC R&amp;amp;D&lt;/a&gt;. It's
a great chance to work on cutting edge technologies for broadcast and
the web. And a great place to work with some really smart people.
&lt;/p&gt;
&lt;p&gt;
The first thing I've been working on is the fledgling &lt;a href="http://groups.google.com/group/radiotag-developers"&gt;RadioTAG&lt;/a&gt;
specification, part of the &lt;a href="http://radiodns.org"&gt;RadioDNS&lt;/a&gt; umbrella of technologies. We're
looking at adding a button to radios or other radio-receiving devices
that will allow a listener to register their interest in a
broadcast. Maybe you've heard a track you'd like to listen to again,
or you have to leave the house during the Today programme and want to
carry on listening where you left off when you reach the
office. Interesting stuff.
&lt;/p&gt;
&lt;p&gt;
As my colleague &lt;a href="http://whomwah.com"&gt;Duncan&lt;/a&gt; &lt;a href="http://whomwah.com/2011/01/07/2011-is-already-turning-out-to-be-amazing/"&gt;said&lt;/a&gt;, we should all try to blog a little more
this year. I've &lt;a href="http://www.bbc.co.uk/blogs/researchanddevelopment/2011/02/prototyping-weeknotes-51-25021.shtml"&gt;made&lt;/a&gt; a &lt;a href="http://www.bbc.co.uk/blogs/researchanddevelopment/2011/03/building-applications-on-large.shtml"&gt;start&lt;/a&gt; over on our team's blog, but I'm going to
try and do so here too.
&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/ADco732K_xw" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Using Rake and Git to find out what I did yesterday</title>
   <link href="http://blog.chrislowis.co.uk/2010/11/24/what-did-I-do-yesterday.html" />
   <updated>2010-11-24T00:00:00+00:00</updated>
   <id>http://blog.chrislowis.co.uk/2010/11/24/what-did-I-do-yesterday</id>
   <content type="html">&lt;p&gt;
At our &lt;a href="http://en.wikipedia.org/wiki/Stand-up_meeting"&gt;daily stand-ups&lt;/a&gt; we have to answer the question "What did you do
yesterday". I wrote a little Rake task for the project I am working on
to help me answer:
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;desc &lt;span style="color: #cc9393;"&gt;"List of all commits commited in the previous 24hours"&lt;/span&gt;
task &lt;span style="color: #dca3a3; font-weight: bold;"&gt;:yesterday&lt;/span&gt; &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;do&lt;/span&gt;
  git_author = &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;ENV&lt;/span&gt;[&lt;span style="color: #cc9393;"&gt;'GIT_AUTHOR'&lt;/span&gt;] || &lt;span style="color: #cc9393;"&gt;"chris.lowis"&lt;/span&gt;
  cmd = &lt;span style="color: #cc9393;"&gt;"git --no-pager log --after=\"1 day ago\" --pretty=oneline --author=&lt;/span&gt;&lt;span style="color: #f0dfaf;"&gt;#{git_author}&lt;/span&gt;&lt;span style="color: #cc9393;"&gt;"&lt;/span&gt;
  puts &lt;span style="color: #cc9393;"&gt;"Commits in the last 24 hours for &lt;/span&gt;&lt;span style="color: #f0dfaf;"&gt;#{git_author}&lt;/span&gt;&lt;span style="color: #cc9393;"&gt;"&lt;/span&gt;
  system(cmd)
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
&lt;/pre&gt;



&lt;p&gt;
This simply shells out to git with the appropriate command line
arguments giving me a simple list:
&lt;/p&gt;



&lt;pre class="src src-sh"&gt;Commits&lt;span style="color: #f0dfaf; font-weight: bold;"&gt; in&lt;/span&gt; the last 24 hours for chris.lowis
6663b95b5832sda91998c05fea7970fe44da13af Adding a great new feature
677b2e8092406b3c2031e8f065fg5672d90b8108 Fixing someone elses bug
&lt;/pre&gt;



&lt;p&gt;
There's quite a lot of interesting options that you can pass to &lt;code&gt;git log&lt;/code&gt;, &lt;a href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html"&gt;see the documentation&lt;/a&gt; for a list of them.
&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/owyPXMg-POM" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Laptop Driven Development (with Emacs)</title>
   <link href="http://blog.chrislowis.co.uk/2010/10/26/laptop-driven-development-with-emacs.html" />
   <updated>2010-10-26T00:00:00+01:00</updated>
   <id>http://blog.chrislowis.co.uk/2010/10/26/laptop-driven-development-with-emacs</id>
   <content type="html">&lt;p&gt;
I read an &lt;a href="http://oinopa.com/2010/10/24/laptop-driven-development.html"&gt;interesting post&lt;/a&gt; over on Bernerd Schaefers blog the other
day where he described his set up for coding when you only have a
small screen. He talks about methods for switching between VIM and a
terminal. If you're an emacs user, like me, it's more common to run
your terminal inside emacs.
&lt;/p&gt;
&lt;p&gt;
I use the &lt;a href="http://github.com/mxcl/homebrew"&gt;homebrew&lt;/a&gt; package manager for OS X. One thing this allows me
to do is compile emacs from source with support for true full-screen
mode
&lt;/p&gt;



&lt;pre class="src src-sh"&gt;$ brew install emacs --cocoa
$ ln -s /usr/local/Cellar/emacs/23.2/Emacs.app /Applications/Emacs.app
&lt;/pre&gt;



&lt;p&gt;
This gives me a recent emacs with a great, full-screen mode which I
activate by running &lt;code&gt;M-x ns-toggle-fullscreen&lt;/code&gt;
&lt;/p&gt;


&lt;img src="/images/emacs-fullscreen.png" alt="Emacs fullscreen screenshot"&gt;&lt;/img&gt;

&lt;p&gt;
That's my entire screen - no menubars, docks or other OS
paraphernalia. I can switch to a shell for running my unit tests by
typing &lt;code&gt;M-x eshell&lt;/code&gt; (or for a standard bash shell &lt;code&gt;M-x shell&lt;/code&gt;)
&lt;/p&gt;


&lt;img src="/images/emacs-terminal.png" alt="Emacs terminal screenshot"&gt;&lt;/img&gt;

&lt;p&gt;
Since the usable area of the screen is quite large, thanks to the
fullscreen mode, I also have room to split the frame in two (&lt;code&gt;M-x split-window-vertically&lt;/code&gt;) to see, for example, tests and
implementation at the same time
&lt;/p&gt;


&lt;img src="/images/emacs-split-2.png" alt="Emacs terminal screenshot"&gt;&lt;/img&gt;

&lt;p&gt;
Or, occasionally, to pop open the shell buffer for quickly issuing a command
&lt;/p&gt;


&lt;img src="/images/emacs-split-3.png" alt="Emacs terminal screenshot"&gt;&lt;/img&gt;

&lt;p&gt;
I find emacs to be a great environment to work in on a smaller
screen. You can see more of my emacs configuration on &lt;a href="http://github.com/chrislo/emacs-config"&gt;github&lt;/a&gt;.
&lt;/p&gt;



&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/u0mU-Ske-qA" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Setting Http Proxy when using the selenium-webdriver gem and Firefox</title>
   <link href="http://blog.chrislowis.co.uk/2010/07/14/http-proxy-selenium-webdriver-and-firefox.html" />
   <updated>2010-07-14T00:00:00+01:00</updated>
   <id>http://blog.chrislowis.co.uk/2010/07/14/http-proxy-selenium-webdriver-and-firefox</id>
   <content type="html">&lt;p&gt;
I've been using the &lt;a href="http://rubygems.org/gems/selenium-webdriver"&gt;selenium-webdriver ruby gem&lt;/a&gt; to do some automated
Cucumber testing of our application. Sadly, I'm sat behind a firewall
which requires an HTTP proxy to access the outside world. Using the
Chrome WebDriver bridge worked fine as it inherits the system
preferences on OS X. However with Firefox I had to perform some
trickery to get it to work:
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;require &lt;span style="color: #cc9393;"&gt;'rubygems'&lt;/span&gt;
require &lt;span style="color: #cc9393;"&gt;'selenium-webdriver'&lt;/span&gt;

include &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Selenium&lt;/span&gt;

profile = &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;WebDriver&lt;/span&gt;::&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Firefox&lt;/span&gt;::&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Profile&lt;/span&gt;.new
profile[&lt;span style="color: #cc9393;"&gt;"network.proxy.type"&lt;/span&gt;] = 1
profile[&lt;span style="color: #cc9393;"&gt;"network.proxy.http"&lt;/span&gt;] = &lt;span style="color: #cc9393;"&gt;"www-cache.at.my.work.co.uk"&lt;/span&gt;
profile[&lt;span style="color: #cc9393;"&gt;"network.proxy.http_port"&lt;/span&gt;] = 80

driver = &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;WebDriver&lt;/span&gt;.for(&lt;span style="color: #dca3a3; font-weight: bold;"&gt;:firefox&lt;/span&gt;, &lt;span style="color: #dca3a3; font-weight: bold;"&gt;:profile&lt;/span&gt; =&amp;gt; profile)
driver.navigate.to &lt;span style="color: #cc9393;"&gt;"http://google.com"&lt;/span&gt;
&lt;/pre&gt;



&lt;p&gt;
The &lt;code&gt;[]=&lt;/code&gt; method on &lt;code&gt;Profile&lt;/code&gt; is setting the options that you find by
typing 'about:config' in the Firefox URL bar. Take a look there in a
working Firefox profile to see what variables you should set for your
webdriver-specific profile in the code above.
&lt;/p&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/FiZ6IYHcCMQ" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Growl notifications from Ruby on OS X</title>
   <link href="http://blog.chrislowis.co.uk/2010/07/06/growl-notifications-from-ruby-on-osx.html" />
   <updated>2010-07-06T00:00:00+01:00</updated>
   <id>http://blog.chrislowis.co.uk/2010/07/06/growl-notifications-from-ruby-on-osx</id>
   <content type="html">&lt;p&gt;
I wanted to generate &lt;a href="http://growl.info/"&gt;Growl&lt;/a&gt; notifications from a Ruby script on OSX and
had a bit of trouble getting it to work. To save you the same hassle,
here's the steps I took:
&lt;/p&gt;

&lt;div id="outline-container-1" class="outline-3"&gt;
&lt;h3 id="sec-1"&gt;Install growl &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1"&gt;


&lt;p&gt;
Install &lt;a href="http://growl.info/"&gt;Growl&lt;/a&gt; if you haven't already. I used version 1.2.
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-2" class="outline-3"&gt;
&lt;h3 id="sec-2"&gt;Set some growl preferences &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-2"&gt;


&lt;p&gt;
In the growl preference plane (find it under System Preferences)
&lt;/p&gt;&lt;ul&gt;
&lt;li&gt;
under network check "Listen for incoming notifications" and "Allow
remote application registration"
&lt;/li&gt;
&lt;li&gt;
restart growl
&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-3" class="outline-3"&gt;
&lt;h3 id="sec-3"&gt;Install the ruby-growl gem &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-3"&gt;


&lt;p&gt;
There's a couple of different ruby bindings for Growl but &lt;a href="http://segment7.net/projects/ruby/growl/doc/"&gt;ruby-growl&lt;/a&gt;
seemed to work for me
&lt;/p&gt;



&lt;pre class="src src-sh"&gt;gem install ruby-growl
&lt;/pre&gt;



&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-4" class="outline-3"&gt;
&lt;h3 id="sec-4"&gt;Send a growl notification from your Ruby script &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-4"&gt;


&lt;p&gt;
You can now send notifications from Ruby
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;require &lt;span style="color: #cc9393;"&gt;'rubygems'&lt;/span&gt;
require &lt;span style="color: #cc9393;"&gt;'ruby-growl'&lt;/span&gt;

g = &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Growl&lt;/span&gt;.new &lt;span style="color: #cc9393;"&gt;"127.0.0.1"&lt;/span&gt;, &lt;span style="color: #cc9393;"&gt;"ruby-growl"&lt;/span&gt;, [&lt;span style="color: #cc9393;"&gt;"ruby-growl Notification"&lt;/span&gt;]

g.notify &lt;span style="color: #cc9393;"&gt;"ruby-growl Notification"&lt;/span&gt;, &lt;span style="color: #cc9393;"&gt;"It Came From Ruby-Growl"&lt;/span&gt;, &lt;span style="color: #cc9393;"&gt;"Greetings!"&lt;/span&gt;
&lt;/pre&gt;



&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/iUO5TKg-dsI" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Open-source rails apps to study and learn from</title>
   <link href="http://blog.chrislowis.co.uk/2010/05/31/five-rails-apps-to-study-and-learn-from.html" />
   <updated>2010-05-31T00:00:00+01:00</updated>
   <id>http://blog.chrislowis.co.uk/2010/05/31/five-rails-apps-to-study-and-learn-from</id>
   <content type="html">&lt;p&gt;
If, like me, you learn best by studying other code here's &lt;del&gt;five&lt;/del&gt; some
open-source rails apps with something to teach. They're a great
resource to study and improve your own code, or to use as the starting
point for your own applications. All of these applications use Rails 2
but as they are open-source they are a great opportunity to get
your feet wet in the Rails 3 world by helping to port them across.
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;Update:&lt;/b&gt; Thanks to the comments here and over on &lt;a href="http://news.ycombinator.com/item%3Fid=1393701"&gt;Hacker News&lt;/a&gt;, I've
added two more applications and made some comments on the non-standard
nature of the Loved by Less application code.
&lt;/p&gt;

&lt;div id="outline-container-1" class="outline-2"&gt;
&lt;h2 id="sec-1"&gt;Gemcutter &lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;


&lt;p&gt;
A site familiar to all Ruby developers is Gemcutter - the recent
replacement for the venerable Rubyforge. I wasn't aware that the
source code of the site was open source until danieldon &lt;a href="http://news.ycombinator.com/item%3Fid=1394270"&gt;pointed it out&lt;/a&gt;
to me, but you can study the code &lt;a href="http://github.com/qrush/gemcutter"&gt;on github&lt;/a&gt;. The Gemcutter source is
written in a very modern way featuring examples of using &lt;a href="http://github.com/qrush/gemcutter/tree/master/features/"&gt;Cucumber for integration testing&lt;/a&gt;, a simple &lt;a href="http://github.com/qrush/gemcutter/tree/master/app/middleware/"&gt;Rack middleware&lt;/a&gt; example and an
interesting &lt;a href="http://github.com/qrush/gemcutter/blob/master/config/routes.rb"&gt;routes.rb&lt;/a&gt; file showing how to cleanly version an API.
&lt;/p&gt;

&lt;/div&gt;

&lt;div id="outline-container-1_1" class="outline-3"&gt;
&lt;h3 id="sec-1_1"&gt;Features &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1_1"&gt;


&lt;ul&gt;
&lt;li&gt;
A very modern Rails application featuring the latest best practices.
&lt;/li&gt;
&lt;li&gt;
Examples of metal and rack middleware.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-2" class="outline-2"&gt;
&lt;h2 id="sec-2"&gt;Spot Us &lt;/h2&gt;
&lt;div class="outline-text-2" id="text-2"&gt;


&lt;p&gt;
&lt;a href="http://www.spot.us/"&gt;Spot Us&lt;/a&gt; is a website that allows individuals to commission freelance
journalists. It has many social-network type features which make the
&lt;a href="http://github.com/spot-us/spot-us/"&gt;source code&lt;/a&gt; interesting reading.
&lt;/p&gt;


&lt;img src="/images/spot_us.png" alt="Spot.us screenshot"&gt;&lt;/img&gt;

&lt;p&gt;
The comprehensive &lt;a href="http://github.com/spot-us/spot-us/tree/5f68f48eef39f5c67ddccd5cdae5feeaaefa320c/spec"&gt;test suite&lt;/a&gt; is written with rspec and the ruby-like
templating system &lt;a href="http://haml-lang.com/"&gt;HAML&lt;/a&gt; is used for the views. It's also an example of
how to use jQuery in a rails app instead of the default prototype
through the use of the jrails plugin.
&lt;/p&gt;

&lt;/div&gt;

&lt;div id="outline-container-2_1" class="outline-3"&gt;
&lt;h3 id="sec-2_1"&gt;Features &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-2_1"&gt;


&lt;ul&gt;
&lt;li&gt;
Haml
&lt;/li&gt;
&lt;li&gt;
rspec
&lt;/li&gt;
&lt;li&gt;
jquery with the jrails plugin.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-3" class="outline-2"&gt;
&lt;h2 id="sec-3"&gt;Loved by Less &lt;/h2&gt;
&lt;div class="outline-text-2" id="text-3"&gt;


&lt;p&gt;
&lt;a href="http://lovdbyless.com/"&gt;Loved By Less&lt;/a&gt; is an open-source social network. I think many Rails
freelancers have been asked to create a site with social network
features - profiles, 'friending', photo sharing etc. Less Everything
were no different and created this open-source platform to help ease
the pain of getting started. The &lt;a href="http://github.com/stevenbristol/lovd-by-less/tree/master"&gt;source code&lt;/a&gt; is available on
github. It's unlikely that simply cloning the app will give you
everything you need, but it's an amazing resource to read through and
take the bits you need for your project.
&lt;/p&gt;
&lt;p&gt;
The loved by less source code is starting to show it's age a bit, and
does include some pretty extensive &lt;a href="http://github.com/stevenbristol/lovd-by-less/tree/master/vendor/plugins/less_monkey_patching/lib/"&gt;monkey patching&lt;/a&gt; which may confuse
a newcomer. While I don't think this is bad in itself (it shows the
flexibility of Ruby, and also the dangers of not following Rails
conventions), it's something to be aware of. I think porting this to
Rails 3 would give newcomers to Rails a great resource to learn from.
&lt;/p&gt;

&lt;/div&gt;

&lt;div id="outline-container-3_1" class="outline-3"&gt;
&lt;h3 id="sec-3_1"&gt;Features &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-3_1"&gt;

&lt;ul&gt;
&lt;li&gt;
Search with Thinking Sphinx
&lt;/li&gt;
&lt;li&gt;
Flickr integration
&lt;/li&gt;
&lt;li&gt;
Comprehensive email support
&lt;/li&gt;
&lt;li&gt;
Paperclip for attachments
&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-4" class="outline-2"&gt;
&lt;h2 id="sec-4"&gt;Saasy &lt;/h2&gt;
&lt;div class="outline-text-2" id="text-4"&gt;


&lt;p&gt;
If you're working on a Software as a Service application, take a look
at &lt;a href="http://github.com/maccman/saasy/tree/master"&gt;Saasy&lt;/a&gt; . It's a template application designed to do billing and
authentication tasks 'so you don't have to'.
&lt;/p&gt;


&lt;img src="/images/saasy.png" alt="Sassy screenshot"&gt;&lt;/img&gt;

&lt;p&gt;
Studying the code base, you'll see examples of using SSL security and
ActiveMerchant. I was also interested in the &lt;a href="http://github.com/maccman/saasy/blob/57686af09acd1d5dddbd07af5dc82efe4a8dcde6/app/models/account.rb"&gt;accounts model&lt;/a&gt; which
uses the acts_as_state_machine plugin to simplify some of the logic.
&lt;/p&gt;

&lt;/div&gt;

&lt;div id="outline-container-4_1" class="outline-3"&gt;
&lt;h3 id="sec-4_1"&gt;Features &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-4_1"&gt;


&lt;ul&gt;
&lt;li&gt;
acts_as_state_machine
&lt;/li&gt;
&lt;li&gt;
ActiveMerchant
&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-5" class="outline-2"&gt;
&lt;h2 id="sec-5"&gt;Simply Agile &lt;/h2&gt;
&lt;div class="outline-text-2" id="text-5"&gt;


&lt;p&gt;
&lt;a href="http://github.com/camelpunch/simply_agile"&gt;Simply Agile&lt;/a&gt; by &lt;a href="http://www.camelpunch.com/"&gt;Andrew Bruce&lt;/a&gt; is an open source agile software project
management application. Think of a simple version of &lt;a href="http://www.pivotaltracker.com/"&gt;Pivotal Tracker&lt;/a&gt;. You can add story cards to a backlog, and then assign each
card to a sprint. Each time a card is completed you can drag and drop
it to the appropriate column in the Simply Agile task board. Andrew
has a very dedicated approach to test-driven development and as a
result the application is well covered by cucumber and rspec
tests. The javascript in this application is written in an unobtrusive
style and is a good example of using jQuery for "progressive
enhancement". The app is fully functional in browsers without
javascript, but where javascript is available so is the drag-and-drop
interface.
&lt;/p&gt;

&lt;/div&gt;

&lt;div id="outline-container-5_1" class="outline-3"&gt;
&lt;h3 id="sec-5_1"&gt;Features &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-5_1"&gt;

&lt;ul&gt;
&lt;li&gt;
Cucumber integration tests
&lt;/li&gt;
&lt;li&gt;
rspec coverage
&lt;/li&gt;
&lt;li&gt;
Drag and drop interface powered by jQuery.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-6" class="outline-2"&gt;
&lt;h2 id="sec-6"&gt;Typo &lt;/h2&gt;
&lt;div class="outline-text-2" id="text-6"&gt;


&lt;p&gt;
&lt;a href="http://github.com/fdv/typo/tree/master"&gt;Typo&lt;/a&gt; is "the oldest and most powerful Ruby on Rails blogware" and is
still under active development. While the &lt;a href="http://media.rubyonrails.org/video/rails_blog_2.mov"&gt;15 minute blog&lt;/a&gt; is still a
fantastic demonstration of how powerful Rails is for rapid application
development, anyone who has decided to take the project further and
create their own fully-featured blog system will know how much extra
work is needed. From comment systems, to anti-spam protection, restful
routing to upload support there are many features that need to be
added. Thankfully Typo has already implemented these and many other
features, and the &lt;a href="http://github.com/fdv/typo/tree/master"&gt;source code&lt;/a&gt; is available to help you learn how to do
the same.
&lt;/p&gt;

&lt;/div&gt;

&lt;div id="outline-container-6_1" class="outline-3"&gt;
&lt;h3 id="sec-6_1"&gt;Features &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-6_1"&gt;


&lt;ul&gt;
&lt;li&gt;
rspec for testing
&lt;/li&gt;
&lt;li&gt;
internationalisation support
&lt;/li&gt;
&lt;li&gt;
email notification
&lt;/li&gt;
&lt;li&gt;
admin and public-facing interfaces
&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-7" class="outline-2"&gt;
&lt;h2 id="sec-7"&gt;Open Source Rails &lt;/h2&gt;
&lt;div class="outline-text-2" id="text-7"&gt;


&lt;p&gt;
&lt;a href="http://www.opensourcerails.com/"&gt;Open source rails&lt;/a&gt; is a gallery of open-source rails projects. I
selected this project for this list because although the &lt;a href="http://github.com/jcnetdev/opensourcerails/tree/master"&gt;code&lt;/a&gt; itself
isn't well documented or tested, in many ways this is illustrates a
great strenght of the Rails framework. It is a good project to study
to realise how much can be achieved with a small amount of code and a
handful of powerful &lt;a href="http://github.com/jcnetdev/opensourcerails/tree/master/vendor/plugins/"&gt;plugins&lt;/a&gt; (not that I'd recommend starting your
next Rails project without tests, of course!).
&lt;/p&gt;

&lt;/div&gt;

&lt;div id="outline-container-7_1" class="outline-3"&gt;
&lt;h3 id="sec-7_1"&gt;Features &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-7_1"&gt;


&lt;ul&gt;
&lt;li&gt;
OpenID integration
&lt;/li&gt;
&lt;li&gt;
Paperclip for file uploads
&lt;/li&gt;
&lt;li&gt;
A simple set of &lt;a href="http://github.com/jcnetdev/opensourcerails/blob/master/config/routes.rb"&gt;routes&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-8" class="outline-2"&gt;
&lt;h2 id="sec-8"&gt;Conclusion &lt;/h2&gt;
&lt;div class="outline-text-2" id="text-8"&gt;


&lt;p&gt;
I hope you enjoyed this selection of Rails projects. This is far from
a definitive list, and I encourage you to read some of the
suggestions of other apps in the comments below and on the discussion
over on &lt;a href="http://news.ycombinator.com/item%3Fid=1393701"&gt;Hacker News.&lt;/a&gt;  With the upcoming Rails 3 release I think it's
a good time to reflect how far the Rails framework has come, and also
to remember to cater for people who are learning Rails for the first
time - studying open-source code is a great way to learn.
&lt;/p&gt;
&lt;p&gt;
Do you have a favourite open-source Rails project? Share it in the
comments below.
&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/RpKUD_uJoEs" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Unfilling regions in Emacs</title>
   <link href="http://blog.chrislowis.co.uk/2010/03/03/unfill-region-emacs.html" />
   <updated>2010-03-03T00:00:00+00:00</updated>
   <id>http://blog.chrislowis.co.uk/2010/03/03/unfill-region-emacs</id>
   <content type="html">&lt;p&gt;
I have the habit of hitting M-q every 5 seconds or so when working
with text in emacs. This key combination is bound to "fill-paragraph"
and inserts line breaks into the current paragraph to keep the line
width to approximately 80 characters.
&lt;/p&gt;
&lt;p&gt;
If you're cutting and pasting the text into an email message or
website form though, this is often not what you want. The way round
this is to "unfill" the current paragraph or region. The following
commands will help:
&lt;/p&gt;



&lt;pre class="src src-emacs-lisp"&gt;&lt;span style="color: #606060;"&gt;(&lt;/span&gt;&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;defun&lt;/span&gt; &lt;span style="color: #f0dfaf;"&gt;unfill-paragraph&lt;/span&gt; &lt;span style="color: #606060;"&gt;()&lt;/span&gt;
  &lt;span style="color: #606060;"&gt;(&lt;/span&gt;interactive&lt;span style="color: #606060;"&gt;)&lt;/span&gt;
  &lt;span style="color: #606060;"&gt;(&lt;/span&gt;&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;let&lt;/span&gt; &lt;span style="color: #606060;"&gt;((&lt;/span&gt;fill-column &lt;span style="color: #606060;"&gt;(&lt;/span&gt;point-max&lt;span style="color: #606060;"&gt;)))&lt;/span&gt;
    &lt;span style="color: #606060;"&gt;(&lt;/span&gt;fill-paragraph nil&lt;span style="color: #606060;"&gt;)))&lt;/span&gt;

&lt;span style="color: #606060;"&gt;(&lt;/span&gt;&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;defun&lt;/span&gt; &lt;span style="color: #f0dfaf;"&gt;unfill-region&lt;/span&gt; &lt;span style="color: #606060;"&gt;(&lt;/span&gt;start end&lt;span style="color: #606060;"&gt;)&lt;/span&gt;
  &lt;span style="color: #606060;"&gt;(&lt;/span&gt;interactive &lt;span style="color: #cc9393;"&gt;"r"&lt;/span&gt;&lt;span style="color: #606060;"&gt;)&lt;/span&gt;
  &lt;span style="color: #606060;"&gt;(&lt;/span&gt;&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;let&lt;/span&gt; &lt;span style="color: #606060;"&gt;((&lt;/span&gt;fill-column &lt;span style="color: #606060;"&gt;(&lt;/span&gt;point-max&lt;span style="color: #606060;"&gt;)))&lt;/span&gt;
    &lt;span style="color: #606060;"&gt;(&lt;/span&gt;fill-region start end nil&lt;span style="color: #606060;"&gt;)))&lt;/span&gt;
&lt;/pre&gt;



&lt;p&gt;
But now you have lines in your emacs buffer that wrap in an unusable
way. Longlines-mode to the rescue (M-x longlines-mode). Longlines mode
uses "soft newlines" which will not show up when yanked or saved to
disk.
&lt;/p&gt;
&lt;p&gt;
I've recently added my &lt;a href="http://www.github.com/chrislo/emacs-config"&gt;emacs config to github&lt;/a&gt;. Feel free to have a
poke around and let me know what other emacs tricks I am missing!
&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/RHTLkuhifhE" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Recent Activities</title>
   <link href="http://blog.chrislowis.co.uk/2009/08/25/recent-activities.html" />
   <updated>2009-08-25T00:00:00+01:00</updated>
   <id>http://blog.chrislowis.co.uk/2009/08/25/recent-activities</id>
   <content type="html">&lt;div id="outline-container-1" class="outline-3"&gt;
&lt;h3 id="sec-1"&gt;Recently&amp;hellip; &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1"&gt;


&lt;p&gt;
Back in May I started a new job at the BBC. I've been working on some
&lt;a href="http://www.bbc.co.uk/music/introducing"&gt;interesting&lt;/a&gt; &lt;a href="http://www.bbc.co.uk/music"&gt;projects&lt;/a&gt; with some great people. I've also been lucky
enough to take part in a couple of Hack Days in an official-ish
capacity, and I intend to blog about some of the technical aspects
soon. For now:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://musichackday.org/hacks.php?page=MusicBore"&gt;The Music Bore&lt;/a&gt; - an automated DJ system that &lt;a href="http://www.aelius.com/njh/"&gt;Nick&lt;/a&gt;, &lt;a href="http://www.metade.org/"&gt;Patrick&lt;/a&gt;, &lt;a href="http://moustaki.org/"&gt;Yves&lt;/a&gt; and
I built at the Music Hack Day. I wrote some more about this over on
the &lt;a href="http://www.bbc.co.uk/blogs/radiolabs/2009/07/the_music_bore.shtml."&gt;BBC Radio Labs blog&lt;/a&gt; Coming soon to an IRC channel, hosted
server, or if Patrick and I get our way Art Installation near you!

&lt;/li&gt;
&lt;li&gt;
David and I were invited to the Guardian's Hack Day where we worked
on a RDF and Processing powered mash-up of Guardian and BBC content
around MPs. David &lt;a href="http://www.bbc.co.uk/blogs/bbcinternet/2009/08/at_the_end_of_july.html"&gt;blogged&lt;/a&gt; about this on the BBC Internet blog.
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/KwxwPtaJkLg" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Using R and Ruby - slides from February LRUG</title>
   <link href="http://blog.chrislowis.co.uk/2009/02/15/LRUG-R-Ruby-talk.html" />
   <updated>2009-02-15T00:00:00+00:00</updated>
   <id>http://blog.chrislowis.co.uk/2009/02/15/LRUG-R-Ruby-talk</id>
   <content type="html">&lt;div id="outline-container-1" class="outline-3"&gt;
&lt;h3 id="sec-1"&gt;Introduction &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1"&gt;


&lt;p&gt;
Last week I gave a short talk at the &lt;a href="http://lrug.org/meetings/2009/01/20/february-2009-meeting/"&gt;February LRUG meeting&lt;/a&gt; about using
the scientific programming environment R together with Ruby.
&lt;/p&gt;
&lt;p&gt;
My presentation gave a few examples of the kind of statistical
analysis that can be performed with R, and showed how easy this
functionality is to access from within your Ruby code.
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-2" class="outline-3"&gt;
&lt;h3 id="sec-2"&gt;Slides &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-2"&gt;




&lt;embed type="application/x-shockwave-flash" »
src="/images/lrug.swf" width="600" height="450"  »
pluginspage="http://www.adobe.com/go/getflashplayer" /&gt;

&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-3" class="outline-3"&gt;
&lt;h3 id="sec-3"&gt;Code &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-3"&gt;


&lt;p&gt;
I'll post the code for the Twitter analysis to github soon. It needs a
little tidying up first.
&lt;/p&gt;
&lt;p&gt;
An initial draft of this presentation used R to develop a
recommendation algorithm (using a k-means clustering) using the GitHub
api. Although it worked, the recommendations it made were not great,
so I removed the code from the presentation and replaced it with the
Twitter analysis. I'd like to resurrect this code at some point, so
remember to subscribe to my &lt;a href="http://feeds.feedburner.com/ChrisLowis"&gt;RSS feed&lt;/a&gt; if you're interested, or nag me
to do it in the comments field below!
&lt;/p&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/90CkCj0du1c" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Calculating the Pearson correlation coefficient using R and Ruby</title>
   <link href="http://blog.chrislowis.co.uk/2009/01/21/pearson-correlation-using-R-and-Ruby.html" />
   <updated>2009-01-21T00:00:00+00:00</updated>
   <id>http://blog.chrislowis.co.uk/2009/01/21/pearson-correlation-using-R-and-Ruby</id>
   <content type="html">&lt;p&gt;
In a &lt;a href="http://blog.chrislowis.co.uk/2008/11/24/ruby-gsl-pearson.html"&gt;previous article&lt;/a&gt; I talked about using the GNU scientific library
to implement the Pearson correlation algorithm, as used for example in
&lt;a href="http://github.com/maccman/acts_as_recommendable/tree/master."&gt;acts&lt;sub&gt;as&lt;/sub&gt;&lt;sub&gt;recommendable&lt;/sub&gt;&lt;/a&gt; As a prelude to some forthcoming articles, I'd
like to show you how easy it is to implement the same thing using the
Ruby bindings to the &lt;a href="http://www.r-project.org/"&gt;R project&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
For this to work you'll need to install &lt;a href="http://www.r-project.org/"&gt;R&lt;/a&gt; and the &lt;a href="http://web.kuicr.kyoto-u.ac.jp/~alexg/rsruby/"&gt;rsruby&lt;/a&gt; gem. Take a
look at the documentation for the rsruby gem, as while installation is
straightforward there's a couple of things to be aware of.
&lt;/p&gt;
&lt;p&gt;
Having done that, let's reopen the Pearson class from the &lt;a href="http://blog.chrislowis.co.uk/2008/11/24/ruby-gsl-pearson.html"&gt;previous article&lt;/a&gt; and add a new R-based method
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;class&lt;/span&gt; &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Pearson&lt;/span&gt;
  &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;def&lt;/span&gt; &lt;span style="color: #f0dfaf;"&gt;initialize&lt;/span&gt;
    require &lt;span style="color: #cc9393;"&gt;'rsruby'&lt;/span&gt;
    &lt;span style="color: #f0dfaf;"&gt;@r&lt;/span&gt; = &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;RSRuby&lt;/span&gt;.instance
  &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;

  &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;def&lt;/span&gt; &lt;span style="color: #f0dfaf;"&gt;R_pearson&lt;/span&gt;(x,y)
    &lt;span style="color: #f0dfaf;"&gt;@r&lt;/span&gt;.cor(x,y)
  &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
&lt;/pre&gt;



&lt;p&gt;
The new initialize method sets up the communication with the R
instance. The actual definition for the Pearson method simple,
conversion from Ruby Arrays to R vectors is handled automatically by
the bindings, you simply need to know the correct R method to call -
in this case 'cor'. Take a look through the R manual to learn more
about this powerful tool - almost all the features are accessible
through the Ruby bindings.
&lt;/p&gt;
&lt;p&gt;
Here's a quick modification to the benchmark to compare performances:
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;require &lt;span style="color: #cc9393;"&gt;'benchmark'&lt;/span&gt;

n = 100000
x = []; n.times{x &amp;lt;&amp;lt; rand}
y = []; n.times{y &amp;lt;&amp;lt; rand}

p = &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Pearson&lt;/span&gt;.new()

&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Benchmark&lt;/span&gt;.bm() &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;do&lt;/span&gt; |bm|
  bm.report(&lt;span style="color: #cc9393;"&gt;"Ruby:"&lt;/span&gt;) {p.ruby_pearson(x,y)}
  bm.report(&lt;span style="color: #cc9393;"&gt;"GSL:"&lt;/span&gt;) {p.gsl_pearson(x,y)}
  bm.report(&lt;span style="color: #cc9393;"&gt;"Inline:"&lt;/span&gt;) {p.inline_pearson(n,x,y)}
  bm.report(&lt;span style="color: #cc9393;"&gt;"R:"&lt;/span&gt;) {p.&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;R_pearson&lt;/span&gt;(x,y)}
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
&lt;/pre&gt;



&lt;p&gt;
And the results,
&lt;/p&gt;
&lt;table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"&gt;
&lt;caption&gt;&lt;/caption&gt;
&lt;colgroup&gt;&lt;col class="left" /&gt;&lt;col class="right" /&gt;&lt;col class="right" /&gt;&lt;col class="right" /&gt;&lt;col class="left" /&gt;
&lt;/colgroup&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td class="left"&gt;&lt;/td&gt;&lt;td class="right"&gt;user&lt;/td&gt;&lt;td class="right"&gt;system&lt;/td&gt;&lt;td class="right"&gt;total&lt;/td&gt;&lt;td class="left"&gt;real&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="left"&gt;Ruby:&lt;/td&gt;&lt;td class="right"&gt;1.590000&lt;/td&gt;&lt;td class="right"&gt;0.020000&lt;/td&gt;&lt;td class="right"&gt;1.610000&lt;/td&gt;&lt;td class="left"&gt;(1.610470)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="left"&gt;GSL:&lt;/td&gt;&lt;td class="right"&gt;0.010000&lt;/td&gt;&lt;td class="right"&gt;0.000000&lt;/td&gt;&lt;td class="right"&gt;0.010000&lt;/td&gt;&lt;td class="left"&gt;(0.062538)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="left"&gt;Inline:&lt;/td&gt;&lt;td class="right"&gt;0.010000&lt;/td&gt;&lt;td class="right"&gt;0.000000&lt;/td&gt;&lt;td class="right"&gt;0.010000&lt;/td&gt;&lt;td class="left"&gt;(0.004548)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="left"&gt;R:&lt;/td&gt;&lt;td class="right"&gt;0.220000&lt;/td&gt;&lt;td class="right"&gt;0.010000&lt;/td&gt;&lt;td class="right"&gt;0.230000&lt;/td&gt;&lt;td class="left"&gt;(0.227184)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;


&lt;p&gt;
The R version is around 7 times faster than the native Ruby version,
but not as fast as the C-based approaches &lt;a href="http://blog.chrislowis.co.uk/2008/11/24/ruby-gsl-pearson.html"&gt;described earlier&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The real power of interfacing with R however is in the ability to
quickly swap out one algorithm for another, or experiment
interactively with your data in an irb console. Once you have an
algorithm that works well in your case, then it may be necessary to
re-implement in a faster language if performance is a concern.
&lt;/p&gt;
&lt;p&gt;
I'll be talking about R and Ruby a little more in the future, so
subscribe to the &lt;a href="http://feeds.feedburner.com/ChrisLowis"&gt;RSS feed&lt;/a&gt; if you're interested.
&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/81VWsh7pJLk" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Identify Programming Languages with SourceClassifier</title>
   <link href="http://blog.chrislowis.co.uk/2009/01/04/identify-programming-languages-with-source-classifier.html" />
   <updated>2009-01-04T00:00:00+00:00</updated>
   <id>http://blog.chrislowis.co.uk/2009/01/04/identify-programming-languages-with-source-classifier</id>
   <content type="html">&lt;p&gt;
Do you need to identify the programming language used in a snippet of
code? For example, in a &lt;a href="http://pastie.org/"&gt;pastie&lt;/a&gt; style application or in your blog
comments system. I've just released version 0.2.1 of SourceClassifier
over on &lt;a href="http://github.com/chrislo/sourceclassifier/tree/master"&gt;github&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Source classifier identifies programming language using a Bayesian
classifier trained on a corpus generated from the "Computer Language
Benchmarks Game":&lt;a href="http://shootout.alioth.debian.org/"&gt;http://shootout.alioth.debian.org/&lt;/a&gt;. It is written in
Ruby and available as a gem. Out of the box SourceClassifier
recognises C, Java, Javascript, Perl, Python and Ruby. A nice
advantage of using a Bayesian classifier to identify the source code
is that even false matches will still give some usable
highlighting. To train the classifier to identify new languages
download the sources from &lt;a href="http://github.com/chrislo/sourceclassifier/tree/master"&gt;github&lt;/a&gt; .
&lt;/p&gt;

&lt;div id="outline-container-1" class="outline-3"&gt;
&lt;h3 id="sec-1"&gt;Usage &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-1"&gt;


&lt;p&gt;
First install the gem using github as a source
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;$ gem sources -a http:&lt;span style="color: #cc9393;"&gt;//&lt;/span&gt;gems.github.com
$ sudo gem install chrislo-sourceclassifier
&lt;/pre&gt;



&lt;p&gt;
Then, to use
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;require &lt;span style="color: #cc9393;"&gt;'rubygems'&lt;/span&gt;
require &lt;span style="color: #cc9393;"&gt;'sourceclassifier'&lt;/span&gt;

s = &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;SourceClassifier&lt;/span&gt;.new

ruby_text = &lt;span style="color: #cc9393;"&gt;&amp;lt;&amp;lt;EOT
def my_sorting_function(a)
  a.sort
end
EOT&lt;/span&gt;

c_text = &lt;span style="color: #cc9393;"&gt;&amp;lt;&amp;lt;EOT
#include &amp;lt;unistd.h&amp;gt;

int main() {
  write(1, "hello world\n", 12);
  return(0);
}
EOT&lt;/span&gt;

s.identify(ruby_text) &lt;span style="color: #708070;"&gt;#&lt;/span&gt;&lt;span style="color: #7f9f7f;"&gt;=&amp;gt; Ruby
&lt;/span&gt;s.identify(c_text) &lt;span style="color: #708070;"&gt;#&lt;/span&gt;&lt;span style="color: #7f9f7f;"&gt;=&amp;gt; Gcc
&lt;/span&gt;&lt;/pre&gt;




&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-2" class="outline-3"&gt;
&lt;h3 id="sec-2"&gt;Training &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-2"&gt;


&lt;p&gt;
Download the sources from github and in the directory run the training
rake test
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;$ rake train
&lt;/pre&gt;



&lt;p&gt;
In the ./sources directory are sub-directories for each language you
wish to identify. Each sub-directory contains examples of programs
written in that language. The name of the directory is significant -
it is the value returned by the SourceClassifier.identify() method.
&lt;/p&gt;
&lt;p&gt;
The rake task populate can be used to build these sub-directories from
a checkout of the &lt;a href="http://alioth.debian.org/scm/?group_id=30402"&gt;computer language shootout sources&lt;/a&gt; but you are free
to train the classifier using any available examples.
&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="outline-container-3" class="outline-3"&gt;
&lt;h3 id="sec-3"&gt;Acknowledgments &lt;/h3&gt;
&lt;div class="outline-text-3" id="text-3"&gt;


&lt;p&gt;
This library depends heavily on the great &lt;a href="http://classifier.rubyforge.org/"&gt;Classifier&lt;/a&gt; gem by Lucas
Carlson and David Fayram II.
&lt;/p&gt;

&lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/HZUtUTJXH4E" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Get working quickly with a customised Rails project launcher</title>
   <link href="http://blog.chrislowis.co.uk/2008/12/30/get-started-quickly-rails-project-launcher.html" />
   <updated>2008-12-30T00:00:00+00:00</updated>
   <id>http://blog.chrislowis.co.uk/2008/12/30/get-started-quickly-rails-project-launcher</id>
   <content type="html">&lt;p&gt;
I just knocked up a quick Ruby script to automate some of the steps I
always do when starting work on a Rails project, namely:
&lt;/p&gt;&lt;ul&gt;
&lt;li&gt;
open an iTerm tab running script/server
&lt;/li&gt;
&lt;li&gt;
open an iTerm tab running script/console
&lt;/li&gt;
&lt;li&gt;
open an iTerm tab running autotest
&lt;/li&gt;
&lt;li&gt;
open an iTerm tab running a shell window
&lt;/li&gt;
&lt;li&gt;
launch Safari on localhost:3000 for testing.
&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;
Customise this little script to suit your own needs. You'll need to
install the rb-appscript gem to start with, and obviously this only
applies to OS X users.
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;require &lt;span style="color: #cc9393;"&gt;'rubygems'&lt;/span&gt;
require &lt;span style="color: #cc9393;"&gt;'appscript'&lt;/span&gt;

&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;RAILS_PROJECT_PATH&lt;/span&gt; = &lt;span style="color: #cc9393;"&gt;"~/path_to_your_rails_project"&lt;/span&gt; &lt;span style="color: #708070;"&gt;# &lt;/span&gt;&lt;span style="color: #7f9f7f;"&gt;Customise this
&lt;/span&gt;
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;def&lt;/span&gt; &lt;span style="color: #f0dfaf;"&gt;create_iterm_tab&lt;/span&gt;( command = &lt;span style="color: #cc9393;"&gt;""&lt;/span&gt; )
  &lt;span style="color: #f0dfaf;"&gt;@iterm&lt;/span&gt; ||= &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Appscript&lt;/span&gt;::app( &lt;span style="color: #cc9393;"&gt;'iTerm'&lt;/span&gt; )
  session = &lt;span style="color: #f0dfaf;"&gt;@iterm&lt;/span&gt;.current_terminal.sessions.end.make( &lt;span style="color: #dca3a3; font-weight: bold;"&gt;:new&lt;/span&gt; =&amp;gt; &lt;span style="color: #dca3a3; font-weight: bold;"&gt;:session&lt;/span&gt; )
  session.exec( &lt;span style="color: #dca3a3; font-weight: bold;"&gt;:command&lt;/span&gt; =&amp;gt; &lt;span style="color: #cc9393;"&gt;'bash -l'&lt;/span&gt; )
  session.write( &lt;span style="color: #dca3a3; font-weight: bold;"&gt;:text&lt;/span&gt; =&amp;gt; &lt;span style="color: #cc9393;"&gt;"cd &lt;/span&gt;&lt;span style="color: #f0dfaf;"&gt;#{RAILS_PROJECT_PATH}&lt;/span&gt;&lt;span style="color: #cc9393;"&gt;"&lt;/span&gt; )
  session.write( &lt;span style="color: #dca3a3; font-weight: bold;"&gt;:text&lt;/span&gt; =&amp;gt; command ) &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;unless&lt;/span&gt; command.nil?
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;

&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;def&lt;/span&gt; &lt;span style="color: #f0dfaf;"&gt;launch_browser&lt;/span&gt;( url = &lt;span style="color: #cc9393;"&gt;"http://localhost:3000"&lt;/span&gt;)
  &lt;span style="color: #f0dfaf;"&gt;@safari&lt;/span&gt; ||= &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Appscript&lt;/span&gt;::app(&lt;span style="color: #cc9393;"&gt;'Safari'&lt;/span&gt;)
  &lt;span style="color: #f0dfaf;"&gt;@safari&lt;/span&gt;.open_location(url)
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;

create_iterm_tab(&lt;span style="color: #cc9393;"&gt;"./script/server"&lt;/span&gt;)
create_iterm_tab(&lt;span style="color: #cc9393;"&gt;"./script/console"&lt;/span&gt;)
create_iterm_tab(&lt;span style="color: #cc9393;"&gt;"autotest"&lt;/span&gt;)
create_iterm_tab()
sleep(5)
launch_browser()
&lt;/pre&gt;



&lt;p&gt;
The sleep(5) is in there to give time for the server to spin up before
launching the browser.
&lt;/p&gt;
&lt;p&gt;
Now put all this in a file called "launch&lt;sub&gt;project&lt;/sub&gt;.command" on the
Desktop, and chmod +x it to allow it to allow it to execute when
double-clicked.
&lt;/p&gt;
&lt;p&gt;
I got some tips from &lt;a href="http://logaan.wordpress.com/2008/01/16/quicksilver-rails-project-opener-revisited/"&gt;Dribblings of a Deranged Hermit&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Happy New Year!
&lt;/p&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/YxV3bf_tCoI" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Fitting curves to data using Ruby and the GNU Scientific Library</title>
   <link href="http://blog.chrislowis.co.uk/2008/12/01/curve-fit-with-ruby-gsl.html" />
   <updated>2008-12-01T00:00:00+00:00</updated>
   <id>http://blog.chrislowis.co.uk/2008/12/01/curve-fit-with-ruby-gsl</id>
   <content type="html">&lt;p&gt;
In this post I'll show you how to use the &lt;a href="http://www.gnu.org/software/gsl/"&gt;GNU Scientific Library&lt;/a&gt; and
its &lt;a href="http://rb-gsl.rubyforge.org/"&gt;Ruby bindings&lt;/a&gt; to fit curves to data. This technique is useful if,
for example, you want to extrapolate into the future on the basis of
some past information.
&lt;/p&gt;
&lt;p&gt;
By way of example, your boss approaches you with some historic revenue
figures from your new Web 2.0 venture, and asks you to predict future
growth. Let's generate some example data to play with:
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;require &lt;span style="color: #cc9393;"&gt;'gsl'&lt;/span&gt;
time = &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;GSL&lt;/span&gt;::&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Vector&lt;/span&gt;.linspace(0,24,100)
revenue = &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;GSL&lt;/span&gt;::&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Vector&lt;/span&gt;.linspace(0,1,100).collect{|yi| yi+rand()/10}
&lt;/pre&gt;



&lt;p&gt;
In this code we're using the GSL Vector class to represent time. Here
we have a vector of months representing two years of data (24
months). The linspace method causes our vector to have 100 evenly
spaced elements between 0 and 24.
&lt;/p&gt;
&lt;p&gt;
We concoct some revenue data using GSL::Vector again. The GSL Vector
class does not implement all of methods found in Ruby's native array
class, but does have 'collect'. Here we create a random scattering of
points.
&lt;/p&gt;
&lt;p&gt;
Let's visualise this data first to see what we are dealing with. To do
this we have a number of options, here I'd like to show how we can use
Gnuplot to do the visualisation.
&lt;/p&gt;
&lt;p&gt;
First install the gnuplot gem:
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;$ gem install gnuplot
&lt;/pre&gt;



&lt;p&gt;
You'll need to have &lt;a href="http://www.gnuplot.info/"&gt;gnuplot&lt;/a&gt; installed to use the bindings. Binary
packages are available for many platforms, just make sure that gnuplot
is in your path after installation. OS X users should install &lt;a href="http://sourceforge.net/projects/aquaterm/"&gt;aquaterm&lt;/a&gt;
to allow plotting to a desktop window.
&lt;/p&gt;
&lt;p&gt;
Now let's plot the data generated above:
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;require &lt;span style="color: #cc9393;"&gt;'rubygems'&lt;/span&gt;
require &lt;span style="color: #cc9393;"&gt;'gnuplot'&lt;/span&gt;

&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Gnuplot&lt;/span&gt;.open &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;do&lt;/span&gt; |gp|
  &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Gnuplot&lt;/span&gt;::&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Plot&lt;/span&gt;.new( gp ) &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;do&lt;/span&gt; |plot|

    plot.title  &lt;span style="color: #cc9393;"&gt;"Company turnover"&lt;/span&gt;
    plot.xlabel &lt;span style="color: #cc9393;"&gt;"Month"&lt;/span&gt;
    plot.ylabel &lt;span style="color: #cc9393;"&gt;"Billions $"&lt;/span&gt;

    plot.data &amp;lt;&amp;lt; &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Gnuplot&lt;/span&gt;::&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;DataSet&lt;/span&gt;.new( [time.to_a, revenue.to_a] ) &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;do&lt;/span&gt; |ds|
      ds.with = &lt;span style="color: #cc9393;"&gt;"points"&lt;/span&gt;
      ds.notitle
    &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;

    plot.terminal &lt;span style="color: #cc9393;"&gt;"svg"&lt;/span&gt;
    plot.output &lt;span style="color: #cc9393;"&gt;"revenue.svg"&lt;/span&gt;
  &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
&lt;/pre&gt;



&lt;p&gt;
The code above generates the following graphic in SVG format.
&lt;/p&gt;


&lt;img src="/images/revenue.jpg" alt="revenue curve"&gt;&lt;/img&gt;

&lt;p&gt;
Gnuplot has a number of output formats, known as "terminals" to choose
from including one which plots straight to screen - great for rapid
exploration of data.
&lt;/p&gt;
&lt;p&gt;
Looking at the data, we see that a straight line drawn through the
points would be a good model for the growth in revenue. We can use
GSL's line-fitting tools to perform this fit for us:
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;(c0, c1, cov00, cov01, cov11, chisq, status) = &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;GSL&lt;/span&gt;::&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Fit&lt;/span&gt;::linear(time,revenue)
revenue_fit = (time * c1) + c0
puts c1
puts c0
&lt;/pre&gt;



&lt;p&gt;
The value of c1 is the growth rate per month, in this case around 0.04
Billion $ per month! We have used a linear fit here, but the GSL
provides &lt;a href="http://rb-gsl.rubyforge.org/fit.html"&gt;many&lt;/a&gt; &lt;a href="http://rb-gsl.rubyforge.org/nonlinearfit.html"&gt;other&lt;/a&gt; &lt;a href="http://rb-gsl.rubyforge.org/bspline.html"&gt;fitting methods&lt;/a&gt; for more complicated data. A quick
plot checks the goodness of our fit:
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;plot.data &amp;lt;&amp;lt; &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Gnuplot&lt;/span&gt;::&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;DataSet&lt;/span&gt;.new( [time.to_a, revenue_fit.to_a] ) &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;do&lt;/span&gt; |ds|
  ds.with = &lt;span style="color: #cc9393;"&gt;"lines"&lt;/span&gt;
  ds.notitle
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
&lt;/pre&gt;



&lt;p&gt;
Add this snippet of code to the plotting function above (after the
first plot.data and before the call to plot.terminal)
&lt;/p&gt;


&lt;img src="/images/fitted.jpg" alt="fit curve"&gt;&lt;/img&gt;

&lt;p&gt;
If you need to perform data analysis, provide graphics for your users
in your webapp, or produce high quality plots I encourage you to
investigate the combination of ruby, GSL and GNUPlot.
&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/94ql0gHVirk" height="1" width="1"/&gt;</content>
 </entry>
 
 <entry>
   <title>Implementing the Pearson correlation algorithm using Ruby and the GNU Scientific Library</title>
   <link href="http://blog.chrislowis.co.uk/2008/11/24/ruby-gsl-pearson.html" />
   <updated>2008-11-24T00:00:00+00:00</updated>
   <id>http://blog.chrislowis.co.uk/2008/11/24/ruby-gsl-pearson</id>
   <content type="html">&lt;p&gt;
At &lt;a href="http://rubymanor.org/"&gt;Ruby Manor&lt;/a&gt; on Saturday &lt;a href="http://www.eribium.org/blog/"&gt;Alex MacCaw&lt;/a&gt; gave a great introduction to his
&lt;a href="http://github.com/maccman/acts_as_recommendable/tree/master"&gt;acts_as_recommendable&lt;/a&gt; plugin for Rails. acts_as_recommendable
simplifies collaborative filtering for Rails models, automatically
generating recommended items, at an on-line store for example, based
on a database of user preferences.
&lt;/p&gt;
&lt;p&gt;
At its heart, acts_as_recommendable uses a statistical measure known
as the Pearson correlation coefficient to calculate the "nearness" of
items to one another. Alex talked about the performance issues he
encountered when implementing the algorithm in pure ruby. To allow
recommendations to be calculated for the entire database he had to
switch to making calculations offline and reimplementing the algorithm
in C using &lt;a href="http://rubyforge.org/projects/rubyinline/"&gt;RubyInline&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The &lt;a href="http://www.gnu.org/software/gsl/"&gt;GNU Scientific Library&lt;/a&gt; has an implementation of the Pearson
algorithm, and in this post I'd like to show how the Ruby code, or its
inline-C equivalent can be replaced with GSL code using Ruby bindings
to the GSL.
&lt;/p&gt;
&lt;p&gt;
My naive pure Ruby version of the algorithm looks like this:
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;def&lt;/span&gt; &lt;span style="color: #f0dfaf;"&gt;ruby_pearson&lt;/span&gt;(x,y)
  n=x.length

  sumx=x.inject(0) {|r,i| r + i}
  sumy=y.inject(0) {|r,i| r + i}

  sumxSq=x.inject(0) {|r,i| r + i**2}
  sumySq=y.inject(0) {|r,i| r + i**2}

  prods=[]; x.each_with_index{|this_x,i| prods &amp;lt;&amp;lt; this_x*y[i]}
  pSum=prods.inject(0){|r,i| r + i}

  &lt;span style="color: #708070;"&gt;# &lt;/span&gt;&lt;span style="color: #7f9f7f;"&gt;Calculate Pearson score
&lt;/span&gt;  num=pSum-(sumx*sumy/n)
  den=((sumxSq-(sumx**2)/n)*(sumySq-(sumy**2)/n))**0.5
  &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;if&lt;/span&gt; den==0
    &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;return&lt;/span&gt; 0
  &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
  r=num/den
  &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;return&lt;/span&gt; r
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
&lt;/pre&gt;



&lt;p&gt;
Here I should note that the acts&lt;sub&gt;as&lt;/sub&gt;&lt;sub&gt;recommendable&lt;/sub&gt; code is considerably
more complicated, however the heart of the calculation looks something
like the above. We can replace that with an inline C version using
something like:
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;require &lt;span style="color: #cc9393;"&gt;'rubygems'&lt;/span&gt;
require &lt;span style="color: #cc9393;"&gt;'inline'&lt;/span&gt;

inline &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;do&lt;/span&gt; |builder|
  builder.c &lt;span style="color: #cc9393;"&gt;'
    #include &amp;lt;math.h&amp;gt;
    double inline_pearson(int n, VALUE x, VALUE y) {
    double sum1 = 0.0;
    double sum2 = 0.0;
    double sum1Sq = 0.0;
    double sum2Sq = 0.0;
    double pSum = 0.0;

    VALUE *x_a = RARRAY(x)-&amp;gt;ptr;
    VALUE *y_a = RARRAY(y)-&amp;gt;ptr;

    int i;
    for(i=0; i&amp;lt;n; i++) {
      double this_x;
      double this_y;
      this_x = NUM2DBL(x_a[i]);
      this_y = NUM2DBL(y_a[i]);
      sum1 += this_x;
      sum2 += this_y;
      sum1Sq += pow(this_x, 2);
      sum2Sq += pow(this_y, 2);
      pSum += this_y * this_x;
    }
    double num;
    double den;
    num = pSum - ( ( sum1 * sum2 ) / n );
    den = sqrt( ( sum1Sq - ( pow(sum1, 2) ) / n ) *
          ( sum2Sq - ( pow(sum2, 2) ) / n ) );
    if(den == 0){
      return 0.0;
    } else {
      return num / den;
    }
   }'&lt;/span&gt;
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
&lt;/pre&gt;



&lt;p&gt;
Which is a considerable amount of code. I love the fact that this code
can be embedded directly in the Ruby source code but, as was pointed
out to me, for some people this would be seen as something of a
maintenance nightmare. If you're prepared to install the pre-requisite
GSL library and its &lt;a href="http://rb-gsl.rubyforge.org/"&gt;Ruby bindings&lt;/a&gt; you can actually replace all of the
above code with the simple:
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;require &lt;span style="color: #cc9393;"&gt;'gsl'&lt;/span&gt;

&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;def&lt;/span&gt; &lt;span style="color: #f0dfaf;"&gt;gsl_pearson&lt;/span&gt;(x,y)
  &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;GSL&lt;/span&gt;::&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Stats&lt;/span&gt;::correlation(
    &lt;span style="color: #dfdfbf; font-weight: bold;"&gt;GSL&lt;/span&gt;::&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Vector&lt;/span&gt;.alloc(x),&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;GSL&lt;/span&gt;::&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Vector&lt;/span&gt;.alloc(y)
  )
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
&lt;/pre&gt;



&lt;p&gt;
In this code, the &amp;lt;verb&gt;GSL::Vector.alloc()&amp;lt;/verb&amp;gt; method converts a
Ruby Array to a GSL Vector class. We then call the correlation method,
helpfully provided by the &lt;a href="http://rb-gsl.rubyforge.org/stats.html"&gt;Statistics&lt;/a&gt; portion of the GSL.
&lt;/p&gt;
&lt;p&gt;
So, how does this perform ? A quick benchmark :
&lt;/p&gt;



&lt;pre class="src src-ruby"&gt;require &lt;span style="color: #cc9393;"&gt;'benchmark'&lt;/span&gt;

n = 100000
x = []; n.times{x &amp;lt;&amp;lt; rand}
y = []; n.times{y &amp;lt;&amp;lt; rand}

&lt;span style="color: #dfdfbf; font-weight: bold;"&gt;Benchmark&lt;/span&gt;.bm() &lt;span style="color: #f0dfaf; font-weight: bold;"&gt;do&lt;/span&gt; |bm|
  bm.report(&lt;span style="color: #cc9393;"&gt;"Ruby:"&lt;/span&gt;) {ruby_pearson(x,y)}
  bm.report(&lt;span style="color: #cc9393;"&gt;"GSL:"&lt;/span&gt;) {gsl_pearson(x,y)}
  bm.report(&lt;span style="color: #cc9393;"&gt;"Inline:"&lt;/span&gt;) {inline_pearson(n,x,y)}
&lt;span style="color: #f0dfaf; font-weight: bold;"&gt;end&lt;/span&gt;
&lt;/pre&gt;



&lt;p&gt;
Gives some indicative results :
&lt;/p&gt;
&lt;table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"&gt;
&lt;caption&gt;&lt;/caption&gt;
&lt;colgroup&gt;&lt;col class="left" /&gt;&lt;col class="right" /&gt;&lt;col class="right" /&gt;&lt;col class="right" /&gt;&lt;col class="left" /&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th scope="col" class="left"&gt;&lt;/th&gt;&lt;th scope="col" class="right"&gt;user&lt;/th&gt;&lt;th scope="col" class="right"&gt;system&lt;/th&gt;&lt;th scope="col" class="right"&gt;total&lt;/th&gt;&lt;th scope="col" class="left"&gt;real&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td class="left"&gt;Ruby:&lt;/td&gt;&lt;td class="right"&gt;1.530000&lt;/td&gt;&lt;td class="right"&gt;0.020000&lt;/td&gt;&lt;td class="right"&gt;1.550000&lt;/td&gt;&lt;td class="left"&gt;(1.544765)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="left"&gt;GSL:&lt;/td&gt;&lt;td class="right"&gt;0.010000&lt;/td&gt;&lt;td class="right"&gt;0.000000&lt;/td&gt;&lt;td class="right"&gt;0.010000&lt;/td&gt;&lt;td class="left"&gt;(0.015925)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="left"&gt;Inline:&lt;/td&gt;&lt;td class="right"&gt;0.000000&lt;/td&gt;&lt;td class="right"&gt;0.000000&lt;/td&gt;&lt;td class="right"&gt;0.000000&lt;/td&gt;&lt;td class="left"&gt;(0.004115)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;


&lt;p&gt;
While the Inline version in this example outperforms the GSL version,
both offer considerable savings on the Ruby version. One of the real
advantages of the GSL is it allows you to rapidly experiment with
alternative implementations of an algorithm. Also you can be safe in
the knowledge that your code is based on a well-tested library of
scientific functions.
&lt;/p&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;img src="http://feeds.feedburner.com/~r/ChrisLowis/~4/BIThI6CXLcA" height="1" width="1"/&gt;</content>
 </entry>
 
 
</feed>

