My Motorcycle Accident

November 23rd, 2007

exciting stuntman stuff

So, I took a spill on Monday. I was off to Monk’s Cross to get some groceries, and the night was cold and wet, and as I slowed to approach a roundabout my back wheel slipped away. I skidded down onto my left side, and the bike slid out ahead of me. I was alright and in one piece, but instantly smashed out of my brains on adrenaline. Some people stopped to help, and I remember being about the most polite I’ve ever been. A lady out walking her dogs let me put the remains of the bike in her driveway and drove me home. I talked to the police, but unless there’s a serious injury or debris, they don’t really need to know.

less frenetic, limping stuff

I now have a massive bruise on my left hip, and am a bit limpy. I heard today from the garage that has my bike that it’s probably a writeoff. If so, I’m going to take the money and buy a car, I think.

Lesson for the day; motorcycles aren’t the ideal form of transport in wet, possibly verging-on-icy roads.

Memories from better times

Steve's Suzuki Bandit 600s

Wordpress experiences so far.

November 23rd, 2007

These are my initial impressions to using Wordpress, the blog engine I’m now using for the site.

First some background; I’ve done web development before, so this is an area I’m comfortable with. Honestly, though, the only skills you need are the abilities to edit a text file and to use FTP.

Installation was actually really easy. Download the application from Wordpress, edit a config file, upload everything, view a installation wizard on the web, and it’s up. So, getting hold of a basic site was really very simple, certainly compared to other blog engines and cms’s I’ve tried

What’s really nice, though, is the ability to add themes and plugins. Themes are visual ’stationary’ for the site, and there is a master site which has loads of themes to choose from. just download a theme’s zip file, and unpack it into a themes folder, and it’s ready to go. Plugins are about as easy, too; plugins provide some clever additions to the site. For example, I’m using the slickr plugin to show my flickr photos, and [reCAPTCHA] to keep spambots out of my comments.

Markdown in wordpress

November 23rd, 2007

I’m just starting to use markdown, a simple markup language that looks a lot like the old plaintext email syntax common on the early intarpipes.

 Here's how you write **bold** and _italics_, and
 here's how you write a link to [stevecooper.org][scorg]

   [scorg]: http://www.stevecooper.org

which turns into

Here’s how you write bold and italics, and here’s how you write a link to stevecooper.org

this words with Wordpress which powers this blog, and is also available as a little script to turn your plain ole text files into lovely html. Nice if you’re more comfortable using plain text over html. Or if, like me, you’ve got a huge chunk of stuff already written in it…

Is SF a genre?

November 22nd, 2007

Have you ever considered that science fiction may not be a genre?

People are always looking for ways to categorise art, and to group together things they like and things they don’t. It’s quite natural for people to lump together all the books with common elements.

I don’t want to try to offer a definition of sci-fi, but in common use, “sci-fi” is applied to books with speculative technology like nanotech, spacecraft, AI, or faster-than-light travel, or alien worlds or characters.

Problem is, that doesn’t really define what the story is about; is it a slasher movie, like Alien; a horror, like Event Horizon; a fairy tale, like Star Wars; or a kung-fu move, like The Matrix?

What I’m really wondering is, if someone says they like Science Fiction, what the hell do they mean? Have they told you anything about their tastes?

The two posts which inspired me; - “What Do You Hate Most About Short Science Fiction” - Hub Magazine’s post that alerted me to it.

Welcome!

November 22nd, 2007

I’ve been trying to roll my own blog software for far too long. Finally I’ve given in and let Google take over. Welcome to my new blog. You never know. Now that it’s easier for me to post, I might actually do so!

How to choose functions in Visual Studio with the keyboard

September 12th, 2007

In Visual Studio, there’s pretty good support for keys, but for me it lacks one significant feature. That is the ability to jump to a function from inside a class. That is, if you’ve got a class open the text editor, you want to see a list of functions in the class, choose one, and navigate to it, via the keyboard. You’ll be familiar with it from the two drop-down lists at the top of the code window; however, this drop-down can’t be activated by keyboard.

Here’s a cheap and cheerful implementation of the same features. Put it into your macro module, and map the macro to a keyboard shortcut.

