Archive for the 'Projects' Category

Published by Niels on 02 Jul 2006

NanoBlogger plug-ins

New releases of the code and gallery plug-ins for NanoBlogger. The code plug-in now no longer causes two blank line to be sent to stdout. The gallery plug-in now handles different versions of NanoBlogger better, i.e. the version check to determine which version of NanoBlogger is running does not cause an error anymore. It also delays the cleanup of meta files on Apple Mac OS X so I hope this is handles better now.

  • The new gallery plug-in can be downloaded here.
  • The new code plug-in can be downloaded here.

Enjoy and if there are any questions or problems contact me.

Published by Niels on 07 Jun 2006

Another category

I had some frustrating experience with sitecopy. A tool I used to maintain this and other web sites. After some investigation is seemed to have a blocking read in one of its functions. Now I could have tried to fix this or contacted the developers about it, but it had to be solved the difficult way: I wrote a similar application myself in Bash :).

Why Bash? Sitecopy had two disadvantages:

  1. It is written in C and had to be compiled for every platform I use. This made it hard to take an executable copy with me on, for example, a USB-stick.
  2. Since it makes use of standard SSH-tools it it also possible to do site maintenance from behind a firewall using connect (although that has to be compiled).

And of course writing the thing, documenting it and packaging it was fun as well :).

Rest to say that I still like sitecopy, it is a very useful tool but in this case I prefer to eat my own dog food.

The new site maintenance utility can be found here.

Published by Niels on 02 Apr 2006

Gallery Plugin version 0.3.0

A new release (0.3.0) of the Gallery Plugin for NanoBlogger to avoid problems with meta files on Mac OS X. These are files starting with ._ and contain data on files not stored on the native file system HFS.

This release will test if the plugin is running on Mac OS X and delete all picture files (*.jpg and *.png) starting with ._ in the current gallery directory.

The new version can be downloaded here.

Published by Niels on 09 Mar 2006

Check this out…

If you want to learn something.

Out of curiosity I started writing an application using PHP and MySQL. The syntax of PHP wasn’t a problem, it feels like a very dumbed down version of Perl, with which I am very familiar. And neither was MySQL. It is ‘just’ another RDBMS and a simple one at that. Nor was the design of the database tables a problem as I remembered my lessons and experiences on database normalization.

When I wanted to code the entire application I found out that I lacked experience in setting up a website using the n-tier model and the MVC (Model-View-Controller) pattern. After some searching Tony Marston provided me with a lot of good insights. He is very pragmatic, but don’t let that scare you off. The proof is in the pudding and a wonderful pudding he made and explains how he made it.

Published by Niels on 14 Jan 2006

Ideas on blog comment spam prevention

One of the reasons I don’t provide a comment facility is that it is very hard to prevent spammers from abusing your weblog. The easiest way to prevent spamming is to work with a registration system: you can only post a comment if you have registered. This has the disadvantage that anonymous people, or people who accidentally came at your site and found something interesting, can’t post comments.

One method of making it possible for anonymous users to post comments is asking the user to type in the text appearing in a so-called CAPTCHA. But if the captcha is too simple the spammer’s automated systems will recognize the text in the picture and are then still able to log in and put spam in the comments. Captchas also have the disadvantage that people that have to rely on, for example, braille readers, cannot post anonymously.

Apart from the braille readers I think the captchas can be best implemented in the following manner:

  1. Make sure that the letters in the captcha are all of a different color and are overlapping. Overlapping letters make it harder for OCR software to guess the ‘word’.
  2. Don’t always ask the user to type in the whole word, but rather one of the following questions:
    1. Type in all letters from the captcha (mentioned that already, just being complete).
    2. Ask the user to provide a subset of the letters in the captcha. For example the first and the third letter. The subset should not be fixed, but be chosen at random.
    3. Ask the user to provide the color of one or more of the letters in the captcha. Since not all the weblog readers will be native speakers of your weblog’s language, it would be best to provide check boxes so that language mistakes can be prevented.

This ofcourse combined with the possibility to create user accounts so that if a spammer succeeds in breaching these barriers, the decision can always be made to shut off anonymous posting.

Another possibility is to also work with a blacklist that contains words and sites that are not allowed to appear in a comment.

