citizen428.blog()

Try to learn something about everything

Review: Meet MacRuby (PeepCode Screencast)

This afternoon I had the time to finally watch the PeepCode Meet MacRuby screencast.

In case you don’t know MacRuby, it’s a Ruby interpreter sitting on top of Objective-C and OS X core technologies (see also here).

During the 74 minute screencast you will build a basic but functional Twitter client, and in the process learn about MacRuby and Cocoa basics, using Xcode and InterfaceBuilder to develop and bundle your application and many other interesting topics.

The screencast is very well structured, easy to follow and full of good and practical information, including perks and rough edges of the current MacRuby version. All in all a really enjoyable and informative video, which is well worth US$9 (or less if you buy packs of credits)!

Review: Ruby in Practice (Manning Publications)

I read Ruby in Practice for the upcoming book promotion on RubyLearning, and I have to say it’s a pretty neat book which will be well worth your time and money. Over the course of 360 pages Jeremy McAnally and Assaf Arkin tackle lots of different topics of interest to developers. The book is structured in 3 main parts:

  • Ruby techniques: Gives a general introduction to Ruby’s strength (which sometimes reads as a bit of a sales pitch), BDD and TDD, as well as scripting with Ruby (including OLE and OSA).
  • Integration and communication: This part covers Rails, web services in general (HTTP, REST, SOAP), automating communication with email and IM, asynchronous messaging and deployment options.
  • Data and document techniques: This part talks about databases, structured text, authentication, searching, indexing and document processing.

Chapters usually present the reader with a problem, then show an example solution which usually makes good use of existing libraries and then finish with further discussion on the topic (alternative ways to implement it, pitfalls in using the shown solution in “real life” scenarios etc.). For people with previous knowledge of Ruby this book is a good read, which shows how the dynamic nature of the language combined with the quite big amount of readily available libraries enable developers to quickly and efficiently find solutions to common problems. I sometimes do have minor quirks with some of the code, but that’s just personal preferences and being nitpicky. All in all it’s a very solid book which I enjoy quite a lot.

Create Your Own (Ruby) API Browser in 3 Easy Steps

  • Step 1: Download Fluid, an awesome little application to create site specific browsers.
  • Step 2: Find some online API documentation. For Ruby I recommend railsapi.com or RubyBrains.
  • Step 3: Create your app in Fluid:
  • Fluid

Here’s an example screenshot of a site specific browser for RubyBrain.com:

Fluid RubyBrain

Of course this still requires you to have a working internet connection, but you could always use a local version of the API docs when creating the app. On a related note you should also check out Goo which is a nice alternative to gem server on OS X.

A TextMate Command for the RubyLearning Forums

As we all know posting code to Moodle (the software that powers RubyLearning) can be a bit cumbersome. I therefore created a TextMate command which will

  • take the currently active file
  • replace all occurrences of < with the HTML-entity
  • wrap all of that in [code ruby] tags and
  • copy it to the clipboard, ready to be pasted into the forums.

Source:

Download:
RubyLearning.tmCommand

I’m in Your Pi, Crunching Your Numbers ;-)

From Ruby Quiz #202:

And sometimes the fastest code is the code you don’t write. Michael Kohl’s solution:

1
2
3
4
5

1
2
3
4
5
<span class='line'><span class="nb">require</span> <span class="s1">&#39;rubygems&#39;</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">&#39;hpricot&#39;</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">&#39;open-uri&#39;</span>
</span><span class='line'><span class="n">doc</span> <span class="o">=</span> <span class="no">Hpricot</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="s1">&#39;http://www.eveandersson.com/pi/digits/100000&#39;</span><span class="p">))</span>
</span><span class='line'><span class="nb">puts</span> <span class="p">(</span><span class="n">doc</span><span class="o">/</span><span class="s1">&#39;pre&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">inner_html</span>
</span>

It finishes in less than one second for the entire 100,000 digits!

And no, this wasn’t a serious submission… :-)

Clever Documentation

