Software


12
Sep 08

Hansel-link, so that’s where the traffic came from

I was out last night, and noticed when I got back that for a brief while the pnotepad.org server had stopped responding. I didn’t really look into it but this morning it all became clear as I read my feeds in Google Reader. Scott Hanselman has a great review of the use of WTL in Chrome (Google’s new browser) in his latest Weekly Source Code.

He linked to an old article I wrote way back when on the Joys of WTL. Fun to see my own words quoted back at me on Scott’s blog! WTL is still the UI framework used for Programmer’s Notepad 2 and in the most part has served very well.

I’d also downloaded the Chromium code to go spelunking into their WTL use having read the excellent post from Peter Krumins’ blog on Code Reuse in Chrome.

Interestingly Google include the WTL code in their distribution, this was something I’d been thinking about doing for PN to reduce the number of steps needed for people to build PN. It would also help with the fact that PN 2.0.9 needs changes currently only available in the WTL Subversion depot.


28
Jul 08

Software Tracking

While playing around with new search engine Cuil I stumbled across a software tracking website I hadn’t seen before: Wakoopa

Sign up for Wakoopa, install a small piece of software and they will track your software use and build up an online profile showing this information. In return they’ll recommend software for you and let you know about new versions. Seems interesting, and you can see a bunch of users of Wakoopa also like Programmer’s Notepad: Programmer’s Notepad on Wakoopa. When I looked, 101 users had clocked up more than 370 hours of usage, across Mexico, Norway, Iran and the Netherlands (amongst many more). Hello international users!

Using Wakoopa reminded me of Ohloh – an open source software tracker. Ohloh concentrates on tracking contributions to open source software, and analyses the source code and commit history for open source projects to build up interesting metrics on each project. Some interesting statistics from the Ohloh Programmer’s Notepad page:

162,795 C++ Code Lines (with a further 29,856 lines of comment)
79,622 C Code Lines (with a further 12,076 lines of comment)

The ratio of comment to code for Programmer’s Notepad 2 is 15.5%, and was only 9.6% for version 1 – clearly I’m getting better behaved in my old age. Statistics are also provided for each developer, and I can see that my Median Commit Rate is 10 commits per month changing 2,200 lines of code – that’s a lot of code for an evenings and weekends project. Of course some of my commits are code contributed by others – don’t want to take all the credit!

You can click the button below to add your support for Programmer’s Notepad at Ohloh:


5
Jun 08

C# Automatic Properties can have Attributes

