The RSpec post (including an important tip on shared example groups) 

Filed under: Blogroll on Thursday, March 27th, 2008 by jeremy | Comments Off

So in my Rails apps lately I’ve been using the hell out of some RSpec. I have to say that it’s making me a better, more methodical coder. It’s not just allowing me to define my app in terms of expected behaviors and providing the well understood regression testing capabilities of any testing framework. It’s a whole new way of organizing my approach to programming.

Read the rest of this entry »

Using attachment_fu with :storage => :db_file 

Filed under: Blogroll on Sunday, March 23rd, 2008 by jeremy | Comments Off

So I recently got to use Rick Olson's attachment_fu in a Rails application I'm working on, and it is pretty awesome. It takes a lot of the hassle out of managing files that you might need to upload such as images, and even has the capability of doing thumbnails on the fly. Attachment_fu has three methods for storing uploads: the file system, Amazon S3 storage, and the database. You can find ample articles on the 'net for using the first two methods, but the last one is poorly documented - both in the attachment_fu docs and on the web (that's not to say it isn't documented at all - I owe everything to Ron Evans' crucially helpful post). But I'd like to provide a streamlined - or at least personalized - tutorial for getting this to work.

Read the rest of this entry »

GitHub: Anarchy for Programmers 

Filed under: Blogroll on Tuesday, March 11th, 2008 by jeremy | Comments Off

I’m at the CVREG meeting watching Jon give his presentation on GitHub, the new awesomeness that everybody (nerdy) is talking about. I’m still learning about it and figuring out how / why it’s different than Subversion, but look for a personal project on there soon.

git is a source code management system designed to make branching easy. It doesn’t enforce a “HEAD” like CVS and Subversion, so you can organize your project (or not) any way you want and fork to your heart’s content. It was written by Linus Torvalds and company to help them develop the linux kernel, so it’s all about lots of people hacking on code and figuring out a way to diff between versions without making full copies of the source. GitHub tracks, hosts, and manages all the distributed goodness: think MySpace for programmers. It also has profiles, update feeds, requests, and more. It’s perfect for starting your own, decentralized, self-organizing coding community.

Let me know if you want a beta invite. I’m jeremy6d if you want to find me.

It’s 11:00 pm; do you know where your model methods are? 

Filed under: Blogroll on Saturday, February 23rd, 2008 by jeremy | Comments Off

So the other day I was implementing what I considered a simple Rails association helper to make my life easier:

has_many :unapproved_posts,
:class_name => "Post",
:finder_sql => 'SELECT posts.* from posts INNER JOIN users ON posts.user_id = users.id INNER JOIN groups ON users.group_id = groups.id WHERE (groups.id = #{id}) and (posts.approved is NULL)'

Yeah, it’s a little clunky, but I needed a quick fix.

Perhaps I should have spent the time on a refactor, because this code put me in Rails hell. When displaying unapproved posts in my controller, my code iterated over a collection of Post objects. When I’d first start the server, the action would grab the association with no problems. However, every subsequent time the action runs, the Post objects I got back were missing the methods I defined in the Post model. All the attributes were there and accessible, but any methods had disappeared. Note that this only happened when accessing the posts via the association helper through the controller; doing the exact same stuff in script/console gave me no problem.

After a few hours of troubleshooting and abject frustration, I came across this ticket which seems to describe the behavior I was seeing. Note that this is a 1.2.6 application I’m working on, so the lack of resolution makes some sense. However, I needed a fix, and my friend Jon suggested I just write a method that returns the collection rather than using the helper. So running the same query with Post.find_by_sql worked fine, and since I merely needed a read-only collection, this serves my purposes.

Just wanted to drop a line in case anybody in the future runs into this. Watch out using finder_sql; it does not appear reliable. Also, if you experience this behavior in a Rails 2.0 app, let me know (less important) and reopen the ticket (very important).

New Frontiers in Ruby Web Applications 

Filed under: Blogroll on Wednesday, February 6th, 2008 by jeremy | Comments Off

So as somebody who has experienced their share of headaches deploying Rails apps (and ended up learning how to provision a VPS from scratch as a result) I’m interested in the questions Peter Cooper of Ruby Inside asks:

  1. Is there / why isn’t there a version of mod_ruby that doesn’t have the “class sharing” issue? What is the technical impediment?
  2. Is there any immutable reason that Ruby apps couldn’t, in the future, be deployed in a PHP-esque fashion?

