Rails Reading - November 1, 2009

Dreamland Welcomes You

Git Magic

As Arthur C. Clarke observed, any sufficiently advanced technology is indistinguishable from magic. This is a great way to approach Git: newbies can ignore its inner workings and view Git as a gizmo that can amaze friends and infuriate enemies with its wondrous abilities.

Rather than go into details, we provide rough instructions for particular effects. After repeated use, gradually you will understand how each trick works, and how to tailor the recipes for your needs.

paperplanes. How To Redis

The simplest way is to just use the redis-rb library and talk to Redis almost directly. That’s quite low level compared what you’re used to with ActiveRecord though. Hurl wraps most of the convenience stuff into a neat class Model that implements basic functionality like saving, validating and handling identifiers.

Ohm takes it the next level, adding more complex validations, integrating the Redis data types as top level class attributes, and even handling associations for you. It’s serious awesomesauce, and the implementation is quite simple too. It even supports having indexes on attributes you want to query for, updating them transparently for you as you create new objects or update existing ones.

Thinking Sphinx RSpec Matchers - blah blah woof woof | tim riley

How do you use RSpec to drive the design of your models that will use Thinking Sphinx for search? Say you’re already using Cucumber for integration tests to verify your index builds correctly and searches return the results you expect. For your models’ specs, you’ll want something that is lighter but doesn’t sacrifice your overall test coverage.

To achieve this, I wrote a couple of small RSpec matchers that inspect the Thinking Sphinx index object on your model to ensure that it contains the fields and attributes that you expect.

Intro to Ruby - Twin Cities Code Camp 7

Slides from Brian Hogan’s “Introduction to Ruby” talk at Twin Cities Code Camp 7

Videos tagged ‘nosqlberlin’ on Vimeo

Six videos from NoSQL berlin covering CouchDB, Redis and such.

Free result after using ActiveRecord::Base.connection.execute · Fingertips

Just a quick warning: when you use ActiveRecord::Base.connection.execute you get a Mysql::Result instance, this is a very thin wrapper around the actual result returned from libmysqlclient. This means you have to free the memory of the result table, failing to do so will result in erratic query times because somewhere a garbage collector will do it for you.

Executing SQL commands in Rails [Snippet] « elc technologies

I had to figure out a database’s timezone and schema but I had no shell access to the server. So I ran this used Base.connection.execute and fetch_row to get the result

q=ActiveRecord::Base.connection.execute ‘SELECT NOW();’

=> #

>> q.fetch_row

=> ["2009-10-20 17:30:49"]

>> Time.now

=> Tue Oct 20 10:32:02 -0700 2009

You can basically run any SQL query you want with these two methods. Now go crash some servers!

Improving Code using Metric_fu – The Devver Blog

Often, when people see code metrics they think, “that is interesting, I don’t know what to do with it.” I think metrics are great, but when you can really use them to improve your project’s code, that makes them even more valuable. metric_fu provides a bunch of great metric information, which can be very useful. But if you don’t know what parts of it are actionable it’s merely interesting instead of useful.

Paul Dix Explains Nothing: Typhoeus, the best Ruby HTTP client just got better

‘ve been quietly working on Typhoeus for the last few months. With the help of Wilson Bilkovich and David Balatero I’ve finished what I think is a significant improvement to the library. The new interface removes all the magic and opts instead for clarity.

It’s really slick and includes improved stubing support, caching, memoization, and (of course) parallelism. The Typhoeus readme highlights all of the awesomeness. It should be noted that the old interface of including Typhoeus into classes and defining remote methods has been deprecated. I’ll be removing that sometime in the next six months.

Rails in a Nutshell

Rails in a Nutshell is a concise introduction to Rails, an overview of commands and configurations, and a guide to the parts of Rails you’ll be using every day.

Full of examples and explanations, this book kicks your skills into high-gear by showing you how to take advantage of the Model-View-Controller concept with tiny but expressive bits of Ruby that power some of the world’s biggest and fastest web services.

Fast to launch and a pleasure to get there are hallmarks of working with Rails. Rails in a Nutshell gets the right stuff in your hands quickly and without fuss, so you can experience it yourself.

Astrails Let my controller go or useful impurity in software design.

It would be nice if @articles.to_xml just worked, but then how will you generate the href url? url_for is not available in models.

Solution? just make it global and let the purists tear their hairs out! :)

This plugin solves the issues above by making the current controller available from a global function current_controller. (actually it uses Thread local storage, so it will work even in multithreaded Rails environment)

paperplanes. There’s Something About Redis

One “movement” (if you can even call it that) is NoSQL. I’ve never been particularly happy with relational databases, and I happily dropped MySQL and the like when an opportunity to work with something entirely new came up. Since it’s my own project I’m not putting anything at risk, and I don’t regret taking that step. We’re working with two members of the NoSQL family in particular, CouchDB and Redis.