Playing with Squeak‘s Method Finder, I discovered a really neat feature that I wish would be available for Ruby documentation. Here’s the description from the built-in help:

[…] use an example to find a method in the system. Type receiver, args, and answer in the top pane with periods between the items. 3. 4. 7

Yes, this means that if you want to know how to do modulo in Smalltalk, you can open the Method Finder, type 7. 3. 1 and see that the answer is Number>>\, whereas ‘abc’ . ‘ABC will tell us about String>>asUppercase.

Reading Frenzy

Since my reading time wasn’t influenced by distracting things like work or studies last year, I managed to read 69 books since end of April 2008, which quite likely is a new personal record for one year. Here’s the complete list, some of this books I had wanted to read forever, some others were just lucky finds and yet others were just…finds. ;-)

Marion Molteno: “A Language in Common”
James Frey: “A Million Little Pieces”
Haruki Murakami: “After Dark”
Haruki Murakami: “After the Quake: Stories”
Ali Smith: “Ali Smith’s Supersonic 70s”
Lewis Carroll: “Alice’s Adventures in Wonderland”
Neil Gaiman: “American Gods”
Heinrich Böll: “Ansichten Eines Clowns”
Anita Desai: “Baumgartner’s Bombay”
Achmat Dangor: “Bitter Fruit”
Monica Ali: “Brick Lane”
Heinz Peter Schwerfel: “Buenos Aires intensiv.: Tango urbano – Stadt im Aufbruch”
Ines Rieder: “Cosmopolis: Urban Stories by Women”
Andrea Camilleri: “Der Hund aus Terracotta”
Peter Handke: “Die Angst des Tormanns beim Elfmeter”
Thomas Mann: “Die Betrogene. Erzählungen 1940 – 1953.”
Helge Schneider: “Die Memoiren des Rodriguez Fazantas”
Stanislaw Lem: “Eine Minute der Menschheit.”
Orson Scott Card: “Ender’s Game”
Terry Pratchett: “Equal Rites”
Jonathan Safran Foer: “Everything Is Illuminated”
Feridun Zaimoglu: “German Amok.”
Terry Pratchett & Neil Gaiman “Good Omens”
Haruki Murakami: “Hard-Boiled Wonderland and the End of the World”
Irvine Welsh: “If You Liked School, You’ll Love Work”
Andre Brink: “Imaginings of Sand”
Orhan Pamuk: “Istanbul”
Gene Brewer: “K-Pax”
Haruki Murakami: “Kafka on the Shore”
Peter Handke: “Kali”
Feridun Zaimoglu: “Leinwand”
Yann Martel: “Life of Pi”
William Golding: “Lord of the Flies”
Elfriede Jelinek: “Lust”
Ryszard Kapuscinski: “Meine Reisen mit Herodot”
Saul Bellow: “Mosby’s Memoirs and Other Stories”
Howard Marks: “Mr. Nice: An Autobiography”
Orhan Pamuk: “My Name Is Red”
Eli Gottlieb: “Now You See Him: A Novel”
John Steinbeck: “Of Mice and Men”
Amit Gilboa “Off the Rails in Phnom Penh”
Terry Pratchett: “Pyramids”
Paul Torday: “Salmon Fishing in the Yemen”
Woody Allen: “Side Effects”
Miriam Tzali: “Soweto Stories”
Helen Oyeyemi: “The Icarus Girl”
John Updike: “Terrorist: A Novel”
Jorge Luis Borges: “The Aleph”
Zadie Smith: “The Autograph Man”
Alex Garland: “The Beach”
Iain M. Banks: “The Crow Road”
John Case: “The Eighth Day”
Paul Theroux: “The Elephanta Suite: Three Novellas”
Shan Sa: “The Girl Who Played Go”
Leon Uris: “The Haj”
Michael Cunningham: “The Hours”
Miguel de Cervantes: “The Jealous Extremaduran”
Terry Pratchett: “The Last Continent”
A. B. Yehoshua: “The Lover”
Ernest Hemingway: “The Old Man and The Sea”
M. C. Beaton: “The Quiche of Death”
Audrey Niffenegger: “The Time Traveler’s Wife”
Roddy Doyle: “The Van”
H.G. Wells: “The War of the Worlds (Penguin Classics)”
Iain M. Banks: “The Wasp Factory: A Novel”
Aravind Adiga: “The White Tiger: A Novel”
Terry Pratchett: “Thud!”
Zadie Smith: “White Teeth: A Novel”
Florian Weber: “You’ll Never Walk Alone. Ein Fussballmusikroman”