Creating captchas on the fly might not always be possible. Especially not since I will be relying on Bash. So it might be a nice idea to write a tool that can create a lot of captchas and a list with the text and colors that are used in each off-line. These can then be sent to the site and the comments plugin would only have to choose a random captcha and a random question (see above) and check the answer with the information from the file. If these ‘standard’ captchas are refreshed on a regular basis it should provide some nice protection from the spammers.

It seems that the tools from ImageMagick provide all the functionality needed so I will have a look at them this weekend.

Published by Niels on 12 Jan 2006

The first release of the Code Formatting Plugin – Version 0.1.0

As mentioned in a previous blog, a plugin to format code snippets in NanoBlogger entries has been in the making. It seems that a first workable version can be downloaded here.

How does it work
In short: just start a line before the code snippet with ‘CODE(<language>){‘ and start a line with ‘}CODE‘ after the code snippet. No other characters may appear on this line. Example:

CODE(c){
#include <stdio.h>

int main( int argc, char* argv[] )
{
    (void)printf( "Hello, World!n" );

    return 0;
}
}CODE

This results in the following:

1
2
3
4
5
6
7
8
include <stdio.h>
 
int main( int argc, char* argv[] )
{
    (void)printf( "Hello, World!n" );
 
    return 0;
}

Here are some other examples:

C#:

1
2
3
4
5
6
7
8
9
10
11
12
using System;
 
namespace Hello
{
    class World
    {
        public static void Main()
        {
            Console.WriteLine( "Hello, World!" );
        }
    }
}

Bourne Shell/BASH:

1
2
3
#!/bin/bash
 
echo "Hello, World!"

The real XHTML generation is done by ViM, so be sure that that is installed on the PC you use for NanoBlogger. Since XHTML is basically XML where you are expected to do the formatting in a stylesheet, you can add the following to your stylesheet if the code needs to have a black background:

