Monthly Archives: August 2008

Restricting access to a WordPress post or page

A recent post on WordPress support forums asked if it were possible to restrict access to a WordPress post or page. I replied saying yes and suggested that the problem could be solved with a plugin. Well, it turned out to be a fun problem to contemplate, so here’s a rough first pass at that plugin. So far, no internationalization and no user-configurable error message; only post content is hidden (meaning that post title and comments, if any, are still visible to all). I am sure a lot of other nice things could be added, too, but the plugin seems to be functional and not dependent on version-specific features.

The installation is WordPress standard; download and unzip the restrict-to.zip file, create a restrict-to directory on your WordPress server under wp-content/plugins, put restrict-to.php into it, and activate the plugin using WordPress’ administrative interface.

To restrict access to a post or a page, put [restrict_to: user1, user2, user3] into the post or page in question, where user1, user2, user3 is a comma-separated list of users allowed to view the post or page (obviously, you can list as many or as few as you want, just don’t forget the commas). Users can be identified by their ID numbers or their login names (which will be handled in a case-insensitive fashion, so someuser, Someuser, and someUser will be perceived as identical).

Freakonomics wonders about American sports

Justin Wolfers writes:

the real puzzle from the 2008 Olympics is why the United States is so terrible at transforming raw talent — the millions of Americans born every year — into world champion material. Moreover, the puzzle deepens once one accounts for the fact that, living in one of the world’s richest nations, U.S. athletes have unparalleled access to the latest training technology.

Um, what puzzle? If you’re an American boy who can run, you join the track and field team only after failing football tryouts; if nothing else, track and field has a much lower chance of winning you a college scholarship.

Additionally, the U.S. has a thriving (and very commercially successful) alternative sports scene. So living in the world’s richest nation, U.S. athletes (aided by skilled business managers, of course) can create their own sports, complete with related film and video game industries (just look at Tony Hawk).

In short, the incentives in the U.S. are aligned in such a way that Olympic sports simply don’t attract a lot of interest from potential competitors; better opportunities are available elsewhere.

Firefox 3: a giant leap backward?

A few days ago, I upgraded to Firefox 3 and almost immediately regretted it. I don’t know what kind of usability testing folks at Mozilla do, but assuming they did some, I must be in the minority of Web users.

So what was so bad about Firefox 3? First, let’s take a look at the navigation in Firefox 3:

firefox3

and in Firefox 2:

firefox2

Why was it necessary to create the elaborate multi-colored control instead of tried and true Back and Forward buttons, each with its own list of pages visited?

More importantly, why is the “smart” (in reality, incredibly annoying) location bar necessary? In Firefox 2, having visited yahoo.com once, I could type “yah” into the location bar, hit a down arrow and Enter, and be taken to yahoo.com. In Firefox 3, the same sequence of actions yields an unpredictable outcome based on which Yahoo! service (mail.yahoo.com, answers.yahoo.com, whatever.yahoo.com) or site that has “yah” anywhere in its domain name or title tag (!) I visited last and/or most often.

Another small, but annoying “innovation” is the download window, which for whatever reason no longer has the Open control. So you downloaded an image and want to look at it? Sure, just open Windows Explorer and navigate to your download location… (Just because Firefox downloads to desktop by default doesn’t mean nobody ever changes this setting; I know I did, but then again, I might be in the minority…)

A small, but also annoying inconsistency: most alert messages in Firefox 3 are pop-ups, just as they were in Firefox 2, but the “Do you want Firefox to remember this password” alert somehow became a nearly invisible toolbar-like thing.

The end result of this acquaintance: I am back to running Firefox 2.0.16. Speaking of which, there was a very minor issue in the downgrade process that you normally don’t experience in an upgrade. Bookmarks, browsing history, etc. were preserved, but some of the settings weren’t. For example, the “You are requesting an encrypted page” and “You are leaving an encrypted page” dialogs, both of which I had turned off long ago, were shown after the downgrade even though they wouldn’t normally appear after upgrade.

Including vs. direct access

Note to self: you can tell whether a PHP script is being called from another script using include() or is being accessed directly using this simple function:

function is_included () {
  if (strpos('[Root]' . __FILE__, $_SERVER['PHP_SELF']) > 4) {
    return false;
  } else {
    return true;
  }
}

The function will return true if the script is being included by another script and false if the script is accessed directly.

Murat Iyigun ponders trends in war and conflict

Murat Iyigun writes:

The graph below shows a 10-year moving average of the number of wars and domestic conflict in continental Europe for the half millennium between 1450 and 1950. It depicts various intriguing facts, some of which have been identified long ago and some others that are recently surfacing.

For starters, the 18th century was the most peaceful on record. In fact, as the political science literature established in the 1960s, this trend holds true not only for Europe, but also for violent confrontations globally.

But why did violent conflicts rise in the 20th century as they did after a remarkable decline commensurate with Europe’s economic ascend in the 17th and 18th centuries? How will a reshuffling and steady evolution of the world political order affect these patterns (remember the League of Nations)?

