Nick Parker http://developernotes.com/Default.aspx My Ramblings on Software Development... en-US Nick Parker Subtext Version 2.1.0.5 Nick Parker http://developernotes.com/images/RSS2Image.gif http://developernotes.com/Default.aspx 77 60 Launch shell script silently at login Open Source OSX Emacs http://developernotes.com/archive/2011/04/06/169.aspx In OSX I needed a shell script to execute at login. There are a few different ways to perform this so I thought it might be helpful to document what your options are. I've switched over to Emacs which typically has a longer startup time than editors such as Vim. This is the shell script we will execute: <pre> #!/bin/zsh emacs --daemon </pre> Oftentimes Emacs will stay open during an entire user session of the OS, so the sooner I can launch it the better. OSX offers a few different startup options for us. First, we have Login Items available within Account Settings of the System Preference pane. We need to rename the shell script above to end in a .command file extension to allow the Login Items to execute it. This will run at login, however we will be left with a Terminal prompt visible when the script has completed. Preferably we would execute this in the background at user login. OSX manages system and user daemons via a tool called launchd. The interface to launchd is a tool called launchctl which allows for loading and unloading daemons into launchd. XML formatted plist files are used to describe operations loaded into launchctl. <pre> &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;Label&lt;/key&gt; &lt;string&gt;emacs-daemon&lt;/string&gt; &lt;key&gt;RunAtLoad&lt;/key&gt; &lt;true /&gt; &lt;key&gt;Program&lt;/key&gt; &lt;string&gt;/Users/nickp/bin/scripts/launch-emacs-daemon.sh&lt;/string&gt; &lt;/dict&gt; &lt;/plist&gt; </pre> The above file, emacs-daemon.plist needs to be saved in the ~/Library/LaunchAgents directory. As you can see the xml dictates that the launch-emacs-daemon.sh file should be executed at load, note we no longer need a .command file extension. We will now use launchctl to load our plist file. <pre> launchctl load ~/Library/LaunchAgents/emacs-daemon.plist </pre> To verify that your script executed correctly lets ask launchctl to show us what is running. <pre> launchctl list | grep emacs </pre> You will likely see two entries, each with three columns. Mine looks like this: <pre> 148 - 0x100100e80.anonymous.emacs - 0 emacs-daemon </pre> The first column is the process id, the first row shows the PID of the emacs daemon our shell script spawned. The second line is the emacs-daemon.plist job entry that executed, returning a status code of zero in the second column - success! With this setup, I can launch the emacsclient process which will attach to the daemon server and launch instantly. <img src="http://developernotes.com/aggbug/169.aspx" width="1" height="1" /> Nick Parker http://developernotes.com/archive/2011/04/06/169.aspx Thu, 07 Apr 2011 01:34:36 GMT http://developernotes.com/archive/2011/04/06/169.aspx#feedback http://developernotes.com/comments/commentRss/169.aspx Generic Factory over Object Initializers .NET Design Patterns http://developernotes.com/archive/2008/10/02/generic-factory-over-object-initializers.aspx Consider the following generic factory method: <pre>    public class Builder<br />     {<br />         public static TType Create&lt;TType&gt;(Action&lt;TType&gt; actionOnTType) where TType : new()<br />         {<br />             var item = new TType();<br />             actionOnTType(item);<br />             return item;<br />         }<br />     }</pre> Which allows us to do something like this: <p> </p> <pre>            var aRunningCar = Builder.Create&lt;Car&gt;(car =&gt; <br />             {<br />                 car.Engine = new Engine("v8"); <br />                 car.Start();<br />             });</pre> What are your thoughts on the above over the standard object initializers found in C# 3.0?  Initially the difference is that this allows us to invoke methods on the instance as the instance is passed into our lambda expression whereas object initializers only allow us to set property values to be assigned to the instance.  It's a subtle difference but something I think could be helpful.  Just a random thought that passed through my head after I finished watching the debate tonight.<img src="http://developernotes.com/aggbug/1.aspx" width="1" height="1" /> Nick Parker http://developernotes.com/archive/2008/10/02/generic-factory-over-object-initializers.aspx Fri, 03 Oct 2008 04:43:00 GMT http://developernotes.com/archive/2008/10/02/generic-factory-over-object-initializers.aspx#feedback 6 http://developernotes.com/comments/commentRss/1.aspx Vimperator Tip - awesome bar Productivity Vim http://developernotes.com/archive/2008/09/22/vimperator-tip-awesome-bar.aspx I just wanted to share a quick vimperator tip. You can get the <a href="http://blog.mozilla.com/blog/2008/04/21/a-little-something-awesome-about-firefox-3/">awesome bar</a> style hints by adding the following two commands to your _vimperatorrc file: <pre> :set wildoptions=auto :set cpt=l </pre> <img src="http://developernotes.com/aggbug/2.aspx" width="1" height="1" /> Nick Parker http://developernotes.com/archive/2008/09/22/vimperator-tip-awesome-bar.aspx Tue, 23 Sep 2008 01:17:00 GMT http://developernotes.com/archive/2008/09/22/vimperator-tip-awesome-bar.aspx#feedback http://developernotes.com/comments/commentRss/2.aspx Vim + Firefox = Vimperator Vim http://developernotes.com/archive/2008/06/30/vim-firefox-vimperator.aspx Okay, so I've lamented about how I enjoy using Vim/gVim several times now. If you are still using notepad.exe as your text editor I strongly advise you to check out some of the other editors out on the market. Vim and Emacs tend to be near the top of the list, are full of features and are both extensible. The bottom line is that you need to find an editor, learn it and use it - it's that simple. In fact Dave Thomas and Andy Hunt discuss this in <a href="http://www.pragprog.com/the-pragmatic-programmer">The Pragmatic Programmer</a>. So, while I enjoy using the keystrokes within Vim to navigate text, what about web browsing - we all do that quite a bit these days? The mouse is the obvious choice, however it is not my only option. Enter <a href="http://vimperator.mozdev.org/">Vimperator</a>, suggested by <a href="http://www.zedshaw.com/blog/2008-03-02.html" title="Zed">Zed</a>, a Firefox addin that allow your browser to act like Vim. <br /> A quick introduction, once you have it installed I like to turn a few things back on so that it still feels like a normal web browser for the times when I actually do want to use my mouse. Like Vim, Vimperator is configurable through a file you can create titled "_vimperatorrc" which needs to be stored within your %userprofile% directory. This file allows you to customize the way Vimperator integrates with Firefox, etc. Below I have included the contents of my _vimperatorrc file to get you started. <pre> "Turn the menu and toolbar on.<br /> :set guioptions+=mT<br /> <br /> "Turn off the show tabs by default.<br /> :set showtabline=1<br /> <br /> "Turn session tracking off.<br /> :set! browser.startup.page=1<br /> <br /> "Allow user to click in address bar.<br /> :set! browser.urlbar.clickSelectsAll=true<br /> :set! browser.urlbar.doubleClickSelectsAll=true<br /> <br /> "Map Ctrl + n for new windows<br /> :map &lt;C-n&gt; &lt;C-v&gt;&lt;C-n&gt;<br /> <br /> "Map Ctrl + t for new tabs<br /> :map &lt;C-t&gt; :tabopen&lt;Enter&gt;<br /> <br /> "Map paste operation normally.<br /> :imap &lt;C-v&gt; &lt;C-v&gt; </pre> <p> <font color="#000000"><font color="#000000"><br /> <font size="2" face="verdana,geneva">After you create this file you will need to restart Firefox and then the settings with be loaded. Standard navigation include: </font> </font></font></p> <ul> <li>j - down one line.</li> <li>k - up one line.</li> <li>o - open URL.</li> <li>shift + l - navigate forward 1 step in browser history.</li> <li>f [number] - opens a link based on the number displayed on screen.</li> <li>shift + f [number] - opens a link based on the number displayed on the screen (new tab).</li> <li>gg - go to top of page.</li> <li>shift + g - go to bottom of page.</li> <li>ctrl + f - navigate down one screen length.</li> <li>ctrl + b - navigate up one screen length.</li> <li>b [number] - switches to the buffer (tab) based on the number supplied.</li> <li>/[word] - search for [word], n goes to the next occurance, shift + n to the previous occurance.</li> </ul> If you want to read about the other options you can hit F1 or type :help.  You can grab a nightly build <a href="http://vimperator.driftaway.org/" title="here">here</a>.  One thing I didn't like about the default configuration within Vimperator was that it would track your session, so when you would close your browser, the next time you open Firefox, the site you were on was reloaded.  There are keyboard commands that will not save your session (i.e., ZQ), however there are many times I will simply close the Firefox window by mouse (old habits die hard).  Above in my configuration file I have turned off the session tracking.  I have found my web navigation experience has increased dramatically with this, and my reliance on the mouse continues to decrease.  Let me know if you decide to give it a try, it will definitely be worth your time.<img src="http://developernotes.com/aggbug/3.aspx" width="1" height="1" /> Nick Parker http://developernotes.com/archive/2008/06/30/vim-firefox-vimperator.aspx Tue, 01 Jul 2008 01:39:00 GMT http://developernotes.com/archive/2008/06/30/vim-firefox-vimperator.aspx#feedback 6 http://developernotes.com/comments/commentRss/3.aspx Vim Tip of the Day - File Explorer Navigation General Open Source Vim http://developernotes.com/archive/2008/05/05/vim-tip-of-the-day-file-explorer-navigation.aspx 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"). <pre> autocmd BufEnter * lcd %:p:h </pre> <img src="http://developernotes.com/aggbug/4.aspx" width="1" height="1" /> Nick Parker http://developernotes.com/archive/2008/05/05/vim-tip-of-the-day-file-explorer-navigation.aspx Tue, 06 May 2008 02:17:00 GMT http://developernotes.com/archive/2008/05/05/vim-tip-of-the-day-file-explorer-navigation.aspx#feedback 2 http://developernotes.com/comments/commentRss/4.aspx Microsoft Mocking Framework and TypeMock .NET Software Visual Studio http://developernotes.com/archive/2008/04/01/microsoft-mocking-framework-and-typemock.aspx While everyone has been wondering over the past couple years when Microsoft would ship its own version of a mocking framework, as of yesterday <a href="http://www.typemock.com/index.html" title="TypeMock">TypeMock</a> <a href="http://blog.typemock.com/2008/03/typemock-acquired-by-microsoft.html" title="annouced">announced</a> it has been acquired by Microsoft and the product will be included in future versions of Visual Studio.  At least they didn't follow their previous pattern and create a less powerful clone of other products already on the market.  Hmm, interesting this should be me thinks.  Next to follow, possibly a DynamicProxy2 clone from Microsoft?  What day is today again? <img src="http://developernotes.com/aggbug/5.aspx" width="1" height="1" /> Nick Parker http://developernotes.com/archive/2008/04/01/microsoft-mocking-framework-and-typemock.aspx Tue, 01 Apr 2008 09:11:00 GMT http://developernotes.com/archive/2008/04/01/microsoft-mocking-framework-and-typemock.aspx#feedback 5 http://developernotes.com/comments/commentRss/5.aspx Creating Objects - Round 3 .NET DLR Open Source Ruby Software http://developernotes.com/archive/2008/03/05/creating-objects-round-3.aspx <a href="http://ayende.com/Blog/Default.aspx">Ayende</a> has <a href="http://ayende.com/Blog/archive/2008/02/27/Creating-objects--Perf-implications.aspx">been</a> <a href="http://ayende.com/Blog/archive/2008/02/28/Creating-objects--round-2.aspx">discussing</a> 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.<br /> The delegate: <pre>delegate Created CreateInstance(int num, string name);</pre> The structure: <pre> public class Created { public int Num; public string Name; public Created(int num, string name) { Num = num; Name = name; } } </pre> Grab the constructor: <pre> ConstructorInfo ci = typeof (Created).GetConstructors()[0];</pre> Define the parameters to be passed to the constructor (relative to the code block we are about to define): <pre> Variable num = Variable.Parameter(SymbolTable.StringToId("num"), typeof (int)); Variable name = Variable.Parameter(SymbolTable.StringToId("name"), typeof (string)); </pre> Build a code block with the Ast factories for building expressions (this builds our function for creating new Created instances with our parameters): <pre> 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]); </pre> Compile our block: <pre> CreateInstance create_instance = TreeCompiler.CompileBlock&lt;CreateInstance&gt;(block); </pre> Invoke the compiled instance: <pre> int iterations = 1000000; Stopwatch watch = Stopwatch.StartNew(); for (int i = 0; i &lt; iterations; i++) { create_instance(i, i.ToString()); } </pre> 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 <a href="http://developernotes.com/files/Builder.zip">here</a> 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?<img src="http://developernotes.com/aggbug/6.aspx" width="1" height="1" /> Nick Parker http://developernotes.com/archive/2008/03/05/creating-objects-round-3.aspx Thu, 06 Mar 2008 00:08:00 GMT http://developernotes.com/archive/2008/03/05/creating-objects-round-3.aspx#feedback 1 http://developernotes.com/comments/commentRss/6.aspx Vibrant Ink for Visual Studio 2008 .NET Software Visual Studio http://developernotes.com/archive/2008/02/10/vibrant-ink-for-visual-studio-2008.aspx For those of you that enjoy the <a href="http://alternateidea.com/blog/articles/2006/01/03/textmate-vibrant-ink-theme-and-prototype-bundle" title="Textmate Vibrant Ink theme">Vibrant Ink theme</a> that was originally produced for Textmate, John Lam <a href="http://www.iunknown.com/2007/06/vibrant_ink_vis.html" title="Vibrant Ink for Vim and Visual Studio 2005">converted it</a> to work under both Vim and Visual Studio 2005 a while back.  I've enjoyed that for both editors, however with Visual Studio 2008 out, we need to update.  I've updated the settings file to now work with Visual Studio 2008.  Feel free to download it <a href="http://developernotes.com/files/VibrantInk-VS2008.zip" title="VibrantInk-VS2008.vssettings">here</a>. <img src="http://developernotes.com/files/VibrantInk.png" alt="" /> <img src="http://developernotes.com/aggbug/7.aspx" width="1" height="1" /> Nick Parker http://developernotes.com/archive/2008/02/10/vibrant-ink-for-visual-studio-2008.aspx Sun, 10 Feb 2008 16:35:00 GMT http://developernotes.com/archive/2008/02/10/vibrant-ink-for-visual-studio-2008.aspx#feedback 1 http://developernotes.com/comments/commentRss/7.aspx Code to Live Video from Tulsa TechFest .NET Open Source Software http://developernotes.com/archive/2008/02/05/code-to-live-video-from-tulsa-techfest.aspx <a href="http://codebetter.com/blogs/jeffrey.palermo/default.aspx" title="Jeffrey Palermo">Jeffrey Palermo</a> and I sat down with <a href="http://blogs.msdn.com/chkoenig/" title="Chris Koenig">Chris Koenig</a> while at <a href="http://www.tulsatechfest.com/" title="Tulsa TechFest">Tulsa TechFest</a> back in October to chat about the new ASP.NET MVC stack.  <a href="http://www.joshholmes.com/" title="Josh Holmes">Josh Holmes</a> just published an extract of our conversation out on Channel 9 <a href="http://channel9.msdn.com/ShowPost.aspx?PostID=375432" title="Watch the video here">here</a>.  This was recorded back in October, right after the ASP.NET MVC stack was first made public by Scott Guthrie down at the <a href="http://altdotnet.org/" title="ALT.NET">ALT.NET</a> 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 <a href="/admin/Pages/Direct video link" title="http://channel9.msdn.com/Screencasts/375432_20080119JeffAndNickOnMVCFramework.wmv">here</a>.  Have you played with the new MVC stack yet, if so what do you think? <img src="http://developernotes.com/aggbug/8.aspx" width="1" height="1" /> Nick Parker http://developernotes.com/archive/2008/02/05/code-to-live-video-from-tulsa-techfest.aspx Wed, 06 Feb 2008 02:09:00 GMT http://developernotes.com/archive/2008/02/05/code-to-live-video-from-tulsa-techfest.aspx#feedback 1 http://developernotes.com/comments/commentRss/8.aspx Happy New Year General http://developernotes.com/archive/2008/01/01/happy-new-year.aspx Happy New Year everyone! I've been having some issues with my server recently, so if this post makes it out there all the better. I just received notification from Microsoft this morning that I have received my MVP award for 2008. I look forward to seeing everyone up in Seattle this coming April. I am planning on blogging more this year. We have been absurdly busy at work, but there are a lot of little nuggets I am looking forward to sharing. Until next time... <img src="http://developernotes.com/aggbug/9.aspx" width="1" height="1" /> Nick Parker http://developernotes.com/archive/2008/01/01/happy-new-year.aspx Wed, 02 Jan 2008 03:21:00 GMT http://developernotes.com/archive/2008/01/01/happy-new-year.aspx#feedback 2 http://developernotes.com/comments/commentRss/9.aspx