Nick Parker
My ramblings on .NET...

Vim Tip of the Day - File Explorer Navigation

Monday, 5 May 2008 21:17 by nickp

I don't know how I didn't come across this before, but when using the file explorer built into Vim, you can tell Vim to automatically switch the working directory to the current file you are editing.  Normally in Vim if you performed a ":cd c:\projects\blah" and subsequently navigated three folders deeper to edit a file (say “c:\projects\blah\foo\bar\foobar\fun.cs”), then choose to go back into the file explorer from your current location by issuing ":e .", the "c:\projects\blah" will be listed, not exactly where you might expect to be.  If you edit your _vimrc file and put the following command in when navigating the file explorer window, your current directory will automatically be set based on the file you are editing, and thus we would be dropped back into "c:\projects\blah\foo\bar\foobar").

autocmd BufEnter * lcd %:p:h 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   General | Open Source | Vim
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Creating Objects - Round 3

Wednesday, 5 March 2008 18:08 by nickp

Ayende has been discussing the different ways of actually creating objects in .NET and the perf cost associated to each of them.  I thought I'd add to the mix one more method, using the DLR.  I've talked to several people who have identified concerns with the speed of the DLR so I found the results rather interesting.  The context is still the same, identify the time it takes to construct one million Created instances.

The delegate: 

delegate Created CreateInstance(int num, string name);

The structure:

    public class Created
    {
        public int Num;
        public string Name;

        public Created(int num, string name)
        {
            Num = num;
            Name = name;
        }
    }

 Grab the constructor:

ConstructorInfo ci = typeof (Created).GetConstructors()[0];

Define the parameters to be passed to the constructor (relative to the code block we are about to define):

Variable num = Variable.Parameter(SymbolTable.StringToId("num"), typeof (int));
Variable name = Variable.Parameter(SymbolTable.StringToId("name"), typeof (string));

Build a code block with the Ast factories for building expressions (this builds our function for creating new Created instances with our parameters):

CodeBlock block = Ast.CodeBlock("CreateInstance", typeof (Created),
                                  Ast.Return(Ast.New(ci, new Expression[] {Ast.Read(num), Ast.Read(name)})),
                                  new Variable[] {num, name}, new Variable[0]);

Compile our block:

CreateInstance create_instance = TreeCompiler.CompileBlock<CreateInstance>(block); 

 Invoke the compiled instance:

int iterations = 1000000;
Stopwatch watch = Stopwatch.StartNew();
for (int i = 0; i < iterations; i++)
{
     create_instance(i, i.ToString());
}

The results are rather impressive, the run time on my machine was 00:00:00.2737688.  It looks like creating objects within the DLR via a dynamic code block is pretty cheap.  I've included the source here if you want to run the example.  The DLR bits are based off a release from CodePlex two days ago, the RubyForge bits are much older and will not compile with the above code.  Thoughts?

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   .NET | DLR | Open Source | Ruby | Software
Actions:   E-mail | del.icio.us | Permalink | Comments (1) | Comment RSSRSS comment feed

Code to Live Video from Tulsa TechFest

Tuesday, 5 February 2008 20:09 by nickp
Jeffrey Palermo and I sat down with Chris Koenig while at Tulsa TechFest back in October to chat about the new ASP.NET MVC stack.  Josh Holmes just published an extract of our conversation out on Channel 9 here.  This was recorded back in October, right after the ASP.NET MVC stack was first made public by Scott Guthrie down at the ALT.NET conference in Austin, TX.  We discussed other things such as the open source movement and it's relationship to the Java counterpart but they didn't make the cut in the editing room.  You can watch the video directly here.  Have you played with the new MVC stack yet, if so what do you think?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   .NET | Open Source | Software
Actions:   E-mail | del.icio.us | Permalink | Comments (1) | Comment RSSRSS comment feed

ALT.NET Super Summary

Thursday, 11 October 2007 20:30 by nickp
It's simple in my opinion: Spreading pragmatic .NET

I wasn't there, however that's my interpretation of the vision. I think one of the core competencies any developer needs to espouse is passion. Passion is at the root of being a pragmatic developer, regardless of whether or not you’re doing .NET/Java/Ruby/LISP, etc. We are going through a hiring phase at work right now, during the interviews, passion is one of the top characteristics that I look for in a candidate. Passion is a catalyst for being pragmatic. Where does your passion lie?

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

NHibernate Performance

Saturday, 15 September 2007 12:17 by nickp

I am doing some research into the use of NHibernate over the use of the current data access layer we use at work. Overall, the results are very good compared with what we current had in place (lazy loading all properties, limited caching strategies to name a few), however I'm curious if anyone wants to ring in on past experience they have had with NHibernate. Our DBA is concerned that we will be losing out on cached execution plans from SQL Server by moving to NHibernate from stored procedures. It is my understanding that parameterize SQL can be just as fast, any comments?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Castle Presentation

