Starting Good CSS Habits: Part 3

April 29th, 2009

The series of posts on Starting Good CSS Habits begins here.

Now that we have work on improving our HTML in the previous articles, we are ready to start applying some CSS to the page. We will begin by discussing text and fonts.

Read the rest of this entry »

Bookmark and Share

Starting Good CSS Habits: Part 2

April 8th, 2009

The series of posts on Starting Good CSS Habits begins here.

Christoph Wiese, a friend who already has good CSS habits, made some good points I forgot to put in the last post. Before we keep going, it is worth going over them.

Read the rest of this entry »

Bookmark and Share

Starting Good CSS Habits: Part 1

April 2nd, 2009

I am often surprised by how much bad HTML is out there. Especially HTML that does not use Cascading Style Sheets yet. CSS has been around for over 10 years now! It was added to HTML in 1997 and well-supported (at least reasonably) in web browsers by 2000. I think the reason many people never upgraded is that they either learned HTML before 2000, they learned it from sources (friends, coworkers, internet, legacy code) from before CSS, or they learned just enough to get a site online and never bothered learning the “right way”.

Legacy sites are not always worth the trouble to update—I know I have plenty of old code still floating around out there—so their flaws are understandable. But some folks are carrying around their bad HTML habits still. If you ask them to code a page they probably know that frames should not be used, so they use a table to layout the page instead. They might use <center> when they want text to center. I see bad code and misused tags all the time. You can “view-source” on many major websites and see bad code by people who should know better.

If that sounds like you or someone you know, keep reading, I will try to help you break your bad habits and start good ones.

Read the rest of this entry »

Bookmark and Share

PHP with MySQL Beyond the Basics

March 26th, 2009

lyndalogo_std_w

I am proud to announce that PHP with MySQL Beyond the Basics has been released on the lynda.com Online Training Library. It is the sequel to my previous video title, PHP with MySQL Essential Training. It’s almost 11 hours of video training; with the previous title, that makes a total of 21 hours of PHP training!

While the first training was an introduction to PHP and MySQL, in this title I focus on “intermediate PHP” and PHP’s object-oriented features. Objects make it easier to organize and maintain your code, make code modular and reusable, and (most importantly) add clarity by reducing complex interactions to simple behaviors. Once you understand the fundamentals of PHP, you’ll want to learn to harness the power Object-Oriented Programming provides.

PHP with MySQL Beyond the Basics is available online as streaming video to subscribers of the lynda.com Online Training Library ($25/month, $250/year, $375/year with exercise files included). It is will also be available as a CD-ROM soon both through lynda.com and Amazon.com.

Here’s the official description:

In PHP with MySQL Beyond the Basics, expert instructor Kevin Skoglund introduces powerful PHP programming techniques using object-oriented programming (OOP). Both novice and experienced PHP developers will benefit from the efficient, well-organized, reusable, and easy-to-understand code that OOP offers. Kevin shows how OOP techniques can streamline database queries, help manage sessions, and simplify user logins. While building a real-world web application, Kevin also includes practical advice on topics ranging from structuring code to logging user actions. Exercise files accompany the course.

If you are already using PHP but not objects or if you use objects but don’t understand them as well as you’d like, give this training a try and let me know what you think!

Bookmark and Share

Rails Hosting Survey 2009

March 12th, 2009

img_rails_hosting_survey

The results of the Rails Hosting Survey for 2009 are out. Thanks to Planet Argon for putting it together!

With about 1250 respondents, it has some pretty interesting results.

Here are the things that stood out to me:

  • 63% use Git vs. 36% use Subversion. I knew Git was growing fast, but I didn’t expect 2:1 over SVN.
  • 75% use Capistrano. About 25 percentage points higher than I would have guessed.
  • 97% use either MySQL or PostgreSQL. I’m not surprised how popular they are, I’m surprised that all other database make up only 3%.
  • 68% Mac, 25% Linux, 7% Windows. I know “everyone” uses Mac, but I’m surprised Windows is that low.
  • 37% use Hoptoad to manage application exceptions. I had never heard of it and will have to check it out.
  • 68% don’t use uptime monitoring tools. 60% don’t use any process monitoring tools. Is that a reflection of improved reliability and ISP/Hosts providing the monitoring? Or is it just hope-for-the-best developers who will wait to hear from users that the site is down? (Of which I am frequently guilty.)
  • 25% use Nginx for their webserver. That’s a lot considering only 2% of all websites uses Nginx. It’s an interesting trend to keep an eye on.
  • And finally, WOW some people are paying a lot for their hosting. More than $50K/month?!?! I’m dying to know who that person is.

I only wish the results had included more information about the survey sample. How did they get their sample? Independent or corporate developers? What size companies? What country and/or U.S. state are they from? If 20 developers taking the survey are all from the same company then it will skew the results in favor of that companies preferences. If they are all from San Francisco, then it says more about SF than about Rails preferences worldwide.

But it is an interesting and informative snapshot nonetheless.

Bookmark and Share

Worthwhile Links

March 3rd, 2009

I promised myself that I would pick up blogging again. I miss it and I think (hope) that my workload will allow me the time again. To kick things off, here are two articles that are definitely worth reading.

