February 4, 2009

Reflection snippet:

Type t = Type.GetType(kid.Attributes["type"].Value);
...
object o = t.Assembly.CreateInstance(t.FullName);

January 8, 2009

How to convert a string in ISO date format to a C# DateTime:

DateTime dt = DateTime.ParseExact(dateString, “yyyyMMdd”, CultureInfo.InvariantCulture);

Yet another DateTime conversion routine, this time using DateTime.ParseExact()

int integerDate = "20081113";

DateTime date = DateTime.ParseExact(integerDate.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);

Theory versus Experiment

October 3, 2008

As a former physicist, and an experimental/numerical/computational physicist at that, I am often in conflict with the “Theorists” be they Theoretical Physicists or Mathematicians.  In a programming context, I find that Theorists want to map out every last detail and believe that they can explain and account for every possible situation on paper.  This isn’t so surprising when you consider that’s what they do/did as TPs or Ms.  Yet in my opinion the best thing you can learn, whilst moving from junior to senior programmer, is how much you don’t know about what might happen.  This led me to think up a pithy phrase to use against a particularly wiley Ph.D. mathematician/”programmer” (I use the latter term loosely…):

“Theory without Experiment is just a set of internally consistent reasoning”

or to put it another way

“Theory is Ego, Experiment is Humility”.

EDIT:  And this pithy re-write that I’ve just found here (http://stackoverflow.com/questions/58640/great-programming-quotes):

The difference between theory and practice is smaller in theory than in practice.

:-)

Creating a 2d Array in R

September 3, 2008

Simple, first of all create a variable that contains (n*m) elements

>  a = rnorm(100*100, mean=100,sd=1)

then dimension it

> dim(a) = c(1000,10)

where the first parameter is the number of rows, and the second the number of columns.  Easy.

Useful “R” Snippet

September 2, 2008

I am using R quite a bit at the moment and found a useful snippet of code to generate random “coin tosses”:

x <- sample(c(-1,1), 1000, TRUE)

select stuff(stuff(convert(varchar(11), getdate(), 111), 5, 1, ‘-’), 8,
1, ‘-’)

Neat! 

http://www.garshol.priv.no/blog/105.html

 

 

Introduction

SvnMerge enables you to track which changes on another branch have been merged into your current working branch. This means that you won’t accidentally merge the same change twice. SvnMerge isn’t a trivial tool to use, so we’ll need to discuss how we are using it, and define some terminology.

Feature Branch: A branch that you are merging changes FROM. There can be more than one Feature Branch, gathering up features from multiple developers.

Target Branch: The branch that you are merging changes TO. There is generally only ONE Target Branch.

In this article, we are going to discuss how to use SvnMerge to track changes on one or more Feature Branches, into a single Target Branch. It is also possible to merge your Target Branch into one of the Feature Branches, but we won’t examine that.

SvnMerge works by storing within subversion, meta information about actions on your files/directories . By doing this it can tell whether a particular change has been merged from Feature to Target. However, because SvnMerge does not automatically commit this information, it is up to you to commit this info into Svn each time you perform an SvnMerge action. We will look into this specifics of that later.

Setting Up

SvnMerge is shipped with Subversion, but can also be downloaded from here: http://www.orcaware.com/svn/wiki/Svnmerge.py. ; It’s a Python script, although there is a windows executable available too. If you use the Python script you’ll need the latest version of Python: http://www.python.org/download/. ; Install Python from the installer, and put SvnMerge.py somewhere on your PATH.

Type SvnMerge.py –version to check that SvnMerge is installed correctly. It should display something along the lines of:

 

 

C:devTesttrunkmike2>svnmerge.py --version
svnmerge r<unknown>
  modified: <unknown>Copyright (C) 2004,2005 Awarix Inc.
Copyright (C) 2005, Giovanni BajoC:devTesttrunkmike2>

Initialising SvnMerge

SvnMerge is used from the command line, so some familiarity with that is assumed. Some familiarity with the svn command-line tools is also assumed, although you can also see what’s going on using the TortoiseSvn GUI.

