Skip to content

Web nourishment by John Ford and crew

Archive for the 'Programming' Category

WordPress 2.5 is officially out

John Ford Mar 29, 2008

WordPress 2.5

It’s official. WordPress 2.5 is now out with a crisp new admin interface and great new features. They’ve even redone the website. Here are some of my favorite changes:

  • A beautiful new admin interface.
  • A much more intuitive flow when making a post.
  • Multiple instant file uploads.
  • Thumbnail, medium and full-sized image options (and you can change the image dimensions in Settings).
  • A quick way to display your photos as a gallery
  • Easily add/edit tags so no more plugins are needed.
  • A visual editor that doesn’t break your code (this one is great for my clients).
  • Search now looks at posts and pages.

I’ve always thought that WordPress is one of the best blogging and content management systems. It’s incredibly intuitive for the user (even more so now) and extremely flexible for developers.

Thanks so much to everyone who has helped with WordPress!

Plugin Update: PDF Bookmark for Adobe Reader 8

John Ford Dec 21, 2007

Some of you may already be using the PDF bookmark plugin I put together for Adobe Reader. It provides a quick and easy way to bookmark the page your on and return back to that spot later. It’s especially handy when reading large PDF books.

Thanks to the input of Michael Hartl, I updated the plugin to work properly with Adobe Reader 8. Adobe turned on some security settings by default in the new Adobe Reader which broke the previous version of the plugin.

See the full details and download the plugin.

Installing ImageMagick/RMagick on Leopard

John Ford Nov 26, 2007

I’ve heard many horror stories of developers trying to install ImageMagick/RMagick to manipulate images. Fortunately, when I needed to install RMagick to use with the attachment_fu plugin, I ran across a fantastic script at OnRails.org by Solomon White (many thanks). It gave the steps to install RMagick from source without MacPorts or Fink.

I made the following minor changes to get it working for me and posted the script below.

  • Changed ‘wget’ to ‘curl -O’
  • Updated a couple of links that weren’t working for me
  • Updated sourceforge links to the east coast
  • Updated links to latest version of source code (as of today)
#!/bin/sh
curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz
tar xzvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure --prefix=/usr/local
make
sudo make install
cd ..

curl -O http://superb-east.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.23.tar.bz2
tar jxvf libpng-1.2.23.tar.bz2
cd libpng-1.2.23
./configure --prefix=/usr/local
make
sudo make install
cd ..

curl -O http://www.ijg.org/files/jpegsrc.v6b.tar.gz
tar xzvf jpegsrc.v6b.tar.gz
cd jpeg-6b
ln -s `which glibtool` ./libtool
export MACOSX_DEPLOYMENT_TARGET=10.5
./configure --enable-shared --prefix=/usr/local
make
sudo make install
cd ..

curl -O ftp://ftp.remotesensing.org/libtiff/tiff-3.8.2.tar.gz
tar xzvf tiff-3.8.2.tar.gz
cd tiff-3.8.2
./configure --prefix=/usr/local
make
sudo make install
cd ..

curl -O http://superb-east.dl.sourceforge.net/sourceforge/wvware/libwmf-0.2.8.4.tar.gz
tar xzvf libwmf-0.2.8.4.tar.gz
cd libwmf-0.2.8.4
make clean
./configure
make
sudo make install
cd ..

curl -O http://www.littlecms.com/lcms-1.17.tar.gz
tar xzvf lcms-1.17.tar.gz
cd lcms-1.17
make clean
./configure
make
sudo make install
cd ..

curl -O http://superb-east.dl.sourceforge.net/sourceforge/ghostscript/ghostscript-8.61.tar.gz
tar zxvf ghostscript-8.61.tar.gz
cd ghostscript-8.61/
./configure  --prefix=/usr/local
make
sudo make install
cd ..

curl -O http://mirror.cs.wisc.edu/pub/mirrors/ghost/GPL/current/ghostscript-fonts-std-8.11.tar.gz
tar zxvf ghostscript-fonts-std-8.11.tar.gz
sudo mv fonts /usr/local/share/ghostscript

