Subversion build number in Visual Studio AssemblyInfo.cs

1 Comment »
  1. Download MSBuild Community Task
  2. Add the following to the .csproj file of the project you want to follow the svn build numbering. Add just before </Project>
  <!-- Import of the MSBuildCommunityTask targets -->
<import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />

<!-- to manage version number -->
<target Name="Version">
  <version VersionFile="version.txt" RevisionType="Increment">
    <output TaskParameter="Major" PropertyName="Major" />
    <output TaskParameter="Minor" PropertyName="Minor" />
    <output TaskParameter="Build" PropertyName="Build" />
    <output TaskParameter="Revision" PropertyName="Revision" />
  </version>
</target>

  <!-- to generate our personnal version info -->
  <target Name="AssemblyInfo">

  <svnversion LocalPath="$(MSBuildProjectDirectory)" Condition="Exists('$(ProgramFiles)\subversion\bin\svn.exe')">
    <output TaskParameter="Revision" PropertyName="Build" />
  </svnversion> 

  <assemblyinfo CodeLanguage="CS"
    OutputFile="Properties\AssemblyInfo.cs"
    AssemblyTitle="WindScanner"
    AssemblyDescription=""
    AssemblyCompany="Risø"
    AssemblyProduct="windscanner"
    AssemblyCopyright="Copyright © 2010"
    ComVisible="false"
    Guid="88812638-9547-4480-3bf4-4fe25103b35c"
    AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)"
    AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)"
    Condition="$(Revision) != '0' "/>
</target>

<!-- We launch these two targets -->
<target Name="BeforeBuild">
    <calltarget Targets="Version" />
    <calltarget Targets="AssemblyInfo" />
</target>

<target Name="AfterBuild">
</target>

Change the path of your svn installation if necessary.

You can now use stuff like