Sub ChooseFunctionAndNavigateInIde()
    Try
        Dim functionIndex As New Dictionary(Of String, Integer)

        Dim doc As Document = DTE.ActiveWindow.Document
        For Each elem As CodeElement In doc.ProjectItem.FileCodeModel.CodeElements
            BuildCodeElements(elem, functionIndex, 0)
        Next

        Dim result As Integer = FChooser.SelectItem(functionIndex)
        If (result = -1) Then
            ' user cancelled
            Return
        Else
            Dim sel As TextSelection = CType(doc.Selection, TextSelection)
            sel.GotoLine(result, True)
        End If
    Catch ex As Exception
    End Try
End Sub

Private Sub BuildCodeElements(ByVal elem As CodeElement, ByVal functionIndex As Dictionary(Of String, Integer), ByVal depth As Integer)

    Try
        Select Case elem.Kind
            Case vsCMElement.vsCMElementClass, vsCMElement.vsCMElementDelegate, vsCMElement.vsCMElementEnum, vsCMElement.vsCMElementEvent, vsCMElement.vsCMElementEventsDeclaration, vsCMElement.vsCMElementFunction, vsCMElement.vsCMElementInterface, vsCMElement.vsCMElementModule, vsCMElement.vsCMElementProperty
                Dim name As String = Space(depth * 4) & elem.Name
                Dim line As Integer = elem.GetStartPoint(vsCMPart.vsCMPartWholeWithAttributes).Line
                functionIndex.Add(name, line)
            Case Else

        End Select


    Catch ex As Exception

    End Try

    For Each child As CodeElement In elem.Children
        BuildCodeElements(child, functionIndex, depth + 1)
    Next
End Sub