curl -O ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.3.7-1.tar.gz
tar xzvf ImageMagick-6.3.7-1.tar.gz
cd ImageMagick-6.3.7
export CPPFLAGS=-I/usr/local/include
export LDFLAGS=-L/usr/local/lib
./configure --prefix=/usr/local --disable-static --with-modules --without-perl --without-magick-plus-plus --with-quantum-depth=8 --with-gs-font-dir=/usr/local/share/ghostscript/fonts
make
sudo make install
cd ..

To test that ImageMagick was installed properly you can check the version number.

convert -version

[you should see something like this]
Version: ImageMagick 6.3.7 11/26/07 Q8 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2007 ImageMagick Studio LLC

To test that ImageMagick is working properly you can run the following test. It will create a copy of the ImageMagick logo.

convert logo: logo.gif

script.aculo.us Slider Demo : Update Text Field and Change Slider

John Ford Jul 16, 2007

For those of you using the script.aculo.us Slider demos I’ve just added a new one. Sometimes you may have a slider and a text field to show the value. This example lets you change the value in the text box and the slider will update to match the value.

Example: Change Slider Value by Changing Text Input Field

Moment of Open Source Zen

John Ford Mar 17, 2007

Every day, as a developer, I’m grateful for the thousands of programmers around the world who have so graciously shared their time, knowledge, and programming code. I have access to millions of lines of free code at any moment through the Internet which allows me to write programs more easily, learn new concepts, and make a difference in society.

Yes, every open source developer plays their part in making life better. Take, for example, the recent updates to Sean Coon’s blog. A few tweaks to some great free programming code and Sean’s rapidly spreading the word about The People, Yes which directly engages the homeless community to share their voice through blogging. He’s able to send a text message which is then automatically relayed to his friends/acquaintances (through Twitter) and also posted to his blog (using a modified version of Alex King’s Twitter Tools plugin). Don’t forget that in conjunction with this great plugin there are other pieces of the free code puzzle - the powerful blogging tool, the simple programming language, and the server’s solid operating system. All of this was made possible by many generous programmers sharing their time and skills.

So here’s to the programming language, plugin, framework, and code snippet givers around the globe. You truly make a difference in the world.

The Architect and Builder Dilemma

John Ford Dec 4, 2006

Blueprint
(Originally uploaded by sweetsexything)

One of the problems I’ve seen over the years, in corporations where I’ve worked and as a business owner, is the misconception that a builder (a developer in this case) can quote a project without the blueprints. I often times receive a request for a quote (10 pages long) and it says something like this:

We want a dynamic website with a unique design and easy to follow navigation that we can update ourselves.

That’s basically the equivalent of going to a car dealership and asking “how much is a car with wheels and doors?” Until you tell them the make, model, and all of the features you want they can’t give you a real price.

The Problem
The problem with this process is that the client and the developer both have expectations and a vision for the project but you’re not talking apples-to-apples. Sure, the developer can give a quote based on vague information but everyone loses during the process. The client loses because their expectations aren’t going to be met. The developer loses since they can’t possibly give a realistic quote. What do you do when you start working and the client expects the Ferrari (which they all do)? Both parties clash when they aren’t on the same page.

The Solution
Hire an architect. When I get a vague request for a quote I tell the client it will take a few hours of billable time and we’ll make a blueprint together. There is no reason for me to give a vague quote on a vague request. I’ll be quoting the Ferrari just to cover every possibility, and the client can’t afford the Ferrari. No one expects an architect to build a blueprint for free and it should be the same with a developer. Once the client has the blueprint they can send it out for quoting and will get apple-to-apple quotes back instead of a fruit basket.

No one is to blame for this misconception since the idea of web development is new and mysterious to most people. However, I challenge all developers to change things and educate the clients that come asking for help. They’ll appreciate the education, respect the architect idea, save money, save time, and you’ll prevent lots of future headaches.

script.aculo.us Slider Demos and Example Code