Bookmark and Share

Ruby on Rails version 2.2

November 24th, 2008

I have been very delinquent in posting to this blog. Fatherhood plus several big projects have forced me to put it on the back burner. I’m hoping to resume regular blogging in January.

But until then, I do want let everyone know that Rails 2.2.2 is out. Here’s the announcement. There are lots of new features that make the upgrade worthwhile.

A few notes about upgrading though. You need RubyGems 1.3.1 first. Here’s how I upgraded RubyGems, including the error I got while trying.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
>gem -v
1.2.0

>sudo gem update --system
...
ERROR:  While executing gem ... (NameError)
    undefined local variable or method 'remote_gemspecs' for
#<Gem::Commands::UpdateCommand:0x14a5744>

(if you get the same error, try this instead)
>sudo update_rubygems
...
RubyGems installed the following executables:
    /usr/local/bin/gem

>gem -v
1.3.1

(and then either...)

>sudo gem update
(which updates ALL gems not just Rails, or)

>gem install rails
(which updates just Rails)

>gem list --local
(shows you a list of all currently installed gems and all versions installed)

>sudo gem cleanup
(once you are 100% sure you want to erase old versions of ALL gems, not just Rails)

Next, edit the /config/environment.rb file in each of your Rails applications so that RAILS_GEM_VERSION is 2.2.2. Now you application will demand the new Rails version. (Even if you didn’t do a “gem cleanup” and still kept the old version installed. As long as you have both versions of the Rails gem, you can have some applications loading up 2.2 while others use still use the old Rails version.)

Then from the root of each of your Rails applications, you can run rake rails:update to update the application to the new version. (Never a bad idea to make a backup copy first.) What does that update change? It may depend on your current Rails version, but for me, it updated the default JavaScript files and also /config/boot.rb.

Bookmark and Share

My Tools of the Trade

August 7th, 2008

Whenever I learn a new set of skills—such as photography or cooking—I want to learn as much as I can about the tools that the pros use.

Sure, to learn photography you need to understand exposure and depth of field, but that’s only part of what it takes to be a real photographer, to be a good photographer. What camera and lenses should you buy? What brand of film? I even pay attention to borderline ridiculous details like what kind of camera bag the pros use. Learning first-rate cooking skills won’t do you much good if you don’t have a good set of pans. Any chef will tell you that having quality, sharp knives make a world of difference in the experience of cooking, even though it may not change the flavor. And, as I love to watch Gordon Ramsay scold, keeping a clean kitchen is an essential (and too often overlooked) step in producing quality food.

The point is that there is more to learn than just the fundamentals. It makes sense to learn from the trial-and-error experience of people who are already working with these tools everyday. I may decide I disagree with their preferences, but knowledgeably making a different choice is much better than stumbling around on my own. Plus in the process, I know I will discover some of the intricacies and pitfalls that come with working in the field.

In that spirit, here are the tools that help me as a web developer.

Read the rest of this entry »

Bookmark and Share

Attachment_fu Tip

July 29th, 2008

I installed the latest version of attachment_fu for a project I’m working on. I ran into a problem that I wanted to document here in case anyone else runs into the same thing.

The before_thumbnail_saved callback in attachment_fu is useful for tasks like giving thumbnail versions the same attributes that parent images have. So if an image belongs to an artist, the callback can give the thumbnail the same artist_id as the parent. The callback originally yielded two values to a block—record and thumbnail—like this:

1
2
3
4
before_thumbnail_saved do |record, thumbnail|
    thumbnail.artist_id = record.artist_id
    thumbnail.visible = record.visible
  end

But now it yields only one value: thumbnail. To get the same functionality as before, you will need to add a line of code to first find the parent record.

1
2
3
4
5
before_thumbnail_saved do |thumbnail|
    record = thumbnail.parent
    thumbnail.artist_id = record.artist_id
    thumbnail.visible = record.visible
  end

If you haven’t tried attachment_fu yet, here are some links you may find helpful:

Bookmark and Share

CRUD Scaffold Generator

June 27th, 2008

Scaffold

Rails 2.1 removed the original scaffold generator and replaced it with a new RESTful scaffold generator.

Bummer.

I’m not talking about the dynamic scaffolding that comes from putting “scaffold :model” in a controller. That “dynamic scaffolding” was removed in Rails 2.0 and few of us miss it. I’m talking about when you type “ruby script/generate scaffold Model” from the command line and get generated model, controller and view files as a result.

While I understand that Rails is “opinionated software” and that they want to encourage everyone to get on the REST bandwagon, I think completely removing the old scaffold generator was a mistake for one simple reason:

It unnecessarily raises a barrier to entry for beginners.

When beginners first start on Rails there is a lot to digest. Installation issues, Ruby language, MVC architecture, ActiveRecord, Rails syntax, routes, migrations and deployment—just to name a few. In my opinion, asking someone eager to learn Rails—someone who may have a background in PHP but who still doesn’t understand code blocks or the basic Rails .find syntax—to also use REST from the start is only going to frustrate them and slow the growth of Rails adoption. They need to walk before they can run. We have added best practices for advanced users at the expense of the newbies.

Read the rest of this entry »

Bookmark and Share