posts by date

04/2007
Heavy equipment in photography

There’s an odd/artistic appeal in heavy equipment photographs. I’ve come across them quite a few times on some of the more popular flickr photostreams. The lens has a lot to do with it, though, as I don’t think they (such as the following picture) would have near the impact if it weren’t from a fisheye perspective. Even so, it still takes a creative eye to turn an overbearing, ugly thing into something that could be worth paying for.

Trying to understand twitter

I’ve been slow to adopt some of the things I see very useful today, but twitter is not in my adoption list. I just don’t get it. I gave it time, holding back my opinion just in case one day I would see the light, but I still don’t. It’s kind of cool when I think about the technology, but even that doesn’t make me want to ever use it. I keep reading about how it’s growing and growing—how come I don’t understand why it’s so popular? I just saw this on the main page: “eyelids drooping… 5pm… what the heck?” Hmmm… ok, whatever.

Meta-programming and the singleton class

Confusing, confusing, confusing. I finally have the opportunity to play with the has_many_polymorphs plugin. I’m using it to handle tagging. As suggested, I’ve written several tag extensions (tag_with, tag_list, tagged_with?, etc). I’m not having trouble writing methods that work on an instance of a class, it’s when I want to add methods that work directly on a class itself (even though a class is an instance of the class, Class—right?). I’ve read a couple of articles, but man, this stuff is tricky.

What I wanted to do was give each model a class method such as find_tagged_with. I thought it would be cleaner as a class method of the “taggable” class in question (but without me having to explicitly define it in each class, as that would defeat the purpose), rather than always referring back to the Tag class. This is how it works currently:

class Dog < ActiveRecord::Base; end;
class Cat < ActiveRecord::Base; end;

Tag.find_by_name("animals").dogs
# => {all dogs tagged with "animals"}

Tag.find_by_name("animals").cats
# => {all cats tagged with "animals"}

I could leave it as is, but it’s not as intuitive as I’d like it to be. Since I’m getting objects of the Dog and Cat classes independently, I would like to have the find_tagged_with method become part of those classes. So I could do something like:

Dog.find_tagged_with "animals"
Cat.find_tagged_with "animals"

From what I’ve read, class methods are just singleton methods defined on the instance of the class in question. So they wouldn’t apply to all instances of a class, but I wouldn’t need them to. I figured I would need to open up the singleton class, since that would only apply to one object. The “taggable” class would be the object, since they are really just instances of the class, Class (and all objects have singleton methods). But obviously what I was thinking wasn’t right, since all I can come up with is “undefined method ‘find_tagged_with’ for ”. I don’t know, maybe I should just move to the mountains and study the Ruby language night and day, since I keep finding more and more I don’t understand.

How to automate tasks using Ruby or Rails?

I’ve yet to get the cron job to consistently execute for the flickr and delicious caching. I’ve tried several different things, but nothing seems to work. So I’ve started seeking alternatives. There are three different methods listed, but it’s not obvious to me how they might work. If I were to setup a scheduler, would I then “start” it when Rails initializes in environment.rb? Of all three options, I’m at a loss as to which one I should pursue.

Right now I’m calling refresh_api_cache via a “refresh” link that appears upon login:

def refresh_api_cache
  reload_cache(ENV['RAILS_ENV']) and redirect_to :back
end

private

def reload_cache(env)
  command = "ruby #{RAILS_ROOT}/script/custom/api_cache.rb"
  env =~ /development|test/ ? system command : exec command
end

That’s not terribly inconvenient, but it requires two things to happen (tag something in delicious or flickr and then come here and click “refresh”). I want this to be automated. Any tips on scheduling in Ruby/Rails?

Is it important to be a well-round programmer?

Back in January, I posted about my plans for the new year. Number five on the list was to learn a new programming language. I thought it would be good for me to grasp how other languages handle the things I’ve come to learn in Ruby/Rails. I still agree with that, but I’m having a terribly difficult time prying myself away from Ruby. I’m so infatuated with it. For Christmas, I got a Python book. I’ve yet to read one single page, but since January, I’ve somehow managed to read three more Ruby/Rails books.

I know I’ve mentioned this numerous times, but Ruby is my first real attempt at a lot of things (OOP, Extraction, DRY code, MVC, etc). I did a little VB.NET and C#, but never had the desire to go home and read books about those technologies. So, being part of projects that involved those languages, mixed with the design aspects that I was more-so responsible for, I didn’t get too much out of it. I do remember having to explicitly write out the “getters” and “setters” for each attribute in .NET (which is ridiculous when compared to attr_accessor). And I can’t even begin to tell you how sloppy my PHP code was, as that was my first attempt at something on my own. I just made it work, so I don’t really know what PHP is capable of. I do know I’m not crazy about the syntax (I knew that back then, though).

