If you get an error that looks like this:
Warning: Cannot modify header information - headers already sent by (output started at /home/.hostname/username/domain.com/wp-content/plugins/myplugin/myplugin.php:345) in /home/.hostname/username/domain.com/wp-includes/pluggable-functions.php on line 272
I feel your pain. It’s one of the more cryptic error messages I’ve run into. You need to trim the whitespace from the end of your php file. In this example, the file myplugin.php has 345 lines. Delete everything after the closing ?$gt;.
Share This
Comments
Check this out (click in the two input boxes and see what happens):
This unobtrusive javascript snippet (below) will add “highlighting” effects to textareas and text and password input fields. Just define “onBlur” and “onFocus” CSS class styles. The extra bonus (provided exclusively by me <grin/>) is that this function supports multiple class names for the highlighted elements. So your input of class “niftyInput” becomes an input of class “niftyInput onBlur” and, when it’s active, “niftyInput onFocus”.
function addHighlightFunction(field) {
field.onfocus = function () {
var N = this.className;
this.className = N.substring(0, N.length - 7) + ' onFocus';
}
field.onblur = function () {
var N = this.className;
this.className = N.substring(0, N.length - 8) + ' onBlur';
}
field.className = field.className + ' onBlur';
}
function initHighlight() {
if (!document.getElementsByTagName) { return; }
var allfields = document.getElementsByTagName('input');
for (var i=0; i<allfields.length; i++) {
var field = allfields[i];
var fieldType = field.getAttribute('type')
if ((fieldType == 'text') || (fieldType == 'password') ) {
addHighlightFunction(field);
}
}
var allfields = document.getElementsByTagName("textarea");
for (var i=0; i<allfields.length; i++){
var field = allfields[i];
addHighlightFunction(field);
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(initHighlight);
This is adapted from a script by Adam Kalsey, which also uses Simon Willison’s addLoadEvent function.
The effect above is accomplished with this CSS:
.onBlur { border:1px dotted #888; }
.onFocus { border:1px solid #F00; }
Elegant, huh? And if you want these behaviors to be form-specific, try something like this:
#Search .onBlur { border:1px dotted #888; }
#Search .onFocus { border:1px solid #F00; }
#Login .onBlur { border:2px solid #AAA; }
#Login .onFocus { border:2px solid #333; }
Share This
1 Comment
Quoting Coda Hale:
I’ve always appreciated the profoundly surreal pedagogical approach popularized by why the lucky stiff (who is a shatter-brained, god-eating holy madman).
I couldn’t agree more.
Share This
Comments
A quick reference for creating a Rails site. Not a complete introduction. More of a cheatsheet. Here’s how to build a sample web application — a web design portfolio:
- Host a domain on a server with Rails support (e.g. Dreamhost shared hosting).
- Create three MySQL databases. Call them portfolio_development, portfolio_production, and portfolio_test.
- Create the Rails application skeleton (folder structure, config files, etc.).
[host]$ pwd
/home/username
[host]$ rails portfolio
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
***
create public/stylesheets
***
create config/database.yml
create config/routes.rb
***
create script/generate
***
- Configure your new skeletal app.
- Edit config/database.yml — set up database hostname, username, and password.
- Edit config/routes.rb — direct the root to “admin”: change line 14 to:
map.connect '', :controller => "admin"
- Link from webroot (here, a folder called “domain.com”) to rails public directory (”portfolio/public”). This is good for security. We don’t want our source files to be under the webroot, where they may accidentally be exposed.
ls -l will confirm that we’ve correctly created the link.
[host]$ ln -s ../portfolio/public domain.com/portfolio
[host]$ ls -l domain.com
total 176
***
lrwxrwxrwx 1 username unixgid 16 2006-11-22 13:40 portfolio -> ../portfolio/public
***
- Rename index.html to index.html.old.
[host]$ cd portfolio
[host]$ mv public/index.html public/index.html.old
- Check the setup by browsing to http://domain.com/portfolio — which gives an error. That’s expected, though, because we haven’t created the “Admin” controller that it needs.
- Create the database table needed for our app. Save the following as db/create.sql and execute it on portfolio_development:
drop table if exists designs;
create table designs (
id int not null auto_increment,
title varchar(255) not null,
about text null,
image varchar(255) not null,
caption varchar(255) null,
primary key (id)
);
- Generate a scaffold. Rails will look for the corresponding table, and automagically give us CRUD (Create, Retrieve, Update, Delete) functionality for it!
[host]$ ruby script/generate scaffold Design Admin
***
create app/models/design.rb
create test/unit/design_test.rb
create test/fixtures/designs.yml
create app/views/admin/_form.rhtml
create app/views/admin/list.rhtml
create app/views/admin/show.rhtml
create app/views/admin/new.rhtml
create app/views/admin/edit.rhtml
create app/controllers/admin_controller.rb
create test/functional/admin_controller_test.rb
create app/helpers/admin_helper.rb
create app/views/layouts/admin.rhtml
create public/stylesheets/scaffold.css
“Design” is the name of the model, “Admin” is the name of the controller. Now that we have created the AdminController, we should see something cool at http://domain.com/portfolio! It’s our bare-bones (but working!) application.
- Time to pretty it up. Let’s customize the listing view.
- Edit app/views/admin.rhtml to something like this:
<div id="wrap"><div id="wrap2"><h1>Design List</h1>
<%
odd_or_even = 0
for design in @designs
odd_or_even = 1 - odd_or_even
%>
<div class="ListLine<%= odd_or_even %>">
<div class="ListActions">
<%= link_to 'Show', :action => 'show', :id => design %>
<%= link_to 'Edit', :action => 'edit', :id => design %>
<%= link_to 'Destroy', { :action => 'destroy', :id => design }, :confirm => 'Are you sure?', :post => true %>
</div>
<h3 class="ListTitle"><%= h(design.title) %></h3>
<div class="ListImage">
<a xhref="<%= design.image %>"><img xsrc="<%= design.image %>"/></a><br/>
<span class="ListCaption"><%= h(design.caption) %></span>
</div>
<span class="ListAbout"><%= design.about %></span><br/>
</div>
<% end %>
<%= link_to 'Previous', { :page => @design_pages.current.previous } if @design_pages.current.previous %>
<%= link_to 'Next', { :page => @design_pages.current.next } if @design_pages.current.next %><br/>
<%= link_to 'New design', :action => 'new' %>
</div></div>
- Edit public/stylesheets/scaffold.css to something like this:
body { background-color: #AAA; color: #333; }
***
.ListTitle { color:#244; font-weight:bold; font-size:x-large; }
.ListAbout { color:#244; }
div.ListImage { float:left; width:173px; margin:0 10px 0 0; }
div.ListImage img { width:173px; border:none; }
.ListCaption { font-style:italic; font-size:x-small; }
.ListActions { font-size:x-small; text-align:right; padding-left:1em; float:right; }
.ListLine0 { background: #D3E9CB; }
.ListLine1 { background: #F7F9DF; }
.ListLine0, .ListLine1 { padding:10px; border:2px solid #333; margin:20px; }
h1 { text-align:center; }
#wrap { width:787px; margin:10px auto; background:#FFF; border:4px solid #444; }
#wrap2 { padding:10px; }
- Look at your pretty, pretty site and think of the possibilities.

Share This
Comments
Herein, and hereinafter, I learn Ruby and Rails. They are elegant, they are beautiful, I am excited.
Ruby :: Overview
Ruby is a modern programming language. It is powerful and extensible like LISP and Python. It is forgiving and flexible like PHP, concise and coherent like Python. End your line with a semi-colon — or don’t. An ellipsis is three dots, but two is ok — we know what you mean. Need a variable? No need to declare it, no special symbol to mark it; just use it.
ruby = "A modern programming language which you will love."
ruby_adjectives = [ "modern", "powerful", "flexible", "concise" ]
ruby_adjectives << [ "clean", "elegant" ]
Ruby’s conventions reflect the collective common sense that programmers have developed through trying times. For examples, naming conventions just make sense: Little things — local, ephemeral variables and methods — use lowercase. Big things — modules, classes, constants — use uppercase. Lowercase names use underscores to split words, and uppercase names use camelcase words.
message_to_readers = "Please comment!"
DesiredCommentCount = 5
if (BlogPost.comment_count < DesiredCommentCount) print message_to_readers
Don’t just take my word for it that Ruby has so many redeeming qualities, try it out for yourself with this interactive tutorial.
If you’re too cheap to buy the canonical introductory Ruby text, I heartily endorse Why’s (Poignant) Guide to Ruby, a well-written and humorous guide which uses mnemonics brilliantly and effectively to not only introduce Ruby, but make it intuitive. Beginning programmers, especially, would do well to read it.
Rails :: Overview
Rails gives you a skeletal web application out of the box (the design of which incorporates many, many design principles learned the hard way over a span of decades) and tools to make working with it much, much easier. Rails is opinionated — it makes (good) infrastructure decisions for you, leaving you to think only of the application level — once you’re mastered Rails, that is! This is a prime example of abstraction, and is analogous to the divisions between layers in the TCP/IP stack and between kernel, drivers and programs. Asking a programmer to create the infrastructure, presentation, and functionality of a web application is a lot like asking for a kernel and a graphical user interface to go with the program they want.
It’s clear that only a select few programmers need to be under the hood creating infrastructure and tools — the rest should build application logic and user interfaces. Presentation is rightly placed in the hands of the specific programmer or designer, supported by countless templates and widgets. The application logic is up to you. Let Rails be your infrastructure, and you will have the pleasure of working with the Ruby programming language, a very well thought out Model-View-Controller (MVC) architectural pattern, and the revolutionary Prototype Javascript toolkit.
Model-View-Controller Pattern
Decouple data representation, application behavior, and presentation. Orthogonal design: it’s a good idea. The upshot is, when you change something you should be able to change it in one place — not here, there and everywhere. Rails keeps layouts in one place, data models in another, controller operations such as Create, Retrieve, Update and Delete (CRUD) elsewhere, and views still elsewhere (a library might have “author”, “book”, and “genre” views, which are just different ways of looking at the data).
Resources
Recommended reading. I’ve only included the good ones.
Dead Tree Books
Online References: Big
Online References: Small
Additional Tools
Next up: I try to build a quick and dirty rails app. Hilarity ensues.
Share This
Comments
According to the authoritative AnandTech (emphasis his):
Intel’s Core 2 Extreme X6800 didn’t lose a single benchmark in our comparison; not a single one…Compared to AMD’s Athlon 64 X2 the situation gets a lot more competitive, but AMD still doesn’t stand a chance.
These chips are not only screamingly fast, they also use less power. This is critical nowadays, as businesses get a double-whammy on their electricity bills — power to run the computers, and power to run the air conditioning.
The Core processor is so good because Intel doubled the very high-speed working memory on the die itself (to 4MB of L2 cache). Combined with the really fat pipe (a bus 256 bits wide) and extensive prefetching, the dual cores stay very busy. To be technical:
The Core architecture’s L1 cache delivers about twice as much bandwidth… while its L2-cache is about 2.5 times faster than the Athlon 64/Opteron one.
The chips also use “bigger, smarter circuitry that can do a lot in parallel” to combine steps when possible (macro- and micro-op fusion), saving about one operation in ten. This also applies to multimedia (SSE) processing (which is bigger) and advance loading (which is smarter).
Share This
Comments