February 9, 2012

Solving WordPress 2.0 External Posting Errors

Since upgrading to WP2.0 I had not been able to use my favorite Weblog editor Ecto to do any posts which contained any inline tags, such as div or span classes. Also, it had been stripping the meat of Image tags. This was playing hell with my Technorati tags and, well, with how I like to blog.

Looking at the Ecto console, I saw that it was actually WP which was refusing to take the tags. With that bit of information, I rapidly zeroed in on the problem.

Solution

Edit your wp-includes/kses.php file, add the tag attributes you want.

I changed or added the following:
'div' => array ('align' => array (), 'class' => array (), 'id' => array(), 'style' => array()),
'span' => array ('class' => array (), 'id' => array(), 'style' => array()),
'p' => array ('align' => array (), 'class' => array (), 'id' => array(), 'style' => array()),
'tag' => array(), 'tags' => array(),

You can download the kses.php file with my fixes, if you like.

Now, everything but the img uploads is working as it should. I’ll figure that out and post the solution soon.

Update: 15 minutes later

To make images work, simply make sure you close the tag, and put a space after the src.

Bad:
<img src=”http://example.com/test.jpg”>
<img src=”http://example.com/test.jpg”/>

Good:
<img src=”http://example.com/test.jpg” />

Thanks go to Doncha for the img tag tip.

Technorati Tags: ,

Django encourages Flow

Django is one good web framework. It is the easiest portal into programming “Flow” I’ve found in ages. Programming for Django rapidly sucks me into an extremely rapid and engaging code-test-next cycle.

Flow = Productivity

There is an often quoted statistic in the programming world. A good programmer will outperform a mediocre one by a factor of 10:1. These numbers are pretty accurate in my experience, and I’ve long considered the reasons why this is so. My observation is that great programmers are not necessarily immensely more intelligent than their slower companions, rather they are more talented at entering Flow.

If my theory is correct, then anything which enables the programmer to get into this state is to be encouraged. The work done in a Flow state will be done much faster and with fewer errors than any other work. Perhaps more importantly for the programmer, it will be more enjoyable.

But what is Flow?

Mihaly Csikszentmihalyi has written two books about this topic, Flow, the Psychology of Optimal Experience and Finding Flow. I think the best summary of the experience is found in the first paragraph of Chapter 4 in Flow.

We have seen how people describe the common characteristics of optimal experience: a sense the one’s skills are adequate to cope with the challenges at hand, in a goal-directed, rule-bound action system that provides clear clues as to how well one is performing. Concentration is so intense that there is no attention left over to think about anything irrelevant, or to worry about problems. Self-consciousnes disappears, and the sense of time becomes distorted. An activity that produces such experiences is so gratifying that people are willing to do it for its own sake, with little concern for what they will get out of it, even when it is difficult, or dangerous.

How Django encourages Flow

  • It allows a Python programmer to use clear rules to create a data model and to apply it to the task at hand. It doesn’t require a lot of context-switching between Python and SQL, which helps maintain flow.
  • It breaks down the problems into clear, testable chunks, which means that one is not “programming out on a limb” for a long while, like I often find Java encourages me to do.
  • It uses Python to configure Python, which is a refreshing change from the increasingly XML-heavy frameworks found elsewhere, especially in the Java world. Not only is that “refreshing”, it is one less context-change that is likely to drop the programmer out of Flow.
  • It automatically produces “the boring parts” of the application. Unenjoyable drudgery such as creating admin pages is one sure way of dropping the programmer from the Flow state.
  • It is so quick to program in, problems are solved so rapidly, that it encourages you to do “just one more part”, thus making time fly by.

[tags]flow, python, django, webapp, productivity[/tags]

AJAX goodness for Invisible Castle

I just rolled my first real AJAX application out to testing. My Invisible Castle site is a die-roller for online gaming. It lets uses roll dice, and it lets their game masters or fellow players go look them up later. Fairly simple, but it got over 150,000 rolls last year alone.

I like to use the site as a testbed for new technologies that I’m interested in learning or exercising. This has worked out really well for me, leading me to the excellent Cheetah Template page template system for Python. Last fall, I completed a major refactoring of the site, and moved it to Dreamhost. With Cheetah in place, and the code all clean and lovely, I am now finding it very simple to add new features.

AJAX, why?

Despite it being a testbed, I don’t like to add features for the sake of features. That’s just silly. I could “ajax-up” the site, making it prettier I suppose. Maybe I’ll do that as I work on the site, but for my first AJAX app, I wanted something more interesting. So, I decided to open up the site to remote calls.

I want remote gaming sites to be able to embed a tiny amount of well-written Javascript, and end up with the ability to roll “in place” for their users. This morning, with the aid of Prototype and Behaviour libraries, I whipped out a nice remoting system in just a couple hours.

Cross-site

The most annoying part of the whole mini-app was enabling the cross-site AJAX call. I solved it by writing a quick PHP script which simply uses curl in the background to call my site, passing along the parameters. That script gets installed on the site which wants to use my roller, and bang, instant on.

It was fun to write. Take a look at the remote test here and let me know what you think. Notice, not a single line of ugly in-line javascript. Behaviour is a wonderful library!