Archive for the ‘Tech’ Category

How to Disable Autosave in WordPress

Monday, March 30th, 2009

The autosave feature in recent versions of WordPress (versions 2.5–2.7) is actually a misfeature:

… A misfeature is not a bug. Nor is it a simple unforeseen side effect; the term implies that the feature in question was carefully planned, but its long-term consequences were not accurately or adequately predicted (which is quite different from not having thought ahead at all).

The improper functioning of the WordPress autosave has bitten me several times. It’s supposed to prevent you from losing work by periodically saving your blog edits in the background, when in fact it has caused me to lose work by its very operation.

[WordPress Logo Inverted]

Basically, the most recent edits made to a blog entry often get dropped when you go to “Preview” or “Publish” the entry. In other words, during either of these two operations, it reverts you to what it had autosaved in the past and the new edits are lost. The frustrating thing is that most users would expect the “Preview” operation if not the “Publish” operation to properly save what’s in the edit box. So often, you might end up publishing an incomplete or incorrect version of your blog entry without even knowing it.

This is madness. Let’s stop it.

Find the following four files in the wp-admin/ directory of your WordPress installation:

  1. page-new.php
  2. page.php
  3. post-new.php
  4. post.php

and comment out the following line:

wp_enqueue_script('autosave')

by changing it to:

//wp_enqueue_script('autosave')

This will disable the autosave feature in the WordPress user interface.

A secondary part of the solution, too, is to always hit “Save Draft” before hitting “Preview”. I’m not sure if this is strictly necessary, but now I’m paranoid.

Thanks to Allen Day and William Lone for showing me how to do this.

New Theme