I keep coming back to the thought of learning a new language. And now I’m considering Erlang (examples: 1 and 2). I read something on it (or watched a video) over a year ago. But when my time is limited, I’d rather reinforce and learn a language I know I love, rather than start over with something new. What’s your take on being a well-rounded programmer? Can that help you learn the language(s) you know you love? If so, is it worth it?

Test for valid markup in functional tests

Here’s a way to assert_valid_markup in Rails. I don’t know if it’s old news or not, but it’s new to me. I always test my markup in the W3C validator after it’s live. I’ve never looked into any other solution, so I think I’ll find this useful. Anyone know how to test for valid markup (locally) other than this?

Strobist, Flickr, and Rebekka Guoleifsdottir

One of my favorite photographers (although I don’t know too many) is Rebekka Guoleifsdottir (her Flickr stream). She has not only inspired me to really dive into photography, but she has also made me want to travel to Iceland—it looks awesome there.

Strobist is writing a series called “Flickr and You.” In part one, they talk about Rebekka Guoleifsdottir, and how her fame became known through Flickr. It seems as though her photography is spreading like wildfire, and she might owe much of that to Flickr (she just reached over 3,000,000 views). Since Flickr is one of my top places to spend “internet time,” I naturally find articles like this interesting. Let’s hope Flickr doesn’t change by attempting to capitalize even more on its ability to fuel the fire for amateur photographers all over the world.

Trouble sorting a hash (sort of)

Last night I removed my custom tagging system, and converted to acts_as_taggable. I’m thinking DHH’s code is probably a little bit better than mine (just a hunch). I’m also converting my tag methods to use some of the other nice things acts_as_taggable provides, such as: find_tagged_with, tag_names, and one of the reasons for this post, tags_count.

The tags to the left are now being pulled via the tags_count method, but I run into a problem. That method returns a hash where the key is the tag name, and the value is the post count (i.e. [[“rails”, 38],[“personal”, 37], ...]). That’s great and all, but I need to sort it in descending order, based on the value and not the key. So here’s what I’m doing:

def self.get_popular(options={})
  Post.tags_count(:limit => (options[:limit].to_i || 10)).invert.sort.reverse
end

The #invert method of the Hash class essentially swaps the key => value pairs to become value => key pairs. This allows me to call #sort which will then sort by the value (aka the count) rather than the key (aka the name). And at the end of this chain we have #reverse which just gives me the descending order. Seems to work, right? Well, almost.

The problem I’m having is when two tags have the same post count. It seems to then grab only one of them (the first in the alphabet?) I don’t exactly know if this is something I’m worried about fixing, but it makes me feel as though I’m not in control of the code, which I don’t necessarily like. Plus, I don’t know that I fully understand what’s happening, here. It’s ignoring the redundant values in the sort. Thoughts/ideas are welcome, even if it means a new method to get the posts-per-tag count.

747 landing at st. maarten airport (insane)

This video of a 747 landing is simply nuts. I can’t believe it’s an everyday thing. Children are swimming on the shores as if 747’s aren’t flying 15 feet above their heads. Craziness.

post headings: inside or out?

Originally, I had the post headings flush with the center column. I liked it that way, and then during one of the five times I adjusted the column widths, I accidentally left too much padding on those headings. Once I saw it, I thought it to be a good way to make the headings stand out more. But now, I don’t know if I like it. What do you think?

Yet another redesign for rpheath.com

And here’s the real reason why I have a site (read: so I can rebuild it over and over). I’ve stripped it down to the bare essentials, and found better ways to implement what was left.

This is my first 3-column layout, although it doesn’t really feel like a 3-column layout to me. And maybe that’s a good thing. Point being, I wanted something different from previous versions, and quit making it more than it had to be. I’ve yet to supply a list of full entries up front. But it was long overdue. I’m actually satisfied with the code this time, and I refused to cut corners. Now, I feel as though it’s worth the effort to make changes and enhance what’s here.

thanks to chris scharf

For a few things, actually.

  1. Idea for a no admin interface (although I’m not using the authentication key, I did manage to get rid of the entire admin section).
  2. Idea to list posts not based on a limit, but on a period of time. However, if I go on another posting drought, rather than letting the site go blank, I’m using the month number as the limit of recent entries (so April would be four entries, May would be five entries, and so on).
  3. And finally, the eztime plugin. I’ve been dragging my feet on using this, and although I’m not overwhelmed with time formats here, I can see its power. Playing a bit in the console has shown me how intuitive it is—great choice of keywords.

keep an eye out

