CodePrairie .NET

South Dakota .NET User Group


  • Using the find command to find non executable files

    I had a bunch of dll's I had checked out of a subversion repo that needed to have the execute bit set on them.

    Enter the find command.

    I have never had a great grasp on how to use find, but finally my laziness got the best of me such that I not only figured out how to use it to find the files I wanted, but also how to send them through xargs to make the change.

    So here's the command I used:

    find . -name '*.dll' ! -perm -a+x -print | xargs chmod +x

    And here's the breakdown of the arguments . Is the directory we start our search from -name Says that the next argument is the name of the file we are searching for '*.dll' Is the pattern of the file we are looking for. In this case we are looking for *.dll or any file that ends with a .dll extension ! Says to negate the next argument -perm Says that the next argument will be some type of expression that qualifies the file based on its permissions -a+x There are multiple parts to this. The first - says that any permissions can match, if that wasn't there then the match would need to be exact? a+x (see man chmod(1)) is a way to specify permissions. It goes [user or group][operator][permission] so in this case it says Angelll(user, group, owner) [+]have e[x]ecute -print To be honest I'm not sure why this is needed, but all the examples I found with find and xargs seemed to use it

    Then the point of xargs is to take the output of the previous command and pass it as input to the command (in this case chmod +x)

  • My new git alias

    git alias's are very handy and powerful.

    Frequently I want to look through the log and have a quick view of who did what, so I created this alias

    git config --global --add alias.who-did-what 'log --pretty="format:%an - %s"'


    the output of which will be something like

    chriso - Fixed bug 145
    matt - Added some neat feature
    wes - fixed one of chris's bugs




    Technorati tags:
  • Using ruby to syncronize some files

    eCRM uses several open source projects.

    When the open source project changes I need to get those changes, build the code on my machine and then copy the new dll's into eCRM's DependentFiles/<ProjectName> folder.

    I have this somewhat automated using ruby (more specifically rake)

    Here is a simple class called LibCopy

    class LibCopy
      def copy(lib_files, lib_build_dir)
        libs_in_use = lib_files
        libs_in_use.each do |lib|
          puts "Check for " + lib
          lib_file = lib_build_dir + "/" +  lib.pathmap("%f") 
          if File.exists?(lib_file)
            puts "Found " + lib_file
            cp lib_file, File.expand_path(lib.pathmap("%p"))
            puts "lib not found:" + lib_file 

    And then the way I use this is like so

    task :castle_to_ecrm do
        dest_castle_libs = FileList['./ecrm/DependentFiles/Castle/*'],CASTLE_BUILD_DIR)
  • altnetgeekcode

    Scott Hanselman started a little meme called the Geek Code generator. Check out his post here for the details.

    For the record, here's my geek code. Click the link to view.

    Technorati Tags: ,

  • Developer Exchange Program Pt2

    Check out this post by Steve Harman He explains some of what we talked about on Saturday night far more eloquently than I ever could. And if you need some help explaining to your boss why you want to to do this it might help.

    There seems to be a fair amount of interest in this idea and that is very encouraging.

    I pitched this idea to my management today and they are definitely willing to support it. So the next step for me is going to be working with our HR / legal folks on some paperwork.

    The main things the paperwork needs to address are

    • Nondisclosure agreement
    • We're not going to steal your employee

    I am going to ask that they let me release any documents we put together under CC although I'm not sure if that will fly or not.

    Right now I am thinking we might get a lot more bang for our buck if we were to not trade but instead I goto your place and you goto someone else's and so on and so forth. That way you take some of my ideas and of yours and we get a bit of a snowball effect happening. Thoughts on that?

    Technorati Tags: ,

  • The Developer Exchange Program

    Just think, what if I came and worked with you for a week, and then you came and worked with me?

    I've been talking to several people here at #altdotnet and pitching this idea and it seems very well received.

    There are some obvious logistics to work out and it might be a difficult sell to management, but I think the payoff is very high.

    If this sounds interesting to you and you have any interest please contact me and lets see what we can do to help each other.

    Technorati Tags: ,

  • Command line history

    >history 1000 | awk '{a[$2]++}END{for(i in a){print aIdea " " i}}' | sort -rn | head
    116 git
    98 ls
    68 cd
    55 shoes
    19 mvim
    12 mate
    11 svn
    10 vim
    10 sudo
    10 cat

  • Using msbuild to create a bootstrapper for you installer

    I stumbled upon a nice task in MSBuild that you can use to create an executable file to install prerequisites for your application. I used to do this in the past with by just creating a Setup Deployment project setting prerequisites and holding onto the generated .exe

    The biggest problem with that was that it made it problematic to ship an installer with the version number in the filename since the setup.exe was bound to an msi filename.

    Using the GenerateBootstrapper task I can create this setup.exe file as part of my build process.

    Take a look at this snippet from one of my build files

      <BootstrapperFile Include="Microsoft.Net.Framework.3.5">
        <ProductName>Microsoft .NET Framework 3.5</ProductName>
      <BootstrapperFile Include="Microsoft.Sql.Server.Express.9.2">
        <ProductName>Microsoft SQL Server Express 2005 SP2</ProductName>
      <BootstrapperFile Include="Microsoft.Windows.Installer.3.1">
        <ProductName>WIndows Installer 3.1</ProductName>
    <Target Name="CreateBootStrapper">
      <Message Text="$(GenerateBootstrapperSdkPath)" />
      <GenerateBootstrapper ApplicationFile="$(OutputName).msi"
                            Culture="en-US" />

    The BootstrapperFile items define my prerequisites. The easiest way I found to see what the list of available prerequisites are was to create a Setup Deployment project and configure them, then look at the generated project file

    Then all I need to do is invoke the task and boom, setup.exe is produced.

    One thing I did run into when doing this is that you have to make sure MSBuild is using the 3.5 ToolsVersion or it won't find the merge modules.

    Also, the referenced prerequisites seem to only get installed with Visual Studio so I had to install it on my build server.

  • Hooking into new Nhibernate features from Castle ActiveRecord

    NHibernate has a lot of great new features. One of which is support for events.

    However, if you are using Castle ActiveRecord you can't specify these things in the configuration like you normally could and must instead roll up your sleeves and do it programatically.

    There are 2 hooks in ActiveRecord that we can use to accomplish our goal.

    The first is SessionFactoryHolderCreated which will notify you that the thing that holds the NHibernate ISessionFactory is ready. The next is RootTypeRegistered which happens after the active record configuration has been turned into NHibernate configuration.

    Here is a simple example

    IConfigurationSource source = ConfigurationSettings.GetConfig("activerecord") as IConfigurationSource;

    ActiveRecordStarter.SessionFactoryHolderCreated += (holder) => {

      holder.OnRootTypeRegistered += (sender, rootType) => {

        var mholder = sender as ISessionFactoryHolder;

        var nhConfig = mholder.GetConfiguration( rootType);

        nhConfig.EventListeners. PreUpdateEventListeners =

        new NHibernate.Event. IPreUpdateEventListener[] {new MyEventListener()};



    Technorati Tags: , ,

  • Quick Resharper Tip

    I'm upgrading my NHibernate references to the new Alpha build and have to change a bunch of using declarations from NHibernate.Expressions to NHibernate.Criterion.

    A simple way to have Resharper do this for you is to declare you own NHibernate.Expression namespace and rename it.

    Resharper will then find anywhere you declared a using for it and update it. When you are done just remove your namespace declaration.

    Technorati Tags: ,

  • git-svn and cherry picking

    git-cherry-pick is great command. It allows you to take a single commit made elsewhere and commit it to your workin g tree. From the man page:

    Given one existing commit, apply the change the patch introduces, and record a new commit
    that records it. This requires your working tree to be clean (no modifications from the
    HEAD commit).

    Today I was working on something and bumped into a bug that I had fixed in a release branch.

    I looked up the ticket for the bug and saw that it was fixed in svn revision 7624. So in order to find that commit in git I did

    git co 1.1
    SHA=`git svn find-rev r7624`

    Now I want this change in my 1.2 branch

    git co 1.2
    git cherry-pick $SHA

    All is well and good, until....

    git log

    commit b48bbd5217206bae0ad3d520e0820ffce5fb8bff
    Author: chriso <chriso@44e5888c-930d-754b-aefa-77e11abcc7dd>
    Date: Tue Feb 26 15:02:55 2008 +0000

    Working around a monorail change that broke me reseting the session state in the reset method of the wizard step. [refs #304]

    git-svn-id: https://buildserver/svn/repos/tags/1.1@7624 44e5888c-930d-754b-aefa-77e11abcc7dd

    See that git-svn-id line? If I leave it as is when I dcommit my 1.2 branch (which goes to trunk in svn) it will make the commit to the tags/1.1 branch in svn because that is where the most recent git-svn-id points to.

    The workaround is actually quite simple

    git cherry-pick -n $SHA

    What this will do is stage the changes but not commit. Now I can git-commit myself and remove the git-svn-id line.


    Technorati tags:
  • Claiming my blog

  • Follow Up: How do you manage your open source software

    A while ago I asked: How do you manage your open source software?. It seems like Bill Pierce had the same question, so I thought I should get to writing my follow up.

    I also asked this same question on the mailing list (whole thread is here).

    A lot of folks suggest not updating once you have picked some library to use. That is a fine approach in some cases, but in my opinion things like Castle and NHibernate are never done and I want to be able to update and take advantage of new features.

    So, how do I handle this today?

    1. Import the open source project subversion repository into a git repository.
    2. Build the project and copy its outputs to MyProject/Lib/OpenSourceProjectName using a rakefile I wrote.
    3. Commit the changes to MyProject noting the sha1 (from git) and the svn revision of the open source project.
    4. Create a git tag in the open source project git repository that ties it to the branch in my other project.

    What does this look like in practice?

    	cd /cygdrive/q/castle
    	git svn fetch #gets changes from castle svn
    	cd ..
    	rake build:castle libcopy:castle_to_myproject
    	cd myproject
    	git add lib/castle
    	git commit -m "Updated castle libs to sha xxxxxxxxxxxxxx svn revision 4000"
    	cd ../castle
    	git tag -f -a myproject-trunk

    So far I have been pretty happy with this approach. It could definitely be a little more automated, but it is doing the job.

    The link between the open source code and myproject is maybe a bit too fragile. I think I can do better using either git submodules or braid.

    I've been experimenting with braid on my rails projects, I'm not sure yet if it will make sense to use it with for this though.

    If you are interested here's the rakefile I use:

    require 'rake'
    class LibCopy
      def copy(lib_files, lib_build_dir)
        libs_in_use = lib_files
        libs_in_use.each do |lib|
          puts "Check for " + lib
          lib_file = lib_build_dir + "/" +  lib.pathmap("%f") 
          if File.exists?(lib_file)
            puts "Found " + lib_file
            cp lib_file, File.expand_path(lib.pathmap("%p"))
            puts "lib not found:" + lib_file 
    namespace :build do
      CASTLE_BUILD_DIR = 'q:/castle/build/net-3.5/debug'
      task :castle do |t|
        cd 'castle'
        puts "Building Castle...."
        puts sh("c:\\tools\\nant-0.86-beta1\\bin\\nant.exe -t:net-3.5 -D:common.testrunner.enabled=false -D:mbunit-console=c:\\progra~1\\mbunit\\mbunit.cons.exe")
        puts "Build Finished"
        cd '..'
      task :rhino do |t|
        #Seems like i may need to do an MSBUILD using the generator sln file before the whole build will work
        cd 'rhino-tools'
        puts "Building Rhino-tools"
        puts `msbuild.exe`
        puts "Done building rhino"
      task :update_rhino_from_castle do
        rhino_castle_libs = FileList['./rhino-tools/SharedLibs/Castle/*'], CASTLE_BUILD_DIR)
    namespace :libcopy do 
      task :castle_to_api do
        api_castle_libs = FileList['./OmniaAPI/DependentFiles/Castle/*'],CASTLE_BUILD_DIR)
      task :castle_to_mrrest do
        dest_castle_libs = FileList['./MRRestSupport/lib/*'],CASTLE_BUILD_DIR)
      task :castle_to_myproject do
        dest_castle_libs = FileList['./myproject/DependentFiles/Castle/*'],CASTLE_BUILD_DIR)
      task :castle_to_codegenerator do
        dest_castle_libs = FileList['./Castle.MonoRail.CodeGenerator/Libraries/*.dll'],CASTLE_BUILD_DIR)

    Technorati Tags: ,

  • Textmate Test

    This is a test post from textmate

    Here's some test code

        1 class Customer
        2   attr_accessor :name
        4   def say_hello
        5     "HI"
        6   end
        7 end

  • Mars Edit Test

    This is a test post from MarsEdit Line break. Here's some code so I can test my syntax highlight.


        1 using System;
        3 public class Customer {
        4   private string _name;
        6   public String Name {
        7     get { return _name; }
        8     set { _name = value; }
        9   }
       11   public String SayHello() {
       12     return "Hi";
       13   }
       15 }
        1 class Customer
        2   attr_accessor :name
        4   def say_hello
        5     "Hi"
        6   end
        7 end
More Posts Next page »
Powered by Community Server (Commercial Edition), by Telligent Systems