Last week people interested in and people working with and on these new and pretty fascinating tools came together for the first NoSQL meetup in Berlin. I talked about Redis, and before I keep blabbering on about it, here are my slides. The talks have been filmed, so expect an announcement for the videos soon-ish.

japh(r): “Newbie” Feedback

I recently had the privilege to supply the challenge for the second ever Ruby Programming Challenge For Newbies. I thought it pretty cool that the challenge provoked 40+ “newbies” to submit responses. As one might expect, there was some rough Ruby, but very few butcherings of the language.

In the spirit of the code review, I tried to provide constructive feedback to all participants. Following is a summary of some common suggestions that I had to offer…

Good Ruby Times [Article] « elc technologies

Doing the travelling codes-man like that is a golden opportunity to see what people’s stumbling blocks are and how a few easy tricks can improve the code substantially. What follows is not your new cutting edge coffe making kitchen sink script-fu, but a rather dull list of everyday Ruby that I learned people need to learn.

Talk Like A Duck : It’s the Little Things

Prior to Ruby 1.9 Array#to_s was a synonym for Array.join which resulted in the concatenation of the results of sending to_s to each element. In Ruby 1.9 Array#to_s is the same as Array#inspect.

This has had a tendency to produce subtle problems which are at time hard to track down. Once they are found, the solution is to do something like changing:

“Whatever #{some_array}”

to:

“Whatever #{some_array.join}”

ISO8601 Dates in Ruby | Virtuous Code

ISO8601 is a standard for representing date/time information as a string. ISO8601 dates look like this: 2009-10-26T04:47:09Z.

There are a lot of good reasons to store dates in the ISO8601 format. The format is…

* Unambiguous. There is never any question how to interpret them.

* Human-readable. You can look at dates stored in ISO8601 and interpret them easily.

* Widely-supported. All major programming languages have libraries for parsing and writing ISO8601 dates.

* Sortable. If you follow a few simple rules, ISO8601 dates sort lexicographically into the order you would expect.

Jetpack Flight Log » Rails 2.3.4 and SWFUpload – Rack Middleware for Flash Uploads that Degrade Gracefully

Browser upload controls have been pretty much the same for years. They are very difficult to style, and do not look consistent across browsers. Perhaps the biggest issue with them is they provide no feedback to the user about how long the submission will take. One alternative is to use Flash for the uploads. There are numerous libraries available, I like SWFUpload. Since the reason you are here is probably because you can’t get it working in Rails, I’m going to try and help you deal with the quirks associated with using Flash and Rails together.

Ruby Best Practices - The Complete Class

here are some basic concepts (often called “aspects”) that need to be implemented for many classes although not all classes need all (or even any) of them:

* initialization

* conversion to a printable string

* equivalence

* hash code calculation

* comparability

* cloning (clone and dup)

* freezing

* customized persistence (Marshal and Yaml)

* matching

* math and operator overloading

Teach Me To Code - Ruby Essentials — blocks

20 minute video covering Ruby blocks

Cross-platform development with JRuby and Swing

In addition to building Web and console applications with Ruby, you can write complex GUI desktop applications that run unmodified on multiple platforms. Thanks to JRuby, a robust alternative to the traditional C implementation of Ruby, Ruby GUI toolkits can use UI tools available to the Java™ platform. This article introduces Monkeybars, a library that uses JRuby and Swing for building applications, and takes you through an example application.

(re)-Introducing simple_importer | Viget Extend

The end result is a gem that makes CSV import tasks easy to create and manage, and hopefully provides some real-world examples of basic Ruby metaprogramming.

The basic use case starts with defining importers using a small internal DSL. Each importer has a name, a csv file, and a block of code that is used to process each row in the file. The row instance that is passed into the block is a fastercsv row and all of the fastercsv configuration options are available.

InfoQ: Dr Nic Williams on Sustainable Ruby Open Source Development

Dr Nic Williams talks about his Ruby open source contributions (TextMate bundles, newgem,…), and how he manages to keep his many open source projects alive while still having a life.

Simplifying your Ruby on Rails code: Presenter pattern, cells plugin | Dmytro Shteflyuk’s Home

Today we will talk about code organization in Ruby on Rails projects. As everybody knows, Ruby on Rails is a conventional framework, which means you should follow framework architects decisions (put your controllers inside app/controllers, move all your logic into models, etc.) But there are many open questions around those conventions. In this write-up I will try to summarize my personal experience and show how I usually solve these problems.

litany against fear ¤ by nick quaranto ¤ Gem Bundler is the Future

Yehuda has a great roundup of what can be done (and has been done with the bundler) on his blog. This is going to be a part of Rails 3, so youre going to have to run into this sooner or later. I was getting frustrated with managing gem dependencies in Gemcutter, so now its bundled up and ready as a decent example of the bundler in action.

Adobe® BrowserLab

Making Deep Copies in Ruby

It’s often necessary to make a copy of a value in Ruby. While this may seem simple, and it is for simple objects, as soon as you have to make a copy of a data structure with multiple array or hashes on the same object, you will quickly find there are many pitfalls.