I’m not claiming that there are no bugs, so if you notice one, please let me know. Like I said before, I’ve tested it in [mac] Firefox, Flock, Safari, [windows] Firefox, Flock, IE7, IE6 (I hate the has layout problem). I’ve also mapped the old RSS feeds to the new methods, so you shouldn’t have to update your feeds—let me know if it’s not working. And that’s about it. I might post a follow-up on more details, but we’ll see how it goes.

Watch SVN repositories with subtlety

Subtlety is a way to get updates via RSS for any public subversion repository. It’s perfect for monitoring Rails plugins, so you don’t miss any must-have additions. I realize that it’s a few months old now, but I just recently started using it. Yesterday I added the Rails trunk so I can keep an eye on the latest and greatest Rails commits.

No more costly 411 calls

Over lunch, I saw a post about Google 411. I cannot stand using the phone, but for whatever reason I called 411 from my cell phone twice last month… at $1.75 per call. I didn’t know they raised the cost again.

Out of curiosity, I tried out Google 411 at lunch. It worked better than Sprint’s 411 service. I called for Radio Shack in Fairmont, WV, and it gave me 8 of them (Sprint returned 2). You may think returning irrelevant locations (i.e. 8) is unnecessary, but it will list them as options starting with the closest location. So it works if you know exactly what you want, and it works if you know generally what you want. Plus, you don’t have to talk to anyone—it’s all automated. Pretty cool.

Oh, and I used 411 to call Radio Shack prior to today. I didn’t just waste $1.75 to compare them, just so you know.

CSS, IE, and conditional comments

I’ll start off by saying I despise Internet Explorer—all versions. I mentioned my desire for a fresh site, and so over the last couple of days (mainly the weekend) that’s what I’ve working on. I only have a few more hours left, mostly on admin-ish type features (as of now, I have no way to post, edit, delete anything). I’ll save the details for the “grand opening” post.

But I do want to express my frustrations with building the layout. First, CSS is amazing; second, IE is not. I know I could ignore IE, since hardly anybody I know uses it, but it’s tough for me to accept my site not working in certain browsers. It’s an unfortunate disease.

I’ve decided on a 3-column layout (my first ever). I wanted the side columns at a static width, while the center column (the content) was liquefied. Despite what you may think, that’s not the easiest cross-browser layout to achieve—for me, anyway. So I decided on 1 of the 10,000 ways this could be done. Everything was going as I expected it to (in Firefox). Those expectations also included the layout not working in IE6. And of course, it didn’t.

So I started writing some * html hacks, and got everything aligned to match Firefox. I finished it up, pulled in some real data, and everything looked good. I was satisfied. Then I thought, “well, I had better check IE7,” just to be sure. Lo and behold, the left column was missing entirely. I was livid. Here we go again.

I stripped out all of the * html crap and made separate CSS files: a default, one for IE6 hacks, and now, one for IE7 hacks. So currently, I’m using conditional comments to load separate style sheets. What an ugly pain. The thing that bothered me the most is how IE6 was closer to being correct than IE7. For IE6, I really only had to adjust the left hand column width a bit (and a few other things, of course), but at least I could see the column. For IE7, I had to entirely change the positioning. Once I found it and brought it back, it wouldn’t re-adjust with the fluidness of the center column; it would either gap or overlay it, which was hideous.

Based on what I know about CSS, Firefox did exactly what I expected. Both IE’s did not. Granted, my CSS may not have been ideal or I should have done it a different way, IE has done nothing in the past that would let me believe it was my fault. I expected more out of IE7, not less.

In closing, here’s the status. I’ve approved the layout in the following environments:

  • Windows: Firefox, Flock, IE6, IE7
  • Mac: Safari, Firefox, Flock

And all is well, finally. I didn’t bother with IE on a Mac, because I figured anyone with a Mac is NOT using IE. And if they are, they’re not interested in my site :-) And now I have class tonight and tomorrow night, so that will more than likely delay progress for two more days. Blah. I’ll keep you posted.

More web design inspiration

Just recently, I found a Web Design Inspiration set on Flickr that has a wealth of good, solid designs. There’s a brief description of each, along with a link out to the actual site. Not surprisingly, I’ve clicked through each individual design (only within the Flickr gallery—I’m not that bad). Here are a few others (not in the set) I’ve come across lately:

If you’re stuck in a rut in terms of creativity (like I am right now), you should click through that Flickr set. I don’t always get motivated just by looking at other designs (real photos actually do more for me), but today, it helped.

Flickr architecture and MySQL

I’ve read, a time or two, things like “if you’re going to scale, you should probably move away from MySQL up to Oracle or SQL Server.” And for all I can argue, that may be true—but it might depend on your idea of scaling. The other day I read through a Flickr presentation on their Architecture (they’re using MySQL), and came across some very impressive stats (such as ~25,000 DB transactions/second). The presentation says a snapshot of db1.flickr.com shows…

  • SELECT’s 44,220,588
  • INSERT’s 1,349,234
  • UPDATE’s 1,755,503
  • DELETE’s 318,439
  • 13 SELECT’s per Insert/Update/Delete