The ensuing discussion in the comments is very instructive, and I’ve even been giving Cooper’s Switchpipe project a bit of attention lately. But Ezra Zygmuntowicz chimed in with quite welcome news:

I’m just going to say that Rubinius has support (as of today!) for running multiple instances of it’s VM within one process, each VM on it’s own *native* thread, each VM running many ruby green threads. Each VM has it’s own heap and so each VM could load different apps that wouldn’t interfere with each other. We have plans for a mod_rubinius for apache that takes full advantage of this feature. Stay tuned ;)

I certainly will!

Two tired girls 

Filed under: Blogroll on Sunday, January 20th, 2008 by jeremy | Comments Off

Just had to post this because it was too perfect a shot not to.

t-girls.jpg

The busyness won’t last; stay tuned for real blogging.

A single press for all my words 

Filed under: Blogroll on Thursday, December 27th, 2007 by jeremy | Comments Off

So one of the big changes I made on my new slice is to centralize my WordPress blogs. I run three WordPress sites, and having to upload a whole new codebase three times while being careful not to overwrite my customizations, plugins, themes, etc. was beginning to grate. It would be better to have one unit of code that I could maintain and tweak. But was that possible without going down the MU route?

The answer is that not only is it possible, but it’s also rather easy. I made a modification to my wp-config.php file that appends a host name prefix to every WP table in the database. So I run everything in one database, and the wordpress PHP code just chooses the tables to run off of based on the requested host. Pretty slick, because it also means I can keep all my themes, plugins, etc. in one place and just turn them on and off in the different tables. And I’m using Subversion to run updates, which means it doesn’t overwrite files I’ve modified, while still letting me do updates with one command.

So I guess now that I’ve found such a convenient solution to my problem, I’m wondering if it’s vulnerable at all how vulnerable it is. I suppose I’m advertising any security holes, but I’m a pretty transparent internet user, and all the data’s backed up anyway - plus, I keep a pretty good eye on the server, and it’s locked up rather tight for anything that would be terribly damaging. But all you WordPress gurus: what do I need to know about this approach? Is it insecure? Are there performance issues with which I need to concern myself? This is running everything from my personal blog to a moderate traffic aggregator. I’d appreciate any insight or warnings or sharp tongue lashings you could provide.

And of course, this is only the first step. I still want to do a full reengineering of my stylesheet and clean up loose ends in the design. And I’m gonna implement some long-overdue social networking upgrades… you’ll see. So stay tuned for more wordpress-y goodness.

Ruby 1.9 released! 

Filed under: Blogroll on Thursday, December 27th, 2007 by jeremy | Comments Off

ruby.pngPraise be to jeebus - a development release of Ruby 1.9.0 was announced on ruby-lang.org Christmas Day (nice timing for the western world). I guess it’s too early to install on my new slice, and probably better to wait for the package anyway. Nevertheless, at RubyConf this year we got a sneak peak at the priorities and decisions that have been guiding the implementation of 1.9, which above all should be much faster than 1.8 (and more competitive with other languages). More detailed changes here.

Also, in case you didn’t hear, Rails 2.0 was released last month. ‘Tis hot. And I finally figured out that scaffolding has NOT been gutted; I had lamented the fact that the scaffolded views no longer generated HTML input fields based on the database table fields. But now it’s much more consistent: you name the fields at generation time and it creates the views and the migration for you. Kids, it pays to read the docs.

Welcome to my new slice 

Filed under: Blogroll on Thursday, December 27th, 2007 by jeremy | Comments Off

Since I’ve been on SliceHost I’ve learned a lot about server management. I’ve also made a lot of mistakes and generally made a mess out of that slice. So I got a new one and am moving everything over. This is the first post from the new slice. If you have performance issues, let me know - I probably could stand to tweak some of the Apache and PHP settings.

2nd Annual McWeiland Chili Cookoff Photo Montage 

Filed under: Blogroll on Monday, November 5th, 2007 by jeremy | Comments Off
And first YouTube upload ever. Tasha did the video on her new MacBook - like that “Ken Burns” effect? Enjoy!