5 Simple Ways To Keep Up With The Rails Community

Update: There are some great suggestions in the comments as well.

There’s a lot going on in the world of Rails these days.  This is great for developers, but sometimes it can be difficult to keep up with all latest happenings in the community.  In addition to changes in Ruby 1.9 and Edge Rails, there’s a constant stream of news with regards to well-known Rails projects, emerging plugins and development/coding strategies.

Below are a few resources I use to stay up-to-date without experiencing information overload:

  1. RubyFlow.com - This relatively new site is a great way to quickly see daily Rails news.  It was built by Peter Cooper (author of Beginning Ruby and the blog Ruby Inside).  Anyone from the community can post links on the site, or comment on posts.  I find myself visiting here multiple times per day to get a quick sense of what’s happening and to make sure I haven’t missed any important news.
  2. GitHub - In addition to being a public git repository, GitHub has become a developer social network of sorts.  By following projects that interest you (including Rails itself), you end up with a single place to view all the commits that have happened on your projects.
  3. Twitter – For the twitter users out there, there are a few options.  First, there’s a user called rornews that you can follow, which posts links to Rails blog and job postings across the web.  You can also follow a number of members of the Rails community who are on twitter, including Obie FernandezGeoffrey Grosenbach, Ryan Bates, and why the lucky stiff (side note: anyone is welcome to follow me on twitter as well!).  Finally, you can consider using the tracking feature on twitter to follow “rails” or “ruby on rails”.  This will give you a lot of updates, but if you’re willing to sift through it you’ll probably learn about news almost as soon as it happens.
  4. Shared Feeds – I really like shared feeds (also called link blogs) as a way to see the best content filtered through a trusted source.  A few feeds to check out include Obie FernandezGeoffrey Grosenbach, and what appears to be “Matz” himself.  Or rather than following a single person, you try tracking searches for “rails” on FriendFeed or RSSmeme.
  5. Blog Suggestions – There are a whole bunch of great Rails blogs out there, but if I had to choose the top 3 they would be the official Ruby on Rails blog, The Rails Way, and Ryan’s Scraps (I find the “What’s New in Edge Rails” posts to be invaluable).

If anyone has any other suggestions, please post them in the comments!

12 Notes on Setting up Gmail IMAP with Apple Mail

Just like Ryan, I’ve been in the process of moving to Gmail to handle all my email, now that they provide IMAP access. In no particular order, here are some notes and thoughts on the process of setting up Gmail IMAP with Apple’s Mail.app:

  1. Rather than restate all the steps I took, I’ll link to this post that I found useful. In particular, configuring Gmail’s Drafts, Junk, Trash and Sent folders to match those in Mail is nice.
  2. The way Gmail implements IMAP wasn’t very intuitive to me and took some getting used to. For example, deleting a message from a mailbox doesn’t really delete it, it just removes that label (or at least that’s how it’s supposed to work; more on that later). I found this page helpful in getting used to how IMAP functions match Gmail actions.
  3. I know this has probably been discussed ad nauseum, but I wish Gmail would loose the “labels” concept and move to “folders”. While I’ve eventually gotten used to it within Gmail, the problem is only made worse with IMAP. For example, if a message has two labels, you’ll see it in two folders, which means it’ll show as two unread messages.
  4. I figured as long as I was setting all this up, I’d use Gmail to backup all my old messages, as described by Ryan. This meant copying over my old mbox files, importing them to Mail, and moving them into the appropriate folders in Gmail. It’s definitely a slow process, but you can view the progress from the Activity window (under Window -> Activity). There were a few times when the moving failed: I believe it was due to cases where messages had very large bodies. Although it failed partway through, I was able to start over without having any duplicate messages, so it looks like Gmail is smart enough not to add an exact duplicate.
  5. To help speed the process a bit, I’d recommend turning off caching while doing any importing or moving of messages. This is done under “Keep messages for offline viewing” in the Advanced tab of the Gmail Account preferences. Once everything is set how you like it, you can turn cacheing back on. For a large number of messages the caching process can also take a while.
  6. It took me a while to find a setup for my outgoing messages that works for me. In the past, I’ve had my email client set to automatically BCC myself on any emails I send. This way my messages get categorized properly, and my emails will be in the same mailbox as the rest of a thread. With Gmail, my sent messages were getting put into the Sent Mail folder in Gmail, which means I never got a chance to filter them into any labels. BCCing myself didn’t help, since Gmail already had a copy of the message in Sent Items. What I’ve done now is to remove Gmail’s Sent folder as Mail’s Sent mailbox, which means the only copy that Gmail receives is the one that gets BCCed, which means I can have it filtered however I like. Update: Turns out I was wrong on this.  Any email sent through Gmail’s SMTP will be added to “Sent Mail”, so BCCing won’t help.
  7. An unfortunate annoyance with Gmail IMAP is that unless you have a message filtered to automatically archive (in Gmail context this means moving it to “All Mail”), it’ll show up twice in Mail: once in the Inbox, and once in “All Mail”. So far I haven’t found a way to avoid this.
  8. The filters in Gmail are rather basic and limited, especially compared to Mail. For example, I don’t think there’s any way to match messages whose subjects start with a string, instead of just containing the string.
  9. Rather than set up a complex set of filters for all the email I get, I got an idea from Ryan to only create filters for less important messages, like automated log messages. Anything important will to go my inbox, and then I can choose how to label it or to delete it. This also has the benefit that on my iPhone, I can just check my Inbox and have important new emails in one place.
  10. Although Google Help says that deleting a message will just remove its label, it won’t necessarily work this way in Mail. Although deleting a message will remove the label (or if it’s in the Inbox, archive it), moving it to the Trash will actually put it in the Trash, which puts it in line for deletion. I think you could prevent this by not having Mail’s Trash mailbox be Gmail’s Trash, but the whole “deleting a message to remove the label” feature isn’t something I really need to use.
  11. I love the new Todos in Mail, but getting them working in Gmail also required some changes. From what I can tell, you can have Mail store the Todos locally or on Gmail (although there doesn’t seem to be a simple Preferences change for this). If it’s on the server, each Todo is stored as an email, and if you want to specify a Calendar for an item, it means defining a new set of Calendars in iCal. If you store the items on the server, each corresponding message shows up in a nice human readable format, but unfortunately on the iPhone all you see is a Mime attachment. Hopefully in the future Apple will provide a simple way to access Todos on the iPhone.
  12. Reading back on these notes, I see how complicated Gmail IMAP can be! I don’t think it’s quite ready for average users yet. That said, it’s nice to know that 1) I now have all my email accounts coming to one place, 2) my old emails are backed up online, and 3) I can access all my email from my computer, my phone, or a browser.

