• About
    • About

Steve Cooper's Personal Blog

  • LaTeX build server in Ruby

    January 23rd, 2008

    So — I’ve been writing functional specs at work in [LaTeX](http://www.latex-project.org/), a system for writing documents in a code-y markup language. Seems to fit nicely with being in a programmer headspace. The only thing, really, is that you have to compile your document. A bit of a ballache. But — I’ve also been learning [Ruby](http://www.ruby-lang.org/en/), and found it easy to knock up a program that sits patiently waiting for you to save your `.tex` source file, then recompiles it in the background.

    So, if you want to use it, here’s how it works;

    1. modify the script below to point to your own latex distribution and source file.
    2. run the script to start the ‘build server’
    3. open your `.tex` file, make a change, and save it.
    4. watch your ruby program spring to life and compile to a `.dvi` file
    5. Open that `.dvi` file in a viewer; I’m using `yap`.
    6. make more changes to your `.tex` file. Every time you save it, the .dvi file will be updated, and `yap` will reload it, giving you instant feedback on your changes. It’s just like a wysiwyg editor! almost!

    enjoy;

    #
    # LaTeX build server!
    #
    # Steve Cooper
    #

    file = “c:\documents and settings\steve\Desktop\bulk-activation-specification.tex”

    cmd = “”C:\Program Files (x86)\MiKTeX 2.7\miktex\bin\latex.exe” –interaction=nonstopmode “” + file + “””
    print “Compilation command:n #{ cmd }nn”

    class String
    def mtime
    File.new(self).mtime
    end
    end

    lastmtime = file.mtime

    while true
    currentTime = file.mtime
    if (currentTime > lastmtime) then
    print “file modified at ” + currentTime.to_s
    lastmtime = currentTime
    print “Compiling ” + file + “n”
    system cmd
    end
    print “. ”
    sleep 1
    end

  • lisp, the beautiful hydra

    January 21st, 2008

    I’m currently learning the programming language, [Lisp][]. If you’re not a programmer, you may wish to simply ignore this post…

    Lisp doesn’t have the mindshare it deserves. At fifty, it is the second-oldest programming language in the world, after [Fortran][]. I’m starting to see the whole history of programming as a struggle between the elder brother, Fortran, and the younger sister, Lisp.

    [Lisp]: http://en.wikipedia.org/wiki/Lisp_programming_language
    [Fortran]: http://en.wikipedia.org/wiki/Fortran

    Fortran Vs Lisp

    Programming is, at it’s core, an attempt to write down the solution to a problem so precisely that a mechanical device can perform the solution. We start with our own ideas, then use the program and a compiler to give us machine instructions;

    > ideas -> program -> machine instructions

    There are two approaches; one is to find better ways to describe machine instructions, which is what FORTRAN does. The other is to find better ways to describe ideas, which is what Lisp does. These two languages established for us an axis; Almost every programming language thereafter fits somewhere in between these two giants.

    So far, my impression is that lisp is an excellent language, let down by it’s awful libraries and tools; compared to Ruby, Python, Java, or C#, it just doesn’t have the libraries, and getting extant libraries installed is a dog. Worse, there is no canonical implementation, which means that your code may or may not work on someone else’s lisp; even worse news for libraries. It’s a pity, because the language itself seems beautiful and powerful. Meh.

  • Object-oriented vs class-oriented programming

    January 13th, 2008

    In his well-reasoned blog post, [chuck hoffman argues][ch] that what are normally called object-oriented programming languages should probably more rightly be called class-oriented languages. The distinction hopefully becomes clear when you consider this example.

    [ch]: http://nothinghappens.net/?p=214

    You are modelling people, and you want to create a person type. You should be able to strike up a conversation, so we want a ‘greet’ method for each. Our people (Alice, Bert, Charlie, and Dennis) all respond differently;

    – Alice responds to a greeting with “Hi!”, or a surly “what!?” if she hasn’t had her morning coffee.
    – Bert responds with either “don’t bother me, I’m walking Spot” or “what can I do for you?”, depending on whether he is walking his dog.
    – Charlie responds with either “good morning”, “good afternoon”, or “good evening”, depending on the time of day.
    – Dennis responds with “Hello, world!”

    Now, in C#, that’s really tricky. Each person uses a different function to answer your greeting. But in C#, the Person class can only have one implementation. You could munge them all together;

    class Person
    {
    string Greet()
    {
    if (isBert && isWalkingSpot) {return “don’t bother me, I’m walking Spot”; }
    else if (isAlice && !hasHadCoffee) { return “what!?”; }
    … etc
    }
    }

    But that is monstrous. You could create subclasses;

    class Dennis: Person
    {
    public override string Greet() { return “Hello, World!”; }
    }

    But this isn’t a class of thing; Dennis is singular. There’s not a whole class of Dennises, just a single solitary one.

    What you really want to be able to do is something like this; (excuse the made-up syntax)

    Person Alice = new Person();
    Alice.HasCoffee = false;
    Alice.Greet = { (HasCoffee ? “Hi!” : “what!?”) }

    Person Dennis = new Person();
    Dennis.Greet = { “Hello, World” };

    That’s what an object-oriented, rather than a class-oriented, version of c# might look like.

  • new blog — remninder

    January 11th, 2008

    Hi, All. If you missed it the first time — Clare and I are both writing to new blogs. They are available via livejournal, though — befriend [info] stevecooperorg and [info] ideapit.

    the original blogs are at http://www.stevecooper.org and http://ideapit.wordpress.com/. Rss feed can be found at http://www.stevecooper.org/feed and http://ideapit.wordpress.com/feed. PS: befriend [info] stevecooperorg and [info] ideapit now!

  • Power-assisted robot suits

    January 10th, 2008

    Right. The future is officially now;

    >As Japan’s dwindling ranks of farmers grow old, scientists are developing new ways to lighten their physical load and keep them productive. At the Tokyo University of Agriculture and Technology, a research team led by professor Shigeki Toyama has developed a wearable power-assist robot suit designed to boost the strength of farmers working in the field.

    from [pink tentatle](http://www.pinktentacle.com/2008/01/power-assist-robot-suit-for-farmers/)

  • First Fiction Sale

    January 7th, 2008

    I’ve made my first fiction sale! [Hub Magazine](http://www.hub-mag.co.uk) have publishing my 600-word story, [Brainfish](http://www.hub-mag.co.uk/?p=24) [[pdf)](http://www.hub-mag.co.uk/images/hub_40.pdf)

  • C# Coding; Missing Functions on IEnumerable

    January 3rd, 2008

    Me old mucker Spencer pointed out today that C# 3’s newly-refurbished IEnumerable<T> class lacks some basic features. Specifically, it lacks equivalents for the classic Map, Filter, and Reduce functions seen in functional languages. The first two are familiar as List<T>.ConvertAll, and List<T>.FindAll. The third isn’t so familiar, but is still very useful. I’ve also thrown in an implementation of ForEach for free.

    [Ben Hall](http://blog.benhall.me.uk/2007/08/converting-ienumerable-to-ienumerable.html) points out that it’s possible to extend the class, but I wanted to get a full, commented implementation of the three functions. Feel free to use this code in your own work.

    So, here they are;

    IEnumerableExtras
    ——

    public static class IEnumerableExtras
    {
    ///

    /// Do ‘action’ to every item in the list.
    ///

    /// The source type
    /// the IEnum
    /// the action to perform.
    public static void ForEach
    (this IEnumerable list, Action action)
    {
    foreach (T item in list) { action(item); }
    }

    ///

    /// Convert every item in the list using the converter
    /// function
    ///

    /// The source type
    /// The destination type
    /// the list to convert
    /// a function to convert
    /// one item to another.
    /// all items in the list converted by
    /// the converter function.
    public static IEnumerable Map
    (this IEnumerable list, Converter converter)
    {
    foreach (T item in list)
    {
    yield return converter(item);
    }
    }

    ///

    /// Returns a new enumerator containing only those
    /// elements which return true from ‘condition’.
    ///

    /// The source type
    /// the list to filter
    /// the ‘keep in’ condition
    /// the items for which condition(item)
    /// is true
    public static IEnumerable Filter
    (this IEnumerable list, Predicate condition)
    {
    foreach (T item in list)
    {
    if (condition(item))
    {
    yield return item;
    }
    }
    }

    ///

    /// Reduces a list of items to a single item; can be
    /// used to, say, sum a list of integers, or
    /// concatenate a number of strings, or find the
    /// maximum value in a collection.
    ///

    ///
    ///
    ///
    ///
    public static T Reduce
    (this IEnumerable list, Func reducer)
    {
    IEnumerator enumerator = list.GetEnumerator();
    if (enumerator.MoveNext())
    {
    // we have some items; start combining them together.
    T aggregator = enumerator.Current;
    while (enumerator.MoveNext())
    {
    aggregator = reducer(aggregator,
    enumerator.Current);
    }
    return aggregator;
    }
    else
    {
    // there was nothing in the list; return default.
    return default(T);
    }
    }
    }

    And here’s an **example program**;

    static void Main(string[] args)
    {
    IEnumerable maybeDoubles =
    new List {1, 2, null, 3, 4, null, null, null};

    // remove all the empty values: [1,2,3,4]
    IEnumerable noNulls = maybeDoubles.Filter(x => x.HasValue);

    // convert Nullable to non-nullable: >[1,2,3,4]
    IEnumerable notNullable = noNulls.Map(x => x.Value);

    // convert to strings so we can display them. [“1”, “2”, “3”, “4”]
    IEnumerable stringVersions = notNullable.Map(x=>x.ToString());

    // join the strings together with commas “1, 2, 3, 4”
    string displayString = stringVersions.Reduce( (s1, s2) => s1 + “, ” + s2);

    // show us the result;
    Console.WriteLine(displayString);
    Console.ReadLine();
    }

    So there you go. Enjoy.

  • Seasick Steve; top mississippi blues at Leeds Met

    January 3rd, 2008

    We stayed in over new year and watched Jools Holland’s [Hootenanny][jh]. Possibly the best act on it was a bluesman called Seasick Steve [(home)][ss] [(w’pedia)]. He is the bastard hillbilly child of Tom Waits and John Lee Hooker.

    Anyway, he’s [playing Leeds Met on the 31st][lm] and we’ll be going. Anyone fancies coming along, I think it’ll be a fine night of good music. Doors at seven, we’ll be getting a train around six, I suppose. Call me.

    [jh]: http://www.bbc.co.uk/later/series30/hootenanny/
    [ss]: http://www.seasicksteve.com/
    : http://en.wikipedia.org/wiki/Seasick_Steve
    [lm]: http://www.seetickets.com/see/price.asp?code=270534

  • I are drunk and full of pudding…

    December 25th, 2007

    and listening to my brother-in-law’s ‘Metal Christmas’ album. Mmmm… christmassy.

  • Happy Christmas!

    December 25th, 2007

    Have yourself a merry one, y’all.

←Previous Page
1 … 5 6 7 8 9 … 18
Next Page→

Create a free website or 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
    • Already have a WordPress.com account? Log in now.
    • Steve Cooper's Personal Blog
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar