Monday, October 31, 2011

Creating a Random String in Ruby

Every once in a while I want to create a totally random password that is not necessarily readable nor pronounceable. I decided to tinker around in Ruby and see what I could come up with. This isn't perfect by any means, and I'm definitely open to suggestions - I'd like to make it more accurate by specifying how many of each character types to include (I tried, but couldn't get it accurate yet). That'll be work for another night, but it was fun playing with it, and here is what I have gotten so far:

Sunday, October 30, 2011

Using jQuery with Rails 3.0

I've been working on a little Rails app that is based on Michael Hartl's Ruby on Rails Tutorial. I'm going back now (after some customization) and adding new functionality to the code. One of the exercises  in the book was to add a simple JavaScript counter to the micropost textbox.

I decided to go with jQuery and found the implementation to be quite simple. First you need to install jQuery in Rails, and you can find instructions on how to do this here.


Once jQuery was installed, I simply had to add the jQuery code to my form, as well as modify the original form code to limit the characters to 140 with f.text_area :content, :maxlength => 140 :




Just for reference, the original code for the form (without the textbox countdown) was as follows:



Feel free to use or modify this code if you found it helpful to you!

Wednesday, October 19, 2011

Ruby and Ruby on Rails Online Learning Resources

I've been in sponge mode for a little while now trying to absorb as much information about Ruby and Ruby on Rails as possible. The great thing about an open source platform like RoR, is that there is an abundance of information available online. I know both Ruby and RoR are getting more and more popular, so I though I would share a few of the resources I have found useful.

First up, is Michael Hartl's Ruby on Rails Tutorial. This has to be hands down, the single most useful and helpful Rails guide anywhere. I plan to buy the book as well, even though the material is the same as the online tutorial, I like books, they make me feel smarter, and I really want to support the author of this great tutorial. Simply put, if you are interested in Rails programming, and don't follow any other link on this post, check this one out (or better yet, support Michael by buying the book!). Michael gives solid code examples, and teaches you to not only code an application, but code tests for the application as well, following the Red, Green, Refactor paradigm of Test Driven Development. You will develop solid habits here.

Next up, is TryRuby.org. This is a great little site that runs you through a nice little tutorial around the Ruby language using a browser based Ruby console. Although if you want to be a Rails developer you need to know Rails along with Ruby, it doesn't hurt to have as strong of a background in the Ruby language as possible. A few other Ruby resources are the Ruby Programming Wikibook and the Ruby User's Guide. These guides and others are linked from the documentation page on ruby-lang.org. One that I would like to mention specifically is Why's (Poignant) Guide to Ruby which is the single most enjoyable piece of technical documentation I have ever read. Another great interactive Ruby guide is RubyMonk, and I wanted to include it here since it's not on ruby-lang.org's Documentation page at this time.

A few more Rails specific resources are, of course, the Rails Wiki, The Meshplex Ruby and Ruby on Rails Tutorials and Rails for Zombies which is availible free from codeschool.com.

Also, no arsenal of online Rails information would be complete without a bookmark to railscast.com's Ruby on Rails Screencasts. These screencasts are searchable, and can help you find answers to many programming problems, and can help you overcome "coders block" when looking for ways to create an efficient solution.

Good luck to everyone on the journey of learning Ruby and Ruby on Rails, and I hope this little collection of links helps you as much as they have helped me. Obviously I haven't completed all of the tutorials (except Michael Hartl's), nor have I read through all of the documentation sites, but I continue to work toward expanding my knowledge nearly every night.

Saturday, October 1, 2011

More thoughts on Vim as a Rails Editor

I'm still using Vim as my editor for Rails development. After doing some more research on things I could do to make it more Rails-centric, I came across this post which gave me some additional ideas, and settings I could snag for my own .vimrc file, which is below:



Also, note that I am using the 'vividchalk' color scheme which isn't installed by default (at least on Ubuntu/Xubuntu), so you can download it here if you'd like to use it as well. Also, I am using the Ubuntu Mono font (in 11pt) as my default GUI font, if you'd like to try it (it's awesome) and aren't running a current Ubuntu Linux distribution, you can download it here (I use it on my Mac as well).

Don't take my settings as right for you though, read through the blog linked above to decide what settings would be right for you.