And how does technological change influence the propensity to engage in conflicts? Here is an intriguing paper by Nippe Lagerlof which attempts to deal with that question.

* * * * *

Why the 3,000-mile salad may be here to stay

Lately, I seem to be reading a lot about the inevitable demise of the “3,000-mile salad”. The logic goes like this. Because of rising fuel prices, it will no longer be economical to truck California produce to the East Coast, so the East Coast will have to either grow its own produce or do without. Superficially, the argument is valid. But is it really?

A lot of energy expended in agricultire is actually expended while producing fertilizers. A head of lettuce grown closer to the East Coast just may require more fertilizer. Plus, the East Cost will have to build processing facilities, which California already has in place.

Obviously, this counteragrument is void without some numbers to back it up. Now where would I go to get the numbers?

Alternative engines?

A question from Askville:

Are real viable alternatives to the combustion engine being paid off/covered up by the oil industry for obvious reasons?

No. And please define “viable”…

There are Wankel engines, but so far, only Mazda figured out how to make them so that they are reliable (and they still are not as fuel-efficient as piston engines; Mazda RX-8 burns 15-20% more gasoline than BMW 325).

There are Stirling engines (those are actually external combustion engines and were first implemented as steam engines), but they are not particularly useful for transportation applications, because they have to have a heater, which requires time to reach working temperature, so if you had a car with a Stirling engine, you could be looking at 10-15 minutes between the time you turn the engine on and the time the car is ready to move. They are great for small-scale power generation though, precisely because in this application they are always on.

There are steam and gas turbines, but they work best when they are large (thousands of horsepower) and operate at near-capacity. In the stop-and-go traffic, turbines suck (there were enough experiments with automotive and locomotive turbines in the 1960s to figure that out). Plus, they are usually supercritical (meaning, the operating RPM is above the critical RPM, which is the RPM that causes severe vibrations), so every time you start or stop a turbine, it goes through a severe shakeup. It’s not a big deal for a power station turbine, which is stopped for maintenance once or twice a year, but for a car, which you start/stop several times a day, it’s a killer.

There are fuel cells, but so far, only Honda figured out how to make a limited-release, sort-of-production car with them. Additionally, Honda’s car runs on hydrogen, which is still an exotic fuel, hard to store and transport (not to mention that most of commercially produced hydrogen is made from oil or natural gas). There are potentially interesting experiments where concentrated sunlight is used to break water down into hydrogen and oxygen (the chemists call it “photolysis”), but the chemical breakdown occurs at about 2,500°C (4,500°F), and there are currently no materials that could last at those temperatures.

There are fuel cells that run on natural gas, but those are still bulky; a company called FuelCell Energy makes a state-of-the-art 300 kilowatt (420 horsepower) power generator, which weighs 77,000 pounds and has a footprint of 28 by 20 feet.

There are alternative fuels, such as ethanol and biodiesel, but their environmental impact is uncertain; they burn no cleaner than gasoline, it takes energy to produce them, and, if produced on a large scale, they could greatly increase the need for irrigation water.

So you can see that there are many avenues that are currently being explored, but a major breakthrough in terms of developing an alternative engine and/or fuel fit for transportation has not yet occurred for reasons that have nothing to do with oil companies…

Linking to an existing forum from WordPress

A question from WordPress support forums:

i built a forum, located here: www.mysite.com/forum, i want to display the forum button along side with home and about pages buttons, and have it linked to the above url, how do i do this?

There are several ways to get it done. Here’s one that is probably going to be the easiest for you.

  1. Create an empty page called Forum with the slug forum.
  2. Create a file in your theme directory called forum.php.
  3. In that file, put the following:
<?php

header('Location: http://yoursite.com/forum/');
die();

?>

Be sure that the file starts with <?php and there is no whitespace in front of the <.

This will create a link to the (empty) forum page, which would redirect to the forum.

ROR: is the jury finally in?

A while ago, Joel Spolsky called Ruby on Rails a platform “where The Jury Is Not In, So Why Take The Risk When Your Job Is On The Line?” Since then, it seems that the jury’s in and the verdict is not particularly pleasant for ROR…

Alex Payne, a developer at Twitter (which developed the namesake application, which is reportedly the largest ROR application deployed to date), has this to say on performance and scalability of ROR:

All the convenience methods and syntactical sugar that makes Rails such a pleasure for coders ends up being absolutely punishing, performance-wise. Once you hit a certain threshold of traffic, either you need to strip out all the costly neat stuff that Rails does for you (RJS, ActiveRecord, ActiveSupport, etc.) or move the slow parts of your application out of Rails, or both. It’s also worth mentioning that there shouldn’t be doubt in anybody’s mind at this point that Ruby itself is slow.

Meanwhile, Google developer Steve Yegge says that trying to use Ruby at Google was “the famously, horribly, career-shatteringly bad mistake”, as Google was built for scalability, not for rapid prototyping. He also points out that Ruby interprets AST directly, which is very slow…