public static String Version
        {
            get
            {
                return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }

And the the changes reflecting the svn build!

Delegate.BeginInvoke vs ThreadPool.QueueUserWorkItem

3 Comments »

ThreadPool is performance-wise faster.

ThreadPool is fire and forget in the sense that BeginInvoke should always be paired with EndInvoke because exceptions are passed to the EndInvoke and should be handled here to avoid the exceptions lingering in memory.

If you don’t care about exceptions and have a relatively simple delegate that should be invoked, use ThreadPool.

If you have more complex delegates where things could go wrong that you care about, use Delegate.BeginInvoke/EndInvoke.

An example of how to use the ThreadPool.QueueUserWorkItem and lambda expressions:


ThreadPool.QueueUserWorkItem(callback => SomeMethod(someArgument));

Alternatively:


WaitCallback waitCallback = new WaitCallback(callback => { x => x*x});

ThreadPool.QueueUserWorkItem(waitCallback);

Remove .svn or _svn directories batch

No Comments »

The following batch file will search for “_svn” directories, clean the out and remove them.

I put it in a file called cleansvndir.bat and ran “cleansvndir.bat >> result.txt” from the command prompt.

<div id="_mcePaste">@echo off</div>
<div id="_mcePaste">pushd</div>
<div id="_mcePaste">for /f "usebackq tokens=*" %%d in (`"dir *_svn* /ad/b/s | sort /R"`) do (</div>
<div id="_mcePaste">ECHO "cd %%d"</div>
<div id="_mcePaste">pushd "%%d"</div>
<div id="_mcePaste">attrib -r *.* /s</div>
<div id="_mcePaste">ECHO "Deleting all in %%d"</div>
<div id="_mcePaste">del *.* /q</div>
<div id="_mcePaste">for /f "usebackq tokens=*" %%e in (`"dir /ad/b/s"`) do (</div>
<div id="_mcePaste">ECHO "cd %%e"</div>
<div id="_mcePaste">pushd "%%e"</div>
<div id="_mcePaste">ECHO "Deleting all in %%e"</div>
<div id="_mcePaste">del *.* /q</div>
<div id="_mcePaste">popd</div>
<div id="_mcePaste">ECHO "Removing dir %%e"</div>
<div id="_mcePaste">rd "%%e"</div>
<div id="_mcePaste">)</div>
<div id="_mcePaste">popd</div>
<div id="_mcePaste">ECHO "Removing %%d"</div>
<div id="_mcePaste">rd "%%d"</div>
<div id="_mcePaste">)</div>
@echo offpushd
for /f "usebackq tokens=*" %%d in (`"dir *_svn* /ad/b/s | sort /R"`) do (	ECHO "cd %%d"	pushd "%%d"	attrib -r *.* /s
ECHO "Deleting all in %%d"	del *.* /q
for /f "usebackq tokens=*" %%e in (`"dir /ad/b/s"`) do (			ECHO "cd %%e"			pushd "%%e"
ECHO "Deleting all in %%e"			del *.* /q
popd

ECHO "Removing dir %%e"			rd "%%e"		)	popd
ECHO "Removing %%d"	rd "%%d")

Run twice!

Batch info.

This suggests that the long filenames could be wrapped in double quotes (“”%%e”") instead of using the tokens=* parameter.

CLR profiler for memory leaks

1 Comment »

http://www.microsoft.com/downloads/details.aspx?familyid=86ce6052-d7f4-4aeb-9b7a-94635beebdda&displaylang=en

Labels in tables and figures not working

1 Comment »

Labels must always come after the caption!

Example:


\begin{table}[!h]
\sffamily{
\begin{tabularx}{\textwidth}{|l|X|c|}
text1 & text2 \\
\end{tabularx}
}
\caption{Texts.}
\label{tab:texts}
\end{table}

Setup default.ctp layout and home.ctp contents

No Comments »

The easy way:

Copy cake/libs/view/layouts/default.ctp to app/views/layouts/default.ctp and change it to suit your needs. The layout is the structure of your page contents.

Create the file app/views/pages/home.ctp (the pages directory does not exist by default, so create it first). This file will be rendered in the layout (default.ctp by default..) as the contents of your website when users visit the front page.

String concatenation optimization

2 Comments »

A discussion on the performance of various ways of concatenating string in c#.

Conclusion seems to be StringBuilder provides better performance for larger concatenation iterations. String.Format does not.

Comparison of foreach and List.ForEach

No Comments »

Sorting links

No Comments »

http://www.sorting-algorithms.com/ holds a nice overview of the most common sorting algorithms.

http://www.csharp411.com/c-stable-sort/show a demonstration of an insertion sort algorithm done in C#.

Installing VirtualBox guest additions on Fedora 11 in Windows (and change the screen resolution)

No Comments »

Once Fedora has been installed:

  1. Unmount the CD-ROM from the VirtualBox toolbar “Devices > Unmount CD/DVD-ROM”. This might require a restart of Fedora.
  2. Click “Devices > Install Guest Additions”, this will mount the guest additions CD.
  3. Open a terminal window (ALT+F2: gnome-terminal).
  4. Type su to switch to administrator mode. (Type the password when prompted).
  5. Install GNU Compiler Collection. Type: yum install gcc
  6. Install the kernel develop: yum install kernel-devel
  7. Now type  cd /media followed by cd VB ([tab] to complete, name depends on version)
  8. Type ./VBoxLinuxAdditions-x86.run (replace x-86 with amd64 if you are running 64 bit OS, and yes it is case sensitive.)
  9. Step 8 might fail because of version issues. You will be instructed to “install the build and header files for your current Linux kernel.” and you will be given the current kernel version. In my case this was 2.6.29.4-167.fc11.i586 so I did yum install kernel-devel-2.6.29.4-167.fc11.i586
  10. Log out and log back in and you’re done.

After installing you should get a higher screen resolution. However, it still might not be large enough to fit your screen fullscreen.

To resolve this follow these steps.

  1. Install the package system-config-display. Type yum install system-config-display
  2. While this installs the package, you will have to run system-config-display –noui –reconfigure before you can use it.
  3. This will create the /etc/X11/xorg.conf which you will have to edit. Type gedit /etc/X11/xorg.conf
  4. Locate the section “Device” and add before “EndSection”: Modes “1024×768″ “1280×1024_75.00″ (Change the resolution to fit your screen settings. _75.00 means refresh rate of 75 Hz.)
  5. Save the file. Log out and log back in.

WordPress Loves AJAX