Are Traditional Blogs On Their Way Out? Not For Me.

With the recent release of the TechMeme Leaderboard, it’s been noted that most of the top 100 sources wouldn’t fall under the general definition of a blog. And if you consider a blog to be the thoughts of a single person (as opposed to multiple writers or an editorial staff), the count is even smaller.

Some consider this to be a sign of disinterest in “traditional” blogs, but for me, the opposite is true. I’ve found that lately I’m much more interested in the blogs of a single person, who gives their opinion and take on current events.

When I first started reading blogs, my main goal was basically “don’t miss anything”. I felt that there was so much news out there that it was important to be able to keep up on everything that was going on. I spent most of my time reading blogs like TechCrunch or link aggregators like Reddit.

But now I find that simply getting the headlines is pretty easy. Usually skimming through TechMeme is enough to update me on the days events in the tech world. After that, I want to go beyond the headlines and read the opinions and views of bloggers based on their personal experience and expertise — people like Robert Scoble, Fred Wilson, Allen Stern, or Dave Winer.

And I think this is where the blogosphere provides value beyond traditional media. Blogs allow influencers and insiders are able to share their views in a way they couldn’t before. So while news sources like the New York Times and the Wall Street Journal will always be around, I don’t think traditional blogs will be going anywhere.

5 Key Points of Great (Facebook) Applications

FaceReviews.com looks at the common traits in successful Facebook applications: Branding, Engaging, Viral, Useful, and Smart (or BEVUS, admittedly not the best acronym ever devised).  Although they’re looking at Facebook apps in particular, these traits more broadly apply to successful web applications in general.

I think some of these characteristics are sometimes looked at as being more than others. For example, being “viral” is considered an important part of bringing a steady flow of new visitors to a site. However, equally important in my mind is filling a real need for the user, and doing it in an intelligent way.

I also think these points nicely show the melding of the big picture ideas with the smaller, more technical details. Specifically, “branding” and “engaging” apply to the general concept of a site, but shouldn’t come at the expense of how the site handles the design and interface of the smaller details (the “useful” and “smart” aspects).

Mail Retrieval with Fetchmail

Fetchmail is one of the core Linux applications that I use consistently — pretty much every email I get is passed through it before getting filtered, forwarded or backed up. It fills an important place in the email chain between the Mail Transfer Agent (or MTA) such as sendmail or qmail, and the Mail Delivery Agent (MDA) such as procmail (there’s also MUA and MSA — the architecture of email seems to demand MxA style acronyms). Fetchmail’s place in this chain is to retrieve emails from a mail server using protocols like POP3 and IMAP, and then deliver them to local or remote users with SMTP.

