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:

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.

Line Movement Commands with PyPN

A bug on Google Code asked for an alternative to the built-in Transpose Lines command in Programmer’s Notepad, allowing a single command to move the current line up or down, allowing repeated use to shift a line through the current document.

To look at implementing this, I started with a python script - it’s so much quicker than writing C++ code to add these commands and going through compile/test for every change.

Here’s how to add these commands as a couple of scripts (which of course can have keyboard shortcuts):

import pn, scintilla, pypn.glue

@script("Move Line Up", "Text")
def MoveLineUp():
	s = scintilla.Scintilla(pn.CurrentDoc())
	l = s.LineFromPosition(s.CurrentPos)
	if (l == 0):
		return

	s.BeginUndoAction()
	s.LineTranspose()
	s.LineUp()
	s.EndUndoAction()

@script("Move Line Down", "Text")
def MoveLineDown():
	s = scintilla.Scintilla(pn.CurrentDoc())
	l = s.LineFromPosition(s.CurrentPos)
	if (l == (s.LineCount-1)):
		return

	s.BeginUndoAction()
	s.LineDown()
	s.LineTranspose()
	s.EndUndoAction()

Drop this in a file in your scripts directory to use it (remember you need PyPN installed), or wait for the next version of PN which has these commands built in.

Implementing Notepad’s .LOG Feature with PyPN

Notepad has a little-known feature where if you start a file with .LOG then every time the file is loaded the current date and time will be appended to the end of the file - allowing you to use a simple text file as a sort of diary.

A feature request came in for this and, pending a decision on whether to support it directly in Programmer’s Notepad, I decided to show how it could be implemented using the latest PyPN bits:


import scintilla, pn, pypn.glue, time

oldDocLoad = pypn.glue.onDocLoad

def docLoad(doc):
    """ docLoad handler to implement notepad .LOG functionality"""

    # Get the edit component:
    s = scintilla.Scintilla(doc)

    # Get the first line:
    lineLength = s.LineLength(0)
    text = s.GetText(0, lineLength)

    # If we have .LOG then add a blank line and then the date and time
    if text == ".LOG":
        timestr = "\r\n\r\n" + time.asctime(time.localtime()) + "\r\n"
        s.AppendText(len(timestr), timestr)

    # Jump to the end of the document
    s.DocumentEnd()

    oldDocLoad(doc)

pypn.glue.onDocLoad = docLoad

Just drop this code in a file called dotlog.py under Programmer’s Notepad\scripts and you’ll have the .LOG functionality. This all uses the very latest 2.0.9 unstable bits and the related PyPN build.

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

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

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

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!

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:

Context-Sensitive Python Help

Over on the forums, Michel Claveau shows how he gets context-sensitive help for Python code in Programmer’s Notepad:

  1. Check where your python help file is (e.g. c:\python25\doc\Python25.chm)
  2. Install keyHH from http://www.keyworks.net/keyhh.htm
  3. Create a new tool in PN:
        - name: Python context Help
        - command: c:\windows\keyhh
        - parameters: -MyHelp -#klink “%w” c:\python25\doc\Python25.chm
        - shortcut: F1
  4. Use it!

Open a Python-source-file, click on the middle of a “strategic” word (examples: “time”, “sys”, “open”, etc.) or select the entire word, like “time.sleep”, and finally press [F1] and [Enter]

[Forum Post]