I would consider that to be a reasonable scale. Oh, and keep in mind, that presentation was from 2004. They’ve probably doubled that since then.

Glancing through those slides has shown me how much I really don’t know about high-traffic application design. But that’s not too disappointing since I’m not-so-much interested in that stuff. Server issues and “vertical partitioning” a DB (whatever that means) doesn’t intrigue me near as much as the application itself. Of course, though (and thankfully), I won’t ever have to worry about an application experiencing over 50 million SELECT’s on one instance of a database cluster. But apparently, when properly configured, MySQL can handle it. I think I’d save the $25,000 it would cost for SQL Server, too.

It was only a matter of time

I’m growing terribly sick of this site. To me, the design is very ugly and bland. It all started to go downhill when I began to realize (and despise) the faded/foggy look from the blend of color choices I’ve chosen. I’ve made an attempt to sharpen things up a bit, and it worked, but was nowhere near enough to bring me back as a fan of my own site.

I no longer like showing a little bit of the “Latest Post.” Really, that doesn’t do anybody any good. It’s a hassle for me, because if the post contains an ul or blockquote or h2 or whatever, I have to worry about the word count ending before the closing tag, which would throw the entire page layout off the rocker. As a fix, I just strip out all of that stuff from the main page (and the bits, as well). It’s a lame solution to something that has no benefit to begin with. There are a few other things like that, but I’ll spare you the details.

My first post on this site was sometime in August of 2006. It’s amazing how much I’ve learned since then. Compared to now, the code here is a mess. But I guess that comes with learning—old code always seems like a mess. In a way, I want to start over again on a clean slate, but as always, time is against me.

I have an idea for something simple, and now, I could probably throw it together rather quickly. I just don’t know if it’s worth it. I thought about Mephisto or a similar solution, but I like to get more experience something out of it. Plus, I enjoy going custom with my own site. I guess I’ll figure something out, and hopefully sooner than later.

Tiger Woods and Rails

A while back, I read a post where someone was listing a few Rails performance tips. Come to find out, half of them were things like “bypass ActiveRecord” and “beware of finders” and “use HTML instead of view helpers” and so on. That’s actually a lot of why I choose to use Rails in the first place; the last thing I want to do is rid myself of convenient ways to avoid tedious programming. If you want to write explicit SQL statements or standard HTML, maybe Rails isn’t the right framework. I’m pretty sure any of the Microsoft options don’t have a problem with explicit SQL, but beware, .NET does like to make up it’s own HTML at times.

I don’t have much experience with other web frameworks (except .NET… blah). I was just about to try out Cake for PHP when I was introduced to Rails. Having said that, Rails is what I know best. I think Rails sometimes catches some flack for things because it does so much already, it’s expected to do more—somewhat similar to Tiger Woods.

Let me explain. Tiger Woods is legitimately said to be the world’s greatest golfer. He has set a number of records, and truly is amazing to watch. But what happens when the world’s greatest golfer gets a bogey? Or heaven forbid, a double bogey? Extreme shock, disappointment, and disgust. That’s hardly a fair attitude considering all that he has accomplished. Since he’s currently the best, the expectations of him have far surpassed those of any other golfer—it’s almost surreal.

Rails’ expectations are as high as they are because of how astonished people were in the beginning. It was so easy to work with, but at the same time, everything is relative. It was so easy relative to writing an extra 20 lines of tedious, unnecessary code. Convention over configuration allowed stuff to just “happen.” Now, it’s like Rails gets compared to itself, and it’s supposed to go above and beyond that, which is an endless cycle. I guess it goes back to the old proverb, “the more you get, the more you want.” But don’t forget how painful things used to be, and appreciate how things are, today. After all, it can only get better.

I personally blame Rails to be the culprit for my web programming passion (and yes, it’s Ruby’s fault, too). I don’t know if I would love this stuff near as much if I were stuck in a static environment where my own customizations and ideas couldn’t be put to work. While I rarely do this, I love having the option to dive right into the framework itself and change/add things specific to my needs. Not to mention the sheer beauty of its organization, configuration, and presentation. And being built on top of Ruby makes it that much better. Clean code gives any mindful programmer motivation; and with (Ruby on) Rails, I’ve written some of the cleanest code of my life. Rails is much more than I could ever expect from a framework.

If you’re upset with Tiger Woods not shooting 20 under, or having a “par” day, simply don’t watch him. But I bet you won’t get near the excitement watching someone else.

2008 by Ryan Heath | Get In Touch

flickr

DesolateInfinityLooking upDazedBlurred