HowtoForge has a nice tutorial on getting setup with fetchmail. Fetchmail’s robust configuration system allows for a variety of setups. This allows for a number of uses:

  1. Consolidating Accounts – It’s common nowadays for a person to have many email addresses, such as work, ISP, school, as well as plenty of free accounts. With fetchmail you can check all of these accounts and forward them to a single address.
  2. Usage of text-based email clients – Since fetchmail can also deliver to a local account, it allows you to store all your email on a Linux machine and read it using a client like mutt, pine, elm and others. This means you can check your email from any computer just by SSHing to your machine.
  3. Integration with mail filters – It’s easy to have messages be filtered before local delivery or remote forwarding. The Linux filter I use is procmail although there are many others. For example, you may want to filter out emails from a mailing list into a separate boxes. It also allows you to benefit from a spam filter that integrates with the mail delivery agent.

My personal email setup is rather complicated but it fits my needs very well. First emails are retrieved from my various accounts using fetchmail, and delivered to my local account with over Qmail. Procmail then filters out any spam, forwards the remaining emails to a separate email account, and then does further filtering before delivering to local mailbox files. The reason for doing this is it allows my email to be stored and backed up on my Linux machine, and if from any computer to SSH in and read email with mutt. But when I’m on my own computer, I can check the secondary account with Thunderbird, which gives me the benefits of a graphical mail client. It’s these kinds of personalized setups that fetchmail (along with the rest of the MxA family) allows.

Scripting with PHP

Normally if I’m going to write a script to automate a task via cron, I’ll use Perl (or lately, Ruby). Recently though I needed to use PHP in order to take advantage of common code from a web application. I was expecting this to be an unpleasant experience, using PHP outside of web programming, its raison d’être. However I ended up being pleasantly surprised with the results.

There are a few cases where it may make sense to write scripts in PHP:

  1. Code reuse. This was my reason for going with PHP. If a script is related to a web application written in PHP, it’s good practice to avoid reinventing as much functionality as possible. This also makes it easier to write tests directly in PHP.
  2. Availability. PHP tends to be widely installed on most machines, especially those with a web server. If you’re not sure what type of system the script may be running on, PHP might be safest bet.
  3. Widely known. There are a lot of languages out there nowadays, but PHP tends to a common denominator among developers due to its age and ease of learning. This is useful if the code is being written in a team that doesn’t have the same knowledge base. Even if someone doesn’t know PHP, it’s usually pretty easy to pick up given it’s similarity to languages like C, Java and Perl.

Luckily, PHP makes it very easy to move out of the web area into scripting. Recent versions of PHP include a Command Line Interface (CLI) which allows code to be run outside of a web server. The CLI also provides for parsing of command-line arguments and easy access to stdin/stdout/stderr. I had never used the PHP CLI before but was able to pick it up very quickly.

My foray into PHP scripting was also made a lot easier though various helper functions. PHP includes quite a few functions that can come in handy when writing a script or doing administration. For file I/O, the file_get_contents()/file_put_contents() pair of functions can be used to read or write the contents of a file in a single line of code, and I found them to be particularly useful. PHP’s functions for dealing with the filesystem, image parsing, string manipulation, and database processing are also helpful and may come in handy for the system administrator.

So the next time you need to write a script, consider using PHP, especially if it relates to a web application that’s written in the language. And if the decision to use PHP is forced upon you, don’t despair, as it might be a lot easier than you think.

Additional Reading:
Using PHP from the command line
SysAdmin to SysAdmin: Scripting admin tasks with PHP
System Administration with PHP

Top 7 Things System Administrators Forget To Do

The O’Reilly Sysadmin Blog has a nice piece on things sysadmins forget to do. Most of them relate to common tasks that fall by the wayside. I think programmers and sysadmins alike have a tendency to prefer interesting, more intellectually challenging activities over things like managing users or root access. The good thing about this is that these kinds of menial tasks can often be automated by programs like cfengine or puppet.

Even for those tasks that cannot be fully automated, such as keeping documentation, there are plenty of applications out there to assist in the process. For example, we’ve found that keeping documentation, notes and fixes in a wiki is a great way to keep information organized.

Personally, one of the tasks I often forget is to keep packages managed and up-to-date. Luckily, this is a lot easier than it used to be with programs like apt-get and yum.

Finally, I think we can all appreciate the reminder to always keep a friendly attitude: “If you want support from management, consider remembering that the user you offend today could wind up on the board of directors. Regardless of that possibility, system administrators should always remember that their clients are internal and if you want to keep your job, be good to your clients.”

System Administration with Ruby

Ruby gets a lot of (well deserved) press because of Ruby on Rails, but recently I’ve found it to also be an excellent choice for scripting tasks, jobs that I otherwise would have used Perl for.

The first benefit of using Ruby is that its built-in code blocks allow for simpler, shorter code. A Ruby block is basically an anonymous function that can be passed to another function as a parameter. For example, here’s how you could take an array of numbers and square each one:

[ruby]

nums = [1, 2, 3, 4, 5]
nums.collect { |x| x*x } # produces [1, 4, 9, 16, 25]
[/ruby]

Blocks are used for all sorts of purposes, like looping, iterating, sorting and mapping. Once you get used to them, they become quite intuitive and save a lot of coding time.

In particular I’ve found code blocks to very useful with database programming. Here’s an example that uses the mysql Ruby plugin to do a query:

[ruby]
require ‘mysql’

db = Mysql.new(“localhost”, “root”, “password”)
db.select_db(“a_database”)

result = db.query “select id,name from users”
result.each do |row|
puts “ID: #{id}, Name: #{name}”
end
[/ruby]

Note that “do/end” is a multi-line alternative to brackets.

In Ruby, everything is an object, even primitive types like numbers and strings. The language makes it quite easy to create your own classes as well, and because of this I find myself creating classes more often than I normally would while writing scripts. Currently in Perl, OO programming is still rather obtuse, so it’s often simpler just to use scalars, arrays and hashes in various combinations (for example, “a hash where the keys are names, and the values are arrays where the first element is a number”, etc). The problem with this is it can create brittle code that can make bugs common.

Ruby classes can be written inline with procedural statements, and are usually very short:

[ruby]
# A simple class to represent a person
class Person
attr_accessor :first_name, :last_name, :age

def initialize(first_name, last_name, age)
@first_name = first_name
@last_name = last_name
@age = age
end
end

joe = new Person(“Joe”, “Schmo”, 25)
[/ruby]

The “attr_accessor” line is a useful declaration that creates a private member variable along with public reader and writer methods.

Two common tasks of scripts are working with operating system calls, and string parsing/manipulation. In these aspects, Ruby works just like Perl. You can use hash marks (the ` character) to run a command return its output. For working with strings, Ruby regular expressions work just like Perl. Here’s an example that uses both:

[ruby]
# Look for a resolve error
resolve = `resolveip #{address}`
puts “Host not found” if resolve =~ /host not found/
[/ruby]

All of this being said, there are still many places where I feel that Perl is a more appropriate choice for sysadmins. While Ruby has a growing set of plugins, nothing can beat the breadth of Perl modules available through CPAN. For a very specific task (say, interfacing with the /proc filesystem) Perl is often a better choice simply because of the amount of publicly available code out there.

The next time you have to do some administrative scripting, consider giving Ruby a try. Even if you decide to stick with Perl (or whatever your language of choice), it’s a great way to try out Ruby if you’re not familiar with it.

How to Deal with Log Overload

Even a relatively inactive server can produce quite a large amount of logs, and a high use machine serving multiple functions will probably have so much log activity that it becomes impossible to discover anomalies, resource problems, or potential attacks. Luckily, this copious amount of data can be made manageable without too much trouble.

Consolidate logs across the network

If you have more than one machine to keep track of (and what sysadmin doesn’t) the log problem only multiplies. One thing that can help in this situation is remote logging. For example, syslog makes it easy to send logs over the network to a single source. In large networks this may be a dedicated logging machine. In any case, this at least somewhat reduces the complexity of the situation, although does not help with the sheer amount of information produced.

I’ll usually leave a window open with a connection to the central logging machine with a running output of logs (this can be done with `tail -f’). This helps me catch some issues as they occur, but it’s easy to miss entries if I’m not at the computer or not paying attention to the running log.

[Read more...]

The rise of the local web application

I do a lot of data backups on CDs and DVDs, and I recently realized that I had no organized way of figuring out which files were located on which discs. Rather than looking for a piece of management software, I decided it would be easier to just write an app myself in Ruby on Rails.

Nowadays, agile development methodologies like such as Ruby on Rails allow you to development applications so quickly, that it’s often easier to write code yourself, even if a similar tool already exists.

Imagine if I had tried to use an existing tool to manage my backups, rather than do it myself. I would needed to take the time to:

  • Research available tools and determine which one fits my needs
  • Setup and install the program
  • Customize it for my needs and environment
  • Learn to use it

During the time it takes to complete these tasks, it’s just as easy (and frankly more fun) to code an app myself, which will be customized to my exact needs from the beginning, and requires no learning time.

As agile development becomes more and more used, I think this “do-it-yourself” practice will also become more common. Certainly for system administrators, who already spend time writing customized scripts and GUI apps. This is the topic of a recent IBM developerWorks article, Develop Web applications for local use, which encourages web application development in place of GUI or command-line applications.

An added benefit of this practice is that the developer might discover that the application fills a need felt by others, and can turn their local webapp into an actual website or product. That’s how RSP started. It started development as a tool to use internally, before we discovered that it could have a use to the outside world.