Private Class FChooser
    Inherits Form

    Dim lv As ListView

    Public Shared Function SelectItem(ByVal list As Dictionary(Of String, Integer)) As Integer
        Dim chooser As New FChooser(List)
        chooser.BringToFront()
        chooser.ShowDialog()
        Return chooser.Result
    End Function


    Public Sub New(ByVal list As Dictionary(Of String, Integer))
        lv = New ListView()
        lv.Dock = DockStyle.Fill
        lv.View = View.List

        For Each kvp As KeyValuePair(Of String, Integer) In list
            Dim lvi As ListViewItem = lv.Items.Add(kvp.Key)
            lvi.Tag = kvp.Value
        Next
        Me.Controls.Add(lv)

        AddHandler lv.KeyUp, AddressOf Key
        AddHandler lv.DoubleClick, AddressOf DoubleClick


    End Sub

    Public Result As Integer = -1

    Public Sub DoubleClick(ByVal sender As Object, ByVal e As EventArgs)
        If (Me.lv.SelectedItems.Count = 1) Then
            Me.Result = CType(lv.SelectedItems(0).Tag, Integer)
            Me.Close()
        End If
    End Sub

    Public Sub Key(ByVal sender As Object, ByVal e As KeyEventArgs)
        If (e.KeyCode = Keys.Enter) Then
            Me.Result = CType(lv.SelectedItems(0).Tag, Integer)
            Me.Close()
        ElseIf (e.KeyCode = Keys.Escape) Then
            Result = -1
            Me.Close()
        Else
            ' could be a letter, and therefore a seek
            Dim letter As String = e.KeyCode.ToString().ToLower()
            If letter.Length = 1 And Regex.IsMatch(letter, "[a-z0-9]“) Then
                ‘ find the first entry starting with this letter

                Dim found As ListViewItem = Nothing
                For Each lvi As ListViewItem In Me.lv.Items
                    Dim lviText As String = lvi.Text.Trim().ToLower()
                    If (found Is Nothing And lviText.StartsWith(letter)) Then
                        found = lvi
                    End If
                Next

                If (found Is Nothing = False) Then
                    For Each lvi As ListViewItem In Me.lv.Items
                        lvi.Selected = False
                    Next
                    found.Selected = True
                End If
            End If
        End If
    End Sub

End Class

Automatic Word Counts in MS Word

August 24th, 2007

I’m writing fiction at the moment. Which of course means I’m wasting time fiddling with formatting in Word.

A neat manuscript requires a word count on the first page. MS Word will give you a neat word count if you try the Insert menu, then Field..., choose NumWords, and hit OK.

It’s fine, as far as it goes, but it’s very precise; it gives you a count that looks a little too autistic; ‘7672 words’. What you’d rather see is an approximation to, say, 100 words. Something more like ‘7700 words’. It’s fiddly, but you can do it. Save this off in a template somewhere and you’ll have automatic, neat wordcounting for ever after.

  1. use Insert | Field...
  2. Click the ‘Formula’ button
  3. Type what follows and hit OK.

    = round ( 666 / 100 , 0) * 100

    You should see ‘700′ displayed as the approximate word count. This is 666 rounded to the nearest hundred. Change 100 to 1000 in the line above to round to the nearest thousand. To get your story’s count…

  4. Right-click the number 700 and choose ‘Toggle Field Codes’

  5. Select the number 666
  6. Hit ctrl-F9. The number now reads { 666 }
  7. Delete 666 and type NumWords instead.

    { = round ( { NumWords } / 100 , 0) * 100 }`

  8. Right-click the grey field and choose ‘Update Field’

  9. Voila! A neat wordcount, rounded to the nearest 100 words, and always up-to-date. The awesome power of a computer, neatly rounded.

A programming language only a mother could love

April 2nd, 2007

For the last few days, I’ve been trying to get my head around Common Lisp. Here are my first impressions.

It’s a language that is both incredibly beautiful and awfully ugly. I don’t know quite how it manages it. First, some of the ugly;

(apply 
  #'(lambda (x y) (+ x y)) 
  '(1 2))

See? Ugly. (The code is from Paul Graham’s free book, On Lisp.) It calculates the same as this C code;

return 1 + 2;

But, of course, all that #'(lambda stuff is doing more than the C; in fact, it’s doing more than C possibly can, which is where the beauty comes in.

It seems to me that Lisp has some fantastic fundamental ideas and some really awful choices in naming and syntax. For example, here’s the way you set a variable in the lisp console;

CL-USER> (setq x 4)
4

setq! not :=, not assign, not set; setq. That’s why I mean by awful naming.

Another; here’s how to get the first item in a list;

(car list)

again, car? Admittedly, you could use first, which is much more sensible, but the Lisp world seems to have settled on car, which stands for the ‘contents of the address register’, referring to a memory register in a long-dead machine from the 1970s. Awful naming.

However, the punctuation is great. It’s just that all the words suck.

If I were an author, and an editor gave me that advice, I’d quit. Wouldn’t you? So tell me something. Why is it that Lisp’s punctuation seems to hold the most profound and important programming concepts?

For example; the quote character — ‘ — allows you to freeze-dry code into something you can pass around like any other variable. If I want to multiply a global variable, x, by two, I’d say this;

CL-USER> (setq x 2)
2
CL-USER> (* x 2)
4

Thats sort-of-equivalent to this c-like code;

int x = 2;
int doublex = x * 2;

But now I’m going to use the quote symbol…

CL-USER> (setq x 2)
2
CL-USER> (setq doublex '(* x 2))
(* X 2)
CL-USER> (eval doublex)
4

I set the global variable x to 2. Then I set the variable doublex to be a piece of code which doubles the current value of x. Then, I evaluate the code in doublex, which gives me four.

The fun part is, you can’t do this in C — I’ve assigned arbitrary code to a variable. So now I can pass functions around like variables. Isn’t that just like function pointers in C? A little. But Lisp goes way beyond.

The awful glory is that the code is just a list; it’s the three symbols *, x and 2. And since lisp can edit lists, and programs are lists, lisp can edit programs. And it’s no trickier to edit programs than it is to change arrays.

I’ll say that again. Lisp programs can edit programs as easily as C can edit arrays.

Watch this. I’m going to examine code to see if it’s a multiplication.

;; `x` is a multiplier if it starts with the `*` symbol
(defun is-multiplier? (x)
  (eq (first x) '*))

;; is doublex a multiplier? returns true.
(is-multiplier? doublex)

Just by checking for the * symbol, I can tell you things about the code.

And if we decided that we actually wanted to calculate x+2, rather than x*2? Well, we just change a piece of the program

;; change the first item in 'doublex' to a plus.
(setf (first doublex) '+)

This is stuff you just can’t do in other languages. I’m going to keep looking into Lisp. It seems worthwhile.