Saturday, November 13, 2010

client denied by server configuration: .htaccess

I was getting the error "client denied by server configuration: /.htaccess" in one specific location recently and I wasn't sure what was going on. Permissions allowed the .htaccess file to be read, because the directives set in that .htaccess were taking effect. There was also no special reason for anyone to try and navigate directly to this directories .htaccess file.

It turns out, that the problem had to do with mod_autoindex. The directory in question is setup to use mod_autoindex and list a bunch of changelogs in the directory. For whatever reason, mod_autoindex wants to access .htaccess while it's building a list of files and since .htaccess files are disallowed for all in the normal Apache configuration, it's getting that permission error.

I've found that adding .htaccess to the IndexIgnore directive will stop this error from happening. Since I also have mod_autoindex ignore the link to a parent directory, my IndexIgnore directive looks like this.

IndexIgnore .. .htaccess

Sunday, November 7, 2010

Select Odd Rows in MySQL

Any time you can use a bitwise operator in place of a function call, it's a good thing. Selecting odd rows from a table in MySQL that have an auto_increment primary key is no exception.

SELECT * FROM mytable WHERE id & 1;


If you're unfamiliar with a bitwise AND, basically what it says is return true of the left operand has the same bits set as the right operand. The number 1 only has one bit set, and conveniently enough that one bit is the same bit that will only be present in odd numbers.

Wednesday, November 3, 2010

Blogger Double Post Bug

Decided to witch back to the default Blogger templates today. I'd stripped out all of the inline management tools when I created the old layout because I never needed them back then. I just started to miss them too much these days though, they make a lot of things easier.

In any event, I'd been putting this off for awhile because when I went to use the blogger template designer, I was getting a double post bug where my posts would show on the page twice whether I was on the index or just a single post page.

I couldn't seem to find an easy way to remove the extra posts widget so I just said screw it. Today though I got tired of putting it off, and decided to dig into the HTML of the template and hunt down the obviously present second posts widget.

From the looks of things, it just wasn't recognizing my posts template when it reverted to the default templates. It was looking at my posts widget as if it were a HTML widget or something other than posts, so it was adding a new posts widget. Though, the editor for my widget was still that of a posts widget, so there was no remove this widget button.

So, I singled out my own posts widget, the one with an id of "blog2", and removed the entire widget wrapper and all of the includables. Worked like a charm.

Tuesday, October 19, 2010

RSS Feed for SVN Changelog

I wanted to create an RSS feed for the SVN logs of a wallpaper site script lately. I've been keeping track of my progress on the feeds over at Ozzu in this thread.

So far I have the feed and an archive of the revisions being automatically generated and uploaded to the remote server daily.

Having an RSS feed for the SVN commit history presented an interesting problem where I couldn't really update the script_version field in the scripts schema.sql file without clogging up my revision history with worthless updates about the version number being updated.

So, I wrote a small script that exports a copy of the script, retrieves the SVN revision number from the repo, then updates schema.sql with the correct version number before finally packaging script for me.

In case anyone's curious, here's the code for that. This little script lives in my working copy on my workstation, not under version control.

#!/bin/bash

echo "Exporting HEAD revision..."
svn -q export http://192.168.1.102/svn/wallpaper-script

echo "Updating working copy..."
svn -q update

php -r '
$properties = `svn info -r HEAD`;
if(preg_match("#^revision:\s*(\d+)\s*$#im", $properties, $revision))
{
echo "Updating script version in schema.sql to 2.{$revision[1]}...", PHP_EOL;
$schema = file_get_contents("wallpaper-script/install/schema.sql");
$schema = str_replace("script_version'\'', '\''2.0'\'')", "script_version'\'', '\''2.{$revision[1]}'\'')", $schema);
file_put_contents("wallpaper-script/install/schema.sql", $schema);

echo "Compressing package...", PHP_EOL;
shell_exec("tar zcf wallpaper-site-script_2.{$revision[1]}.tar.gz wallpaper-script");
}
'

echo "Cleaning Up..."
rm -rf wallpaper-script

echo "Done."

Saturday, February 6, 2010

gedit Loads Slow

After a recent Ubuntu install I was having a problem with gedit loading slowly. When I would open gedit, I would geta blank gedit window with no toolbar buttons or text area.

The way I fixed this issue was to disable the file browser pane plugin from Edit -> Preferences -> Plugins. Once I disabled the file browser pane plugin I was able to get gedit to startup faster, immediately even.