Skip to content
    • About
    • About

Steve Cooper's Personal Blog

  • Markdown in wordpress

    November 23rd, 2007

    I’m just starting to use [markdown][md], 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][scorg]

    [scorg]: http://www.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…

    [md]: http://daringfireball.net
    : http://www.wordpress.com

  • 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](http://www.cs.cmu.edu/~mslee/format.html) 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.

    [On Lisp]: http://www.paulgraham.com/onlisp.html

  • Secret Santa 2006

    October 10th, 2006

    Once again I’m running Secret Commie Santa. It’s open to the York crowd, and thanks to Internet Shopping, anyone around the country that knows them.

    Why would you want to be involved?

    It makes your christmas shopping very, very easy.

    The idea is simple. We enter into a pact to buy each other pressies. Everyone gets a present of about the same value, even though people can afford to contribute different amounts. That’s the magic of Secret Commie Santa.

    1. Join the Pact by sending an email to steve

    /a t/

    @stevecooper

    /d o t/

    .org. Livejournal comments ain’t good enough!

    2. Tot up the amount you would normally spend on presents for everyone in the Pact. Tell me how much that is. We put all that money into a pot, and then share it out equally.

    3. I choose you a person I think you’d enjoy buying a present for, and act as a double-blind for questions, suggestions, and wishlists.

    4. You deliver your presents to me. If you contributed over the average into the pot, I’ll take the difference. If you contributed under the average, I’ll give you some cash to make up the difference. Equal Presents for All!

    5. With the help of my Magic Elves, I’ll deliver the presents out in time for Christmas.

    This year, since Santa has no sleigh, he’ll need to find some Magic Elves to help with the deliveries. Apply now for extra Christmas Kudos.

  • Clare and I are engaged!

    October 9th, 2006

    After a fantastic meal at Middlethorpe Hall, I asked Clare to marry me, and she said yes.* And then nearly sqeezed my head off with a great big cuddle.

    I’m over the moon.

    Here’s the ring;

    chuffing big diamond ;)

    We’ve not decided on a date for the wedding yet, but it’ll probably be in York, and Greg is the best man.

    —–
    * Well, of course she would. Who wouldn’t?

  • Leeds festival – thanks to cfw

    August 29th, 2006

    was very, very good to me and managed to get me tickets for Leeds festival over the weekend. I knew I love that woman for a reason ;)

    I saw Kaiser Chiefs, Arctic Monkeys, and Muse. Got right into the mosh with the first two, and that was a lot of fun. If you’re willing to get thrown about and crushed a bit, you can get right up the front with only a little effort; both times I was two or three rows from the front, right in the middle. You just need a bit of persistance and to not mind bruised ribs ;)

    Muse were fantastic, too. I stood a bit further off that time; still, the crowd were enthusiastic and it gave me more space to pogo rather than spend all my energy just trying to stand up.

  • Fantastic ’50’s science songs

    February 1st, 2006

    Wow

    These are, well, they’re delightful. Atomic-age kids songs about the joys of science. They feature the original soure of They Might Be Giants’ “Why does the sun shine”, and loads of other pieces of perhaps the finest empiricist kitsch ever…

    There is no disputin’,
    There is no refutin’,
    We’re all indebted to Sir Isaac Newton.

    Just when the creationists are getting you down, something like this comes along. Genius. GO LISTEN NOW!

    from the x-ray and electron and the quantum theory,
    down to Einstein and his formula for mass and energy.
    Hip Hooray! We’ve got atomic energy.
    It could mean a better world for all.

←Previous Page
1 … 8 9 10 11 12 … 18
Next Page→

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Subscribe Subscribed
    Steve Cooper's Personal Blog

    Have a WordPress.com account? Log in now.

  • Steve Cooper's Personal Blog
    View site in Reader
    Manage subscriptionsSign upLog in
    Report this content
    Collapse this bar