Multiple rubygems versions, GEM_HOME and GEM_PATH « format internet:

Installing rubygems is failrly easy and it’s great to have a package manager so you can forget about manually installing and upgrading the components you use. After installing a gem, you can require it from any ruby script and use it hassle-free. Well, given your ruby interpreter can find it.

extending self in a module

Statement extend self is an executable statement. When module is being loaded then self if the moduel itself. So that’s like saying extend Say. And that’s what happens. When a module extends another module then first module gets to invoke all the instance methods of the other module. That’s how in this case Say module is able to invoke method bar .

http://ruby-metaprogramming.heroku.com/

First Step on Ruby Metaprogramming course notes

Using Selenium with Webrat and Cucumber | BDDCasts - BDD Screencasts with Cucumber, RSpec and Ruby on Rails

How to use Webrat and Selenium to test the

parts of your application that rely on AJAX or some form of Javascript interaction

with the user.

Ajaxian » The State of Developer Tools

In this session, co-founder of Ajaxian.com, and The Ajax Experience conferences, and now head of Mozilla Foundation’s new Tools team Ben Galbraith will take us on an expedition through the developer tools landscape. Learn what’s out there, and what they can do to make you more productive, your sites and applications better and faster, and your life as a developer more enjoyable.

Software Craftsmanship – Katas » Number to LCD

My inaugural code kata is the venerable Ruby Quiz #14: LCD Numbers. This is a fun exercise, as it exists it two distinct parts: single-digit and multi-digit. I appreciate the natural move between them, and I often find myself focusing on one side or the other, starting from scratch and working until I have single-digit support, or starting with single-digit already working and moving to multi-digit.

StackOverflow cool Ruby questions 2 - Khaled alHabache’s official blog

let’s proceed to questions:

Hash Autovivification

Hash Autovivication in simple words is the ability to do things like:

3 Ruby Quirks You Have to Love | Engine Yard Blog

Ruby’s a fantastic language; we love it because it’s flexible, readable and concise, to name just a few reasons. The Ruby language is also incredibly complex as far as language syntaxes (grammar) are concerned. This sometimes leads to some dark seedy corners… but by examining the stranger aspects of Ruby’s syntax, it helps us to better understand the power of Ruby. This entry will show some of the stranger aspects of the language and reflect on how we rarely see these used in real life.

has_many :bugs, :through => :rails: Railssummit Slides

Here are the slides of my presentation at Railssummit 2009. Huge thanks to Locaweb and Fabio Akita for organizing the conference and having me there.

My talk was about Rails focused tips/tricks.

Emphasized Insanity: STI best practices in Rails

Single Table inheritance. Lot’s of developers i talk to seem to hate the concept of STI and claim that it’s “java-ish” and something that should be avoided on all costs. Generally i would spend me time explaining to that person why STI is a legitimate design pattern which can be useful and correct when being used in the right place and not as a “super solution for everything”, but a recent post named The Rails Code Quality Checklist recently bashed STI and surprisingly (imo, at least) got pretty good responses from people around.

Video: Sinatra at Boston.rb, part 1 - GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS

This the first in a series of short videos. They feature Blake Mizerany discussing Sinatra and Heroku in great technical detail at September’s Boston.rb.

Rails deployment made easy with Inploy | Diego Carrion

After working in some systems made in Rails, Capistrano became one of the things that began to bother me more and more. I tried to find other alternatives, including Vlad, but none satisfied me, so I decided to create a solution and called it Inploy.

BBC - Web Developer: CSS Resets

When investigating them for Barlesque, we pretty quickly decided a reset would be of overall benefit to developers on bbc.co.uk: we have a lot of browsers to support and zeroing everything would get rid of those inconsistent default values, like paragraph margins for example, that different browsers have. Also, with so many developers swapping code, moving around the business, debugging each others work and so on, it would be a big win to have everyone’s stuff starting from the same known base.

Relevance Blog : The Power of Names

So if we can deal with non-optimal names just fine, and choosing good names is really difficult, it hardly seems worth it. But good programmers understand the value of names. This story illustrates how hard it can be to find just the right name, and also how good names can help you to understand your own program and domain in deeper ways.

dude :composed_of => [:software, :music, :stuff]: Ruby Chops: rubyisms 2 with metaprogramming examples

dude :composed_of => [:software, :music, :stuff]: Code Kata: Simple Content Tag

In this video I test drive code to build a simple content tag class. This was presented at Spokane/CDA Ruby User Group on Oct 7th, 2009. Enjoy!

WNYC - Radiolab: Sperm (November 21, 2008)
Finally somebody points out how obnoixious “Only in America” is.
2009-01-03 - Today’s Ruby/Rails Reading
2009-02-13- Today’s Ruby/Rails Reading

This entry was posted on Sunday, November 1st, 2009 at 12:24 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.