Saturday, 18 August 2007 14:09 by nickp

I will be presenting at the September Iowa .NET User Group meeting, if you don't have any plans September 5th come on out for some free pizza and a presentation on the Castle MicroKernel/WindsorContainer. I will be giving an introduction to the dependency inversion principal, and then we will jump into MicroKernel and the extensions that have been built on top of MicroKernel to create WindsorContainer. My final demo will include a custom facility to extend WindsorContainer that will provide integration with the memcached distributed object caching system. I hope to see you out there!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Open Source | .NET | Software
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

IronRuby Emerges

Monday, 23 July 2007 17:57 by nickp

So John Lam annouced the alpha release of IronRuby, he mentions that they did a lot of work on string and arrays, unfortunately, with the current release .NET types aren't able to execute Ruby mixins. I was hoping to do something like the following:

require 'mscorlib' 
require 'System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'

list = System::Collections::ArrayList.new
list.Add(5)
list.Add(10)
list.Add(15)
list.extend Enumerable
list.each {|i| puts i.to_i}


The following code does execute:

require 'mscorlib'
require 'System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'
require 'System.Drawing, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
require 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'

Application = System::Windows::Forms::Application
Form = System::Windows::Forms::Form
Button = System::Windows::Forms::Button
Point = System::Drawing::Point
Size = System::Drawing::Size
MessageBox = System::Windows::Forms::MessageBox
window = Form.new window.text = 'Testing IronRuby'
window.size = Size.new(250, 200)
button = Button.new
button.text = 'Click Me'
button.location = Point.new(75, 75)
button.click {|sender, e| MessageBox.show 'I was clicked'}
window.controls.add(button)
Application.EnableVisualStyles
Application.run(window)

Of all the windowing toolkits I've seen for Ruby, the .NET Framework is the easiest to read for me, although I'm sure toolkits like Swiby will get noticed, especially due to it's DSL syntax which is the new hotness in the development world these days. Next up, extending the IronRuby Builtins.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   .NET | Open Source | Ruby | Software
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

EventWaitHandle.Set

Monday, 16 July 2007 22:18 by nickp

This blog has been pretty quiet lately, what's going on, has Nick fallen asleep? Nope, I've just been busy wrapping a few things up. Most importantly, I got married on June 2nd, and we took a few weeks off to head down to Hawaii and relax. If you've never been, my recommendation is to skip Maui and head right for Kauai.

I will be presenting at the Cedar Rapids User Group on January 7, giving my presentation on Castle's MicroKernel/Windsor Container, so if you are interesting in hearing more about the light-weight IoC container come on out. My presentation starts with an introduction to the IoC concepts and progresses through extending the container via custom facilities.

Last but not least, last year my boss Eric Jacobs got Levi Rosol and I involved in the Ankeny Summerfest cardboard boat regatta. Last year we didn't quiet make it too far past the starting line, however we took notes and gave it another attempt this past weekend. Results - Success, we made it down and back without sinking, a major step forward. Next year I plan to build a boat that will last longer than a single run, however we will do it in Eric's style by only beginning the construction two nights in advance. :-) My wife recorded the event, take a look:

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

DLR Hosting Services

Tuesday, 1 May 2007 21:31 by nickp

I was poking around within the DLR code that was release yesterday within the IronPython Alpha release and I came across the Script class which allow local hosting of a script. Given a language provider you can then execute a block of code. Internally the ScriptEnvironmentSetup loads 4 LanguageProviderSetup classes currently

  • IronPython.Hosting.PythonLanguageProvider
  • Microsoft.JScript.Compiler.Hosting.LanguageProvider
  • Microsoft.VisualBasic.Scripting.Hosting.VisualBasicLanguageProvider
  • Ruby.Hosting.RubyLanguageProvider

Unfortunately it appears they are only including the IronPython.Hosting.PythonLanguageProvider with this current release. A quick example of what you can do, the Script class is a wrapper around the ScriptDomainManager:

using System;
using Microsoft.Scripting;
namespace IronPythonScriptHost
{
class Program
{
static void Main(string[] args)
{
string code = "print \"Hello\" + Name";
Script.SetVariable("Name", "Nick");
Script.Execute("py", code);
Console.Read(); 
}
}
}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Open Source | .NET | Software | DLR
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Tailing your log file

Wednesday, 18 April 2007 20:50 by nickp

In Unix we have tail -f which will allow a user to see during real-time the values that are being committed to a log file. I tend to use log4net as my logging utility, however I can't always use a console appender to view your log in real-time. On Windows, a good replacement is called Tail for Win32 which allows you to do the same thing, and also colorize the output based on keywords. A nice little tool.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5