And that’s the 2 books I’m currently reading:

Nancy L. Clark: “South Africa: The Rise and Fall of Apartheid”
Will Ferguson: “Hokkaido Highway Blues”

Learning Haskell

To get my mind off Ruby I recently started dabbling in Haskell. I really like what I’ve seen so far and it seems I’m finally starting to understand functional programming (my two attempts with Practical Common Lisp never got past the first few chapters).

In case you are interested in Haskell too, here’s a list of the resources I use:


  • Haskell :: Functional Programming with Types: A very nice Wikibook covering a wide range of topics from the very basics to Monads, Arrows and Zippers.

  • Learn You a Haskell for Great Good: A nice and colorful tutorial in the spirit of Why’s (Poignant) Guide to Ruby

  • Real World Haskell: Yes, the entire book can be read online (including per paragraph comments!) for free! I’ve only just started reading this, since I first want to brush up my basic Haskell a bit, but once I’m past the Project Euler stage this is probably gonna be very nice.

  • Write Yourself a Scheme in 48 Hours: Now that I’m slowly getting the hang of this functional programming thing, why not write an interpreter for one functional language in another? “Along the way, you’ll learn Haskell’s I/O, mutable state, dynamic typing, error handling, and parsing features. By the time you finish, you should be fairly fluent in both Haskell and Scheme”. Sounds good to me! :)

Enumerable#filter

Update: Thanks to some feedback I rewrote Enumberable#filter so it doesn’t use ‘eval’. It’s a bit less flexible now and I also like the syntax less, but at least it doesn’t eat puppies for breakfast. As the disclaimer said, maybe it was a bad idea to begin with.

As much as I like Ruby, some constructs I just don’t find too sexy, e.g.:

1

1
<span class='line'><span class="o">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">9</span><span class="p">,</span><span class="mi">5</span><span class="o">].</span><span class="n">select</span> <span class="p">{</span> <span class="o">|</span><span class="n">x</span><span class="o">|</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="mi">5</span> <span class="p">}</span>
</span>

That’s why I came up with an alternative solution which I find reads nicer than the above code:

(Sorry, I really don’t care much about having this for strings)

I kinda got inspired by Martin Aumont’s every, which allows us to use

1

1
<span class='line'><span class="n">enum</span><span class="o">.</span><span class="n">every</span><span class="o">.</span><span class="n">floor</span>
</span>

instead of

1
2
3

1
2
3
<span class='line'><span class="n">enum</span><span class="o">.</span><span class="n">map</span> <span class="p">{</span><span class="o">|</span><span class="n">n</span><span class="o">|</span> <span class="n">n</span><span class="o">.</span><span class="n">floor</span> <span class="p">}</span>
</span><span class='line'><span class="ow">or</span> <span class="k">in</span> <span class="mi">1</span><span class="o">.</span><span class="mi">8</span><span class="o">.</span><span class="mi">7</span> <span class="ow">or</span> <span class="mi">1</span><span class="o">.</span><span class="mi">9</span><span class="o">.</span><span class="mi">1</span>
</span><span class='line'><span class="n">enum</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="o">&amp;</span><span class="ss">:floor</span><span class="p">)</span>
</span>

Disclaimer: Today this seems like a pretty good idea, but I also haven’t slept much. In case this breaks in horrible ways, already exists in some other form or is stupid for some other reason I’m too tired to consider, please let me know.

Copyright © 2016 - Michael Kohl - Powered by Octopress