mysqlguy.net

ruby

Ruby Succinctness competition

For some reason I never was that excited about trying to accomplish these sorts of things in Perl:

1..rand(256)).inject("") {|string,n| string + ('a'..'z').to_a[rand(25)] }

This generates a string from 1 to 256 characters long, containing random letters from 'a' to 'z'.  

Normally, I wouldn't use something that's quite so unreadable, but I'm starting to like Ruby's way of taking what should be a very simple operation that I might have done in 3-5 lines in Perl and boiling it down to a single line.

I'd love to see if anyone can make this more succinct (but one line is still a requirement!)

Here's the code in it's context. It's just a test script writing into my partition table every minute so I can verify my Events from previous posts are working correctly.

MySQL

Yahoo

Recent comments

About Me

Jay Janssen
Yahoo!, Inc.
jayj at yahoo dash inc dot com

MySQL
High Availability
Global Load Balancing
Failover

View Jay Janssen's LinkedIn profileView Jay Janssen's Facebook profile

User login

Friends

  • Super Geeky: Removing Subversion files from a directory with Windows Powershell
  • Sliding content from a partial height with jQuery.
  • Accessing Google Spreadsheet with PHP
  • Magento: Jump back to Payment Screen when Payment Declined
  • Laptop cooling stand – Keep your lap cool
  • Pattern Tap: We dig Jay because we got Dugg and not buried
  • How To: Build a Custom Ergonomic Computer Desk
  • New Times… New Desk
  • Google Adds Another Search Tool
  • Selling a Great Car: 1995 Honda Accord EX Wagon

Links