First we have to tell SvnMerge which changes have happened on this directory BEFORE the Feature Branch was created. This is a tricky bit. Open a command window and cd into the Feature Branch directory (e.g., c:\dev\f1222)

type:

svn log

Note down the list of revisions before and upto the creation of the Feature Branch. For example, in this log output:

 

 

C:devTestbranchesmike2>svn log
------------------------------------------------------------------------
r2616 | e151145 | 2006-12-06 12:25:01 +0000 (Wed, 06 Dec 2006) | 1 linecreating branch
------------------------------------------------------------------------
r2615 | e151145 | 2006-12-06 12:24:33 +0000 (Wed, 06 Dec 2006) | 1 linecreated in trunk/
------------------------------------------------------------------------

The versions in question are 2615-2616. You will also need the full Svn URL of your Feature Branch, e.g., http://subversion.ny.company.com/svn/repos/OnSite/test/branches/mike2. ; You can get this by cd’ing into your Feature Branch directory and typing “svn info”. Now that we have this information, we can initialise SvnMerge. CD into the Target Branch directory, and issue this command:

 

 

 svnmerge.py init -r2615-2616 http://subversion.ny.company.com/svn/repos/OnSite/test/branches/mike2

where 2615-2616 is replaced with your versions, and the URL is replaced with your Feature Branch URL. If all goes well, you should get a message back like this:

 

 

property 'svnmerge-integrated' set on '.'

As mentioned earlier, you need to commit any changes created by using SvnMerge. SvnMerge creates a standard merge comment for you, in a file called svnmerge-commit-message.txt. If you issue the following command, you will check the changes into Subversion:

 

 

svn ci -F svnmerge-commit-message.txt

This should give you a result along the lines of

 

 

Sending mike2Committed revision 2625.

You must now delete the svnmerge-commit-message.txt file. SvnMerge requires that the branch it works on be free of uncommitted files. So do:

 

 

del svnmerge-commit-message.txt

SvnMerge is now initialised. Note that you only have to go through this process once for each branch whose changes you want to track.

Using SvnMerge

Once initialised, SvnMerge is relatively easy to use.

Type:

 

 

svnmerge avail

to show the list of available merges from all initialised branches.

To peform a merge, type: svnmerge merge -r<revisionNumber> where <revisionNumber> is the range of revisions that came up from svnmerge avail. Example flow:

 

 

C:devTesttrunkmike2>svnmerge avail
2624,2655

C:devTesttrunkmike2>svnmerge merge -r2624,2655
U    file2.txt

property 'svnmerge-integrated' set on '.'

C:devTesttrunkmike2>svn ci -F svnmerge-commit-message.txt
Sending        mike2
Sending        mike2file2.txt
Transmitting file data .
Committed revision 2656.

C:devTesttrunkmike2>del svnmerge-commit-message.txt

Multiple Feature Branches

SvnMerge is capable of integrating from more than one Feature Branch. To do this, simply perform the Initialisation against each Feature Branch in turn. When using “svnmerge avail” or “svnmerge merge” you need to add the “-S” parameter, which you use to specify the path or URL. If you are making many integrations from multiple branches, it may be worth creating some environment variables containg the Feature Branch URLs.

Uninitialise Merge Tracking or Changing the Revision Range

It is possible that you want to switch off merge tracking on a branch. It is also possible that you will enter the wrong range of revision when doing an “svnmerge init”. In both cases you can call “svnmerge uninit” in the Target Branch directory, adding the -S <branch url> parameter if you have multiple feature branches. Once you have done the uninit, you will need to do an “svn ci -F svnmerge-commit-message.txt”. You can then run another “svnmerge init -r<range-range2> <url>” as before.

I discovered recently that running “installutil.exe” on a executable actually uses references the PDB files of that program.  Therefore, if you’re deploying a new version of the service into your test environment you have to call “installutil /u” before you can overwrite the PDB files.