John Ford Nov 12, 2006

I’ve been following along the script.aculo.us Slider Demo discussion area recently and have tried to answer questions when possible. Since it’s difficult to post examples to the discussion I’ve compiled a more extensive set of Slider demos. Some are examples that I’ve wanted and others are in response to questions in the discussion area.

The demo code includes the following slider examples:

  • Standard Slider
  • Reversed Slider
  • Slider Controlled with Mouse Wheel
  • One Slider Controlling Multiple Sliders
  • Using Images to Spruce Up a Slider
  • Two Colored Slider
  • Submit the Slider Value in a Form
  • Use a Slider as a Scrollbar (added Nov 21, 2006)
  • Change Slider Value by Changing Text Input Field (added Jul 16, 2007)

It’s really amazing what you can do with the script.aculo.us library. Please let me know what you think!

has_many :through Self-referential Example

John Ford Nov 10, 2006

While using an association table for the first time with Ruby On Rails I had a bit of trouble finding an easy to understand example of has_many :through. I needed to build a self-referencing table where People could have other People as friends through a Friendship. I was getting “stack too deep” errors, “could not find the association” errors, and also crashing Webrick before I figured out the correct setup. Here’s how I did it:

# the people table
create_table :people do |t|
  t.column :name, :string
end

# the friendships association table
create_table :friendships do |t|
  t.column :person_id, :integer
  t.column :friend_id, :integer
  t.column :authorized, :boolean, :default => false
end

class Friendship < ActiveRecord::Base
  # don't have to give class_name or foreign_key b/c ActiveRecord reflection works here
  belongs_to :person

  # make sure to give class_name and foreign_key b/c ActiveRecord doesn't know what friend is
  belongs_to :friend, :class_name => "Person", :foreign_key => "friend_id"
end

class Person < ActiveRecord::Base
  # tell ActiveRecord that a person has_many friendships or :through won't work
  has_many :friendships

  # create the has_many :through relationship
  has_many :friends, :through => :friendships

  # an example of how to get only the authorized friends
  has_many :authorized_friends, :through => :friendships, :source => :friend, :conditions => [ "authorized = ?", true ]

  # an example of how to get only the unauthorized friends
  has_many :unauthorized_friends, :through => :friendships, :source => :friend, :conditions => [ "authorized = ?", false ]
end

Using Mouse Wheel to Control script.aculo.us Slider

John Ford Sep 30, 2006

You may have noticed that Google Maps will zoom in and out when you use your mouse wheel (or trackpad scrolling). If you want to do the same thing using the script.aculo.us JavaScript Slider here is an example to get you started.

The example uses a slightly modified version of Adomas Paltanavicius’ mouse wheel event code. Firefox 1.5 seems to work fine but not Safari 1.3. Please let me know how it handles in other browsers.

Example: Using Mouse Wheel to Control Slider

Update: I’ve created a more extensive set of Slider demos which includes the mouse wheel demo. (Nov. 12, 2006)

Execute Rails Code Before the View is Rendered

John Ford Sep 25, 2006

At one time, I was looking for a way to execute code for every action in my controller before the view was rendered. I saw this come up again yesterday in the #rubyonrails IRC channel so I looked at it a bit more. Currently, Rails provides a before_filter method which will “run before actions on this controller are performed” or an after_filter which will “run after actions on this controller are performed.” What I wanted was a before_render filter which would run right at the end of the action but before render/view was executed.

Here is one idea how to do this. Since you want the code to run right before render is executed just override the render method that’s in ActionController. You can put the following code inside any of your individual controllers or add it to your ApplicationController and it will run in all of your controllers.

protected
  def render(options = nil, deprecated_status = nil, &block)
    # your code goes here
    @rockon = "rock and roll!"

    # call the ActionController::Base render to show the page
    super
  end

This is just an example, and maybe someone will take this a step further and actually create a before_render filter plugin. It would be nice to have the same flexibility as before_filter and after_filter which allows you to include “:only” or “:exclude” certain actions.

Next Page »