Tuesday, June 18, 2013

How do I concatenate text files on Windows?

Strangely enough, I've had this same question asked of me twice within the last week, so I figured I'd post it here.

At the command prompt, use this command:
type *.txt > outfile

If you name outfile with the extension .txt, you'll actually wind up with stuff duplicated because the *.txt will cause the output file to be input, too!


Monday, June 17, 2013

What does dcommit stand for in git svn?

It took me some scrounging around to find it, and I don't remember where I did, but git svn dcommit means delta commit.

Git stores full versions of files (and relies on compression to make everything as a whole a manageable size), but SVN stores deltas, or differences between files.

So, when pushing your changes to an SVN repo, git has to build deltas out of all the commits you are sharing and then commit those to the SVN repo.

Saturday, June 01, 2013

Building Mercurial (hg) -- fatal error: Python.h: No such file or directory

The version of Mercurial you get using sudo apt-get install mercurial is a relatively old one. But, if you download it from http://mercurial.selenic.com/, you can get the latest. However, in a fresh install of Linux Mint, I got the following error when I tried to run sudo make install:
mercurial/base85.c:13:20: fatal error: Python.h: No such file or directory
compilation terminated.
To fix this, you need to install the python-dev package using:
sudo apt-get install python-dev
You'll need to install python-docutils, too. Then you can run make install.

Saturday, February 16, 2013

Installing python-markdown on Linux

I am running Lubuntu. I couldn't find these directions quickly using a google search, so maybe this will help someone else out in the future.

First, install python: sudo apt-get install python

Next, install "pip": sudo apt-get install python-pip

Now, for markdown: sudo pip install markdown

 To run it, use markdown_py input.md

Sunday, April 24, 2011

Another go at Blogger

I had given up on Blogger because it looked like it wouldn't automatically word wrap.  But, there was some CSS that got copied from Stack Overflow when I copied some text for the previous post.  When I figured that out, word wrapping worked as expected.

So, here I am again.  I tried out WordPress in the meantime, but am afraid that their ads may eventually become as obtrusive and off-topic as the ones over at LiveJournal.

Monday, April 11, 2011

Take some repetition out of safely raising events in C#

Recently, I stumbled across this page:  http://stackoverflow.com/questions/786383/c-events-and-thread-safety This wasn't what I was looking for at the time, but the comment by JP Alioto is just so beautiful.

Events in C# are a bit weird.  One reason is that they can become null, and because no one wants their program to crash with a NullReferenceException, we had numerous methods that looked like this (where EventOccurred is a delegate of type
EventHandler<EventOccurredEventArgs>):
private void OnEventOccurred(EventOccurredEventArgs args)
{
    var handler = EventOccurred;
    if ( handler != null )
    {
        handler(this, args);
    }
}
Due to their nature, the event delegates are often used in multi-threaded code and could potentially become null at any point in time.  To correctly deal with that problem, the copy of the handler on the first line of the method is required to prevent problems when the last delegate method is removed from the handler after the compare to null but before we invoke it.  (event handlers are immutable, so there's no chance of EventOccurred becoming null while we're invoking it):

We literally had dozens of these methods scattered through our source code, one for each EventHandler type in each class that used it.  But, adding the following extension method means we never have to write that boilerplate code ever again:
public static class EventHandlerExtensions
{
    public static void Raise<TEventArgs>(this EventHandler<TEventArgs> handler,
        object sender, TEventArgs args) where TEventArgs : EventArgs
    {
        if (handler != null) handler(sender, args);
    }
}
Because it's a static method, it can be invoked on even a null delegate and doesn't need to be copied to each class that uses it.

Because the handler is passed as a parameter to the method, a copy has already been made, so we don't need to make a local temporary to test against null and invoke:  the act of method calling makes that copy automatically for us!

Because it's generic, the compiler and CLR makes one for every EventHandler type we could invoke it on, automatically.

So, I've replaced those dozens of boilerplates with a single line like this:
EventOccurred.Raise(this, new EventOccurredEventArgs());
Beautiful!  (Microsoft's Framework Design Guidelines for .NET indicate that "raise" is the correct term to use when referring to what happens to an event.  [Other systems use "fire" or "signal."])

That really brightened my day a few weeks ago, and I wanted to share it yet another time on the web to increase the likelihood that folks will see it and adopt it.

First post!

LiveJournal started having just too many advertisements.  Annoying advertisements:  full screen, animated, with sound.  Just not cool.  So, now, I'm trying out blogger.  Maybe, at some point, I'll try to move some of my better posts from LiveJournal to here, but not tonight.