.nbcode { line-height: 120%; }
.nbcode .Comment { color: #00ffff; font-weight: bold; }
.nbcode .Constant { color: #ff40ff; font-weight: bold; }
.nbcode .Error { color: #ffffff; background-color: #ff6060; font-weight: bold; }
.nbcode .Identifier { color: #00ffff; font-weight: bold; }
.nbcode .PreProc { color: #8080ff; font-weight: bold; }
.nbcode .Special { color: #ff6060; font-weight: bold; }
.nbcode .Statement { color: #ffff00; font-weight: bold; }
.nbcode .Title { color: #ff40ff; font-weight: bold; }
.nbcode .Todo { color: #808080; background-color: #ffff00; }
.nbcode .Type { color: #00ff00; font-weight: bold; }
.nbcode .lnr { color: #ffff00; font-weight: bold; }
.nbcode body { color: #ffffff; background-color: #000000; }
.nbcode pre { color: #ffffff; background-color: #000000; }

Or the following if a white background is preferred:

.nbcode { line-height: 120%; }
.nbcode .Comment { color: #8080ff; }
.nbcode .Constant { color: #ff6060; }
.nbcode .Error { color: #ffffff; background-color: #ff6060; font-weight: bold; }
.nbcode .Identifier { color: #00ffff; }
.nbcode .PreProc { color: #ff40ff; }
.nbcode .Special { color: #ff40ff; }
.nbcode .Statement { color: #ffff00; }
.nbcode .Title { color: #ff40ff; }
.nbcode .Todo { color: #808080; background-color: #ffff00; }
.nbcode .Type { color: #00ff00; }
.nbcode .lnr { color: #ffff00; }
.nbcode body { color: #000000; background-color: #ffffff; }
.nbcode pre { color: #000000; background-color: #ffffff; }

Installation:
Depending on the version of NanoBlogger used place the plugin code.sh in one of the following directories:

  • plugins/entry/mod (>=3.2)
  • plugins/entry/body (3.1)
  • plugins/entry (>=2.8 && <3.1)

The plugin combines nicely with for example Markdown, as long as the plugin is called on the entry body before the Markdown plugin. Since code.sh comes before markdown.sh alphabetically this should not be a problem.

If you do not want NanoBlogger to call code.sh for every entry, the plugin can alternatively be placed in plugins/entry/format. If the code formatting plugin capabilities are needed just add code to the FORMAT: meta tag in the entry. As mentioned above, be sure to put it before any other format setting like markdown.

From blog.conf, nb.conf or using environment variables, the following variables can be set to influence the behavior of the plugin:

  • NBCODE_VIM
    Where ViM can be found. Defaults to vim.
  • NBCODE_TABSTOP
    Number of spaces a tab counts for. Defaults to 4.
  • NBCODE_SHIFTWIDTH
    Number of spaces for each indent. Defaults to 4.
  • NBCODE_EXPANDTAB
    Replace tabs with spaces (yes/no). Defaults to yes.
  • NBCODE_NUMBERING
    Add line numbering (yes/no). Defaults to yes.

Since this is the first release expect some bugs. Feel free to contact me for comments, questions and suggestions.

Published by Niels on 25 Dec 2005

Version 0.2.0 of the Gallery Plugin

Version 0.2.0 of the Picture Gallery Plugin is available. This version should play nice with versions of NanoBlogger <3.3.

Beware: This plugin has only be tested with versions 3.1 and 3.3 RC3 of NanoBlogger. If I have time I will try to test the plugin for other versions. But don’t let that stop you from doing the same and provide me with feedback :).

You can download it here.

Published by Niels on 21 Dec 2005

New Gallery plugin release – 0.1.0

After trying to add a second picture gallery to this site the plugin would overwrite the title and the introductory text for all galleries with the ones from the latest gallery. This has been fixed in the new release together with a minor bug.

You can get this release here

Published by Niels on 09 Dec 2005

First release of a Picture Gallery Plugin for NanoBlogger

As mentioned in a previous post we visited a Sinterklaas celebration where we took a lot of pictures. The problem was that putting them on-line using NanoBlogger was a bit cumbersome. After some investigation on the NanoBlogger Yahoo group I found that a man named Chris had written a picture gallery plugin. After contacting him about it, he was so kind as to make it available to me. As it was still in a somewhat rudimentary state and I really like to tinker, I started writing my own plugin.

It is now in a quite usable state so I am sharing this with the rest of the world. Its usage is (hopefully) quite simple:

Usage

  1. Install the plugin gallery.sh in the NanoBlogger plugin directory. The plugin can be downloaded here.
  2. Create a directory named galleries in the NanoBlogger image directory. Any sub-directory of galleries will be considered a gallery.
  3. Place the pictures (JPG or PNG format) in the sub-directory of galleries that you created.
  4. Adjust the template main_index.htm to include the variable $NB_GalleryLinks
  5. Run nb -u all.

The created gallery will get the title of the sub-directory in which the pictures are stored.

These are the basics. But the plugin also gives the possibility to:

  • Prepend an introductory text
  • Annotate arbitrary pictures

Prepend introductory text

Create a file named intro.txt in the place the pictures are stored using nb --draft intro.txt and treat it like you would treat a regular entry for NanoBlogger. The title you set in the entry will be the title for the gallery.

Annotate pictures

Create a file named annotations.txt and put a line for each picture you want annotated using the following format:

<picture file>,<annotation>

Picture file is the local file name of the picture. Do not include paths, just use the bare file name. Everything after the comma is then considered an annotation for the picture.

To make the gallery a bit more pleasant-looking adjust your website’s style sheet. You can use this as an example.

Published by Niels on 01 Dec 2005

What to do

So I made this script to help me maintain my site. But it only helps me when I upload the site to the remote host. Suppose I want to work on the site from different machines. How can I then keep everything synchronized? The simple answer would be: assume that the remote site is the original and find out what the changes are compared
to the local copy of the site. The workflow would then become:

  1. Retrieve the MD5 checksums and directory list from the remote server a using sftp.
  2. Compare these with the current files and directories.
  3. Get the files that need to be added using sftp.
  4. Delete the files that are no longer needed.
  5. Delete and create local directories as needed.

My problem with this approach is that I need two separate sftp sessions, which means providing the system with at least my password twice. Since I want to
be as efficient as possible (read: I am Lazy :) ) I would rather give it once.

As I currently see it I have the following options:

  1. Find some clever bash-trickery to make sure that I can keep one sftp-session open. But so far that does not seem promising.
  2. Use expect. Very good solution, but the urge to make the program rely on Bash and sftp is very big.
  3. Use something like Perl and Net::SSH. See 2.
  4. Learn more about sftp and ssh2 to see if there is a possibility to keep session information for at least long enough to do all the work.

Decisions, decisions. If anybody out there has some good suggestions, feel free to contact me….

« Prev - Next »