The MSDN documentation for Automatic Properties (a C# 3 language feature) states that attributes are not valid on automatic properties. This is not true, the following code compiles and works as expected:

public class Data
{
[XmlAttribute]
public int SomeNumber { get; set; }
}

class Program
{
static void Main(string[] args)
{
using (XmlWriter w = XmlWriter.Create(@”c:\temp\test.xml”))
{
XmlSerializer s = new XmlSerializer(typeof (Data));
s.Serialize(w, new Data { SomeNumber = 5 });
}
}
}

Running this code results in an XML file looking roughly like this (I stripped some unneeded namespace declarations):

< ?xml version="1.0" encoding="utf-8"?>
<data SomeNumber="5" />

SomeNumber is saved as an attribute, so the XmlAttribute attribute worked correctly.


28
May 08

Microsoft Source Analysis Released

My team at work uses a fantastic Visual Studio add-in called Source Analysis to ensure consistency in our C# code formatting, commenting and organisation.

Microsoft Source Analysis

Source Analysis has now been released for the whole world to use, for free! The free download is available at the MSDN Code Gallery:

Source Analysis at Code Gallery

There’s also a blog here:

Source Analysis Blog


28
May 08

Damien Guard’s Envy Code R Font Updated

Another update to Damien’s great coding font Envy Code R, now at preview 7. This time we get a bunch of hinting improvements (Damien paid big bucks for the software to do this, consider donating!) and improvements when the font is used with larger sizes. Envy Code R also contains all the box drawing characters so makes a good console font – Damien even includes a .reg file to set this up for you.

Here’s what it looks like editing some python code in Programmer’s Notepad 2.0.9 with the Murky theme:

Envy Code R - preview #7

Read more at Damien’s Blog


28
May 08

Programmer’s Notepad 2 0.9.794 Released

It’s time for a second 0.9 unstable release, bringing a number of bug fixes and new features:

  • Automatic Update Check – at launch Programmer’s Notepad checks in the background whether there is an update available and shows you a message if there is one.
  • Vista open and save dialogs are now used throughout when you’re running Vista, previous OS versions should be unaffected
  • Programmer’s Notepad is now marked as Vista-aware, meaning that reads and writes to Program Files and similar locations are no longer redirected to the Virtual Store.
  • Find in Files can now search all open files
  • PyPN update 0.9 fixes a couple of event handlers

The update check is a very commonly requested feature. The system understands the difference between stable and unstable releases so most users will only ever see stable updates.

Currently there’s no UI option to enable unstable update checks (there will be!) but you can enable them for yourself by setting this registry value (assuming you’re using a default PN install):

Key: HKEY_CURRENT_USER\Software\Echo Software\PN2\General Settings
Value (REG_DWORD): CheckForUnstableUpdates = 1

209

What else is new in the 0.9 series?

  1. File browser window
  2. Open files window
  3. New, far better regular expressions support (multiline is coming)
  4. More colour schemes (I’m currently using ZenBurn) and the base styles adapt better with the colour schemes
  5. New PyPN release with more event hooks
  6. More Vista control styling dotted around (when running on Vista!)

Downloads

Installer: http://pnotepad.googlecode.com/files/pn209794.exe
Zip: http://pnotepad.googlecode.com/files/pn209794.zip
Portable Zip: http://pnotepad.googlecode.com/files/portable-pn209794.zip
PyPN for Python 2.4: http://pnotepad.googlecode.com/files/pypn-0.9.794-py24.zip
PyPN for Python 2.5: http://pnotepad.googlecode.com/files/pypn-0.9.794-py25.zip


28
Apr 08

Online Help now using Dokuwiki

The Programmer’s Notepad Online Help was previously run using MoinMoin, a wiki engine developed using Python and one that I was fond of many years ago. As with everything else on the internet, the help website had begun to develop a lot of spam over the last couple of months, and it would seem that MoinMoin just wasn’t up to the job of helping me to fight that.

I had to resort to regularly shelling into the server to rm -rf the page directories manually, as the web UI had nothing useful for removing several days of spam. In addition, managing the user base was a massive pain. Here’s how not to implement user control UI:

  • For every user operation, require the current user to switch into the user they wish to operate on (e.g. admin has to switch to be spammer)
  • Then and only then allow disabling of the spammer account
  • Once disabled, log the current user out rather than return them to their own account

For each bad user, I had to login, switch users, disable account, and log in again. I am fairly sure that the spammers had a much easier job than me!

I stumbled across Dokuwiki while browsing, it looked much better maintained and cared for than MoinMoin, and much more feature-rich – the two features I was particularly looking for were Docbook export (provided via a plugin) and support for Akismet for spam catching. Akismet support was still not available from MoinMoin last I checked. Dokuwiki also has a much better look and feel than MoinMoin alongside including a reasonable web administration interface, and built-in support for syntax highlighting code.

The Online Help site has now been transitioned to Dokuwiki, maybe now would be a good time for you to take a look and maybe contribute!


26
Apr 08

pnotepad.org hacked

Who would want to hack my website?!

It would appear that hacking doesn’t always take the “This site 0WneD by L33t Hax0rs” form, and that WordPress sites in particular are being targetted by Spam Injection hacks.

A few weeks ago I noticed that the ads on the front page of pnotepad.org were a little odd, lots of drug adverts and nothing programming related. I didn’t really think much about it, however, and moved on to something else.

Yesterday I got a friendly tip-off e-mail (thanks Erik!) telling me that pnotepad.org was serving up adverts and links for various drugs and other unpleasantness. Weirdly, I couldn’t see the problem at all. A little bit of investigation showed that these ads were only showing up if you used Firefox (not Safari or IE), but sure enough they were there.

I spent the rest of yesterday evening undoing the work of the hacker, tying down various parts of the host system, upgrading WordPress and re-doing the customisations used on the pnotepad.org site.

It’ll never happen to me.

I had put off upgrading WordPress for a long time due to thinking I’d need to rework various customisations with the upgraded code, and not really knowing how much effort the upgrade would cost me. I learned a lesson there! The hacker got in via well-known WordPress hacks. In the end, the pnotepad.org site didn’t work properly for a few hours – perhaps 10 at most (some while I slept). I wish I had just upgraded earlier.

If you run a WordPress-based site or blog, make sure you are up-to-date! This means you may have to take some pains and use newer versions that you’re not fully sold on, but the alternative is you may end up with a hacked site. You may not even notice at first!

There are some useful pages on hardening your WordPress install here:


4
Apr 08

Boost::Xpressive and Scintilla

Programmer’s Notepad has long needed an improved Regular Expressions engine. Currently PN uses PCRE for all tasks but searching Scintilla. This is because PCRE doesn’t support searching anything but a memory buffer – i.e. it doesn’t support iterators. We need iterator (or indirect access) support because a regex engine for a text editor can’t expect all text for the editor to be in a single contiguous memory block.

Boost::Regex has been suggested several times, but it still doesn’t support named captures. When allowing users to specify regular expressions for use in parsing, named captures can significantly simply the process. For example, when using a regular expression to parse compiler output we have two alternatives:

  1. \s*(?P<f>.+)(?P<l>[0-9]+)(,(?P<c>[0-9]+))?\s*:

    This uses the standard named capture syntax to name the three capture blocks: “f” for filename, “l” for line and “c” for column. The single expression can be parsed and understood by PN without the user having to understand capture indexing.

  2. \s*(.+)([0-9]+)(,([0-9]+))?\s*:

    This uses basic regular expression capture groups and results in the user having to enter three additional pieces of non-obvious data: the capture index for each capture. In this case these would be 1, 2, and 4 but this would potentially change for each output pattern.

 

I believe that using named captures significantly improves the user experience around this, especially considering that PN uses %f, %l and %c to represent the three named capture groups meaning that users don’t even need to understand regular expression capture syntax to use them.

Boost 1.35 introduces version 2 of Boost.Xpressive, the other boost regular expressions engine. Boost.Xpressive naturally supports iterators. Version 2 supports named captures.

Implementing a Scintilla Iterator

Xpressive requires a bi-directional iterator class (one that can move forwards and backwards over the contents). I’ve currently implemented a very simple, naive iterator to prove that this can work:

/**
 * std::iterator compatible iterator for Scintilla contents
 */
class ScintillaIterator : 
public std::iterator<std::bidirectional_iterator_tag, char> { public: ScintillaIterator() : m_scintilla(0), m_pos(0), m_end(0) { } ScintillaIterator(CScintilla* scintilla, int pos) : m_scintilla(scintilla), m_pos(pos), m_end(scintilla->GetLength()) { } ScintillaIterator(const ScintillaIterator& copy) : m_scintilla(copy.m_scintilla), m_pos(copy.m_pos), m_end(copy.m_end) { } bool operator == (const ScintillaIterator& other) const { return (ended() == other.ended()) && (m_scintilla == other.m_scintilla) && (m_pos == other.m_pos); } bool operator != (const ScintillaIterator& other) const { return !(*this == other); } char operator * () const { return charAt(m_pos); } ScintillaIterator& operator ++ () { m_pos++; return *this; } ScintillaIterator& operator -- () { m_pos--; return *this; } int pos() const { return m_pos; } private: char charAt(int position) const { return m_scintilla->GetCharAt(position); } bool ended() const { return m_pos == m_end; } int m_pos; int m_end; CScintilla* m_scintilla; };

 

This can then be used with Xpressive like this:

typedef boost::xpressive::basic_regex<ScintillaIterator> sciregex;
typedef boost::xpressive::match_results<ScintillaIterator> scimatch;
typedef boost::xpressive::sub_match<ScintillaIterator> scisub_match;

void test()
{
    sciregex regex = sciregex::compile("[0-9]+");
    scimatch match; 
    if (regex_match(m_scintilla, match, regex))
    {
        LOG("Yay!");
    }
}

This code is now available in Programmer’s Notepad subversion, and it seems to work. The iterator needs a bit of improvement to buffer data from Scintilla, or perhaps needs moving so that it doesn’t have to send a windows message for every character access. However, as a proof of concept it’s a good one and it suggests that we should be able to replace the current lacklustre regex searching support with fully featured multi-line support for the next release.


14
Feb 08

ClipX

Occasionally I get a feature request for Programmer’s Notepad asking for clipboard ring support. Personally I’ve never been a big fan of clipboard rings, although it may be implementations like that in Office that puts me off. Jeff Atwood is a big fan of them, however, and pointed to ClipX as an implementation that works regardless of what program you’re using:

clipx-intray

ClipX is freeware, and will from now on be my recommendation for those wanting Clipboard Ring support in Programmer’s Notepad. I’ve even downloaded it and installed it myself to see if I can see what the fuss is about!