Monday, January 19th, 2009
[Milk Carton by http://openclipart.org/media/files/jonata/3950]

In the spirit of minimalization, I’ve decided to greatly simplify the look of my blog. So I’ve adopted and slightly modified the White as Milk theme (v1.8) designed by Azeem Azeez.

Some of the modifications I made include:

  • Set page width to 95%.
  • Set posts as justified text.
  • Set the <blockquote> text colour to #777 (grey) like the original WordPress Kubrick theme.
  • Disabled the underlining of hyperlinks.

I like the cleanness of the design, and it looks good in text-based browsers (and on mobile devices). Importantly, it puts the blog’s navigational elements after the main text on each page. I’m not sure about the right-aligned sidebar on the left, though. For one thing, it doesn’t show the hierarchy of my categories at all well.

There is some colour to this theme, but only if I post some code:

/*Background Color of the page*/
    body {background-color:white;}

/*Body text color*/
    body {color:#333;}

/*Text color of the blog title in the header*/
    #header h1 a {color:#3b6ea5;}

/*Text color of the blog description in the header*/
    .description {color:#333;}

/*Links color*/
    a {color:#0066CC}

/*Links hover color*/
    a:hover {color:#333}

/*Headings color*/
    .post h2 a, #sidebar h2 {color:#333;}

/*Headings hover color*/
    .post h2 a:hover {color:#0066CC;}

/*Width of the entire page*/
    #page {width:95%;}

Also, in this same spirit, the sidebar now only shows the Search box, About text, a greatly reduced set of Pages, an Archives dropdown, Categories, and two bits of syndicated content that I produce elsewhere (the RSS feeds). The WordPress (v2.7) Widgets functionality made it super easy to set up and arrange these elements on the sidebar without requiring me to edit the sidebar.php code as in the past. It is very slick.

Dialog Box

Wednesday, December 31st, 2008

Does the following dialog box make sense to you? That is, are you able to answer the question it asks?

[Nonsensical dialog box]

Think about it for a bit, then see the comments for this post for the answer.

School

Saturday, December 27th, 2008

[xkcd's 11th Grade]

Interestingly, Python was first released when I was in Grade 11. Via xkcd.

Jason’s Alternator Story

Monday, October 8th, 2007

My friend Jason Rule was in Edmonton for the Father’s Day weekend and had a funny trip back from Edmonton to Calgary. In his own words, here is what happened.

[Alternator photo by goodharbor. Used with permission.]

While driving in Edmonton, I noticed at one point my alternator light go on… It just happened for a second and I did not really think anything of it. Later as I was leaving the city, the light was about 50% on, so basically it’s putting out some power—the exact amount the car needs. By the Edmonton International Airport, the light was on and I was running on battery power (the battery power was making the spark for the engine).

I went into conservation mode and turned off all electrical systems but the radio.

Around Red Deer, the engine started skipping a beat and the radio died. There was not enough power to spark the plugs… I pulled over (leaving the engine running) and quickly wired up my second battery to the engine by the wires I had pre-installed years before. The car’s back to life!!! I turn off the radio and keep driving.

It starts raining… I try using the windshield wipers, but there is so little power, they take about 10 seconds to cycle. So, with no fan (defog) and no wipers… I continue.

I need to stop in Didsbury where Brooke’s dad lives. I needed to pick something up and get as much power as possible. About 10 km from Didsbury, the dash fails, no speedo, nothing… About 3 km from Didsbury, the car is skipping again. I am approaching a stop sign and go to apply the brake. The power going to the brake lights makes the engine quit. As I was still travelling fast, I pop the clutch and get the engine running again. I then stop the car with engine breaking and the ebrake. I just get to the house and park in front of her dad’s truck.

Without explaining what I was doing, I start his truck and start transferring as much power as possible via booster cables into the car battery. I also start charging the second battery via a charger…. How long to wait… it’s 8 p.m. and the sun is going down. By 9:45 p.m., it will be dark and I will need headlights and I will be screwed… But, I need as much power as possible.

I pull out almost all of the circuit breakers from the fuse box. At 8:15 p.m., I start driving, extra battery not connected, car battery driving the engine. There are no electrical systems at all…

I make it to just north of Airdrie. Engine, with no warning, fails… Poor steering and brakes (that was a surprise). I pull over and remove the primary battery and install the secondary battery. I tried to start the engine, but there is not enough power to turn the starter…. I get out of the car, push it backwards, down the little hill I was on… Pop the clutch and the engine is running… I’m off.

I make it to Deerfoot and McKnight. Engine again quits… I pull over and call Brooke. The Deerfoot Trail is nuts as cars are going by at nuts speeds. She comes quickly and now it’s about 9:30 p.m. I pull the extra battery from her truck and throw it into the car. The car starts and we start driving—Brooke following me and being my lights.

About five blocks from home, car again fails… We load the gear into the truck and leave the car there for the night… We come back the next morning with a charged battery and drive home.

Two points to this story:

  1. All that crap I carry in my car sometimes comes in very handy.
  2. MacGyver himself would have been proud!

– Jason

My First Bug Report

Tuesday, May 15th, 2007

I recently submitted my first bug report to the Debian Project, regarding mod_dav and apache2. It was accepted by the maintainers of the relevant packages, and they’re taking the necessary steps to fix it.

So I’m proud of my little contribution. :) Yay for me! Yay for Debian!

An awesome blog about Python, Linux, and System Administration

Friday, March 9th, 2007

I recently discovered an awesome blog about Python, Linux, and System Administration. Chris Siebenmann is a sysadmin for the University of Toronto Unix Systems Group. I could spend hours reading his archives. Smart guy. Articles are short and informative to the max. Hope you enjoy it:

Emailing cron output to different users

Thursday, February 1st, 2007

When a cron job generates output on either stdout or stderr, the output gets mailed to the owner of the crontab. Now, you can specify an alternative email address by setting the MAILTO environment variable in the crontab, but this applies to all jobs in the crontab.

So, if you want the output of different jobs to get mailed to different users, then you can just redirect the stdout and stderr of each job to the mail command like this:

13 02 * * *     /bin/backup 2>&1 | /usr/bin/mail -s "Cron <root@exobox> /bin/backup" \
user@example.net

MTR as a combined traceroute and ping tool

Thursday, December 21st, 2006

mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.” And it’s really cool.

Like ping, it sends “echo” packets from your machine to the target machine to measure latency and packet loss along the network path, but it continuously displays updated statistics in real time as it operates.

Like traceroute, it shows the names or IP addresses of each machine along the network path, also updating these statistics for each machine.

Here’s some (frozen) sample output from the ncurses mode (terminal mode) mtr:

                                My traceroute  [v0.71]
exobox (0.0.0.0)                                             Thu Dec 21 16:15:01 2006
Keys:  Help   Display mode   Restart statistics   Order of fields   quit
                                             Packets               Pings
 Host                                      Loss%   Snt   Last   Avg  Best  Wrst StDev
 1.                                         0.0%    20    0.4   0.3   0.2   0.7   0.1
 2.                                         0.0%    20    1.6   1.4   1.0   2.7   0.4
 3.                                         0.0%    19    1.3   1.3   1.0   2.7   0.4
 4. 10.0.0.25                               0.0%    19    1.1   1.2   1.0   2.7   0.4
 5. 219.142.10.17                           0.0%    19    1.4   2.6   1.2  16.0   3.3
 6. bj141-130-121.bjtelecom.net             0.0%    19    1.4   1.6   1.4   2.5   0.3
 7. 202.97.57.221                           0.0%    19  199.3  12.0   1.3 199.3  45.4
 8. 202.97.37.9                             0.0%    19    1.7  35.7   1.3 186.5  56.2
 9. 202.97.53.146                           0.0%    19    1.8   2.0   1.5   4.8   0.8
10. 202.97.61.50                            0.0%    19  284.6 292.2 278.3 305.8   8.7
11. so-4-0-0.mpr2.lax9.us.above.net        15.8%    19  286.2 291.9 278.6 325.2  11.5
12. so-5-0-0.mpr1.iah1.us.above.net        15.8%    19  313.2 323.8 311.3 340.5   8.6
13. so-5-3-0.cr1.dfw2.us.above.net          5.3%    19  319.6 331.1 314.1 404.6  20.3
14. so-0-0-0.cr2.dfw2.us.above.net         11.1%    19  696.0 718.7 693.3 797.2  33.7
15. so-3-1-0.cr2.dca2.us.above.net         36.8%    19  347.4 354.9 342.5 368.7   8.6
16. so-0-1-0.mpr1.lhr3.uk.above.net        11.1%    19  421.5 423.6 411.1 438.2   7.8
17. so-1-0-0.mpr3.ams1.nl.above.net        11.1%    19  433.9 438.9 422.4 514.1  22.0
18. DutchDSL.above.net                     33.3%    19  423.1 432.7 418.7 463.0  11.4
19. ge-0-1-0-v189.rtr1.ams-rb.io.nl        27.8%    19  405.8 414.7 398.2 434.6  11.6
20. 213.196.40.242                         23.5%    18  404.8 418.1 399.9 485.8  21.9

Looking at the Avg column (units in ms), the above output shows that my network packets pass through Beijing Telecom’s routers to the U.S., then to the U.K., and finally to their destination in the Netherlands. A large latency increase occurs between lines 9 and 10 (presumably leaving P.R. China), and another between lines 13 and 16 (U.S. to U.K.).

mtr has some interesting display modes besides the above, where it shows the latency of each packet graphically according to a dynamic scale. In this way, the above points of really large latency can be easily detected.

mtr can be obtained from the mtr website, or it can be installed in Debian/Ubuntu by:

# apt-get install mtr-tiny

or

# apt-get install mtr

for the ncurses or X11 versions, respectively, although mtr-tiny appears to be installed by default in the Debian and Ubuntu machines I have tested. So you may already have it.

The Machines Have Taken Over

Friday, December 8th, 2006

The latest comic from Dilbert speaks some truth about life as a Sysadmin:

[Dilbert: The machines have taken over]