All your Base62 are belong to us

I am currently working on my own url shortener: konv.es.  In order to create the shortest possible character hash of the url, I use the GetHashCode() method of the string, then convert the resulting number to base 62 ([0-9a-zA-Z]).  The most elegant solution that I have found thus far to make the convertion (which is also a handy-dandy example of a yield return) is:

private static IEnumerable<char> ToBase62(int number)
  {
    do
    {
      yield return "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[number % 62];
      number /= 62;

    } while (number > 0);
  }

Extra credit: re-factor as an extension method

Posted on November 22, 2011 at 8:59 pm by Steve Konves · Permalink · 2 Comments
In: C#, konv.es

Custom Configuration Sections

They are the wave of the future, the next big thing, this Christmas’s useless fad item! Or whatever.  I don’t have time to type about them now, but here’s the link to someone who did:

http://devlicio.us/blogs/derik_whittaker/archive/2006/11/13/app-config-and-custom-configuration-sections.aspx

Posted on November 16, 2011 at 2:01 pm by Steve Konves · Permalink · Leave a comment
In: C#

It’s All About Productivity

Here is a list of tools that I use.  Some are Visual Studio plugins, some are external stand alone tools, but all of them make life of a developer just a little better.  All of them have a very functional free version which is a huge win.  (Note: you will not find resharper in my list.  You have to pay for it and I personally don’t care for it.  So there.)

Ghost Doc

http://submain.com/products/ghostdoc.aspx

VS plugin – This tool automates the process of generating method-level, xml documentation in code.  It does an excellent job of automagically guessing what each method, property, etc does and automatically populates all common elements such as method properties and return values.  It also goes as far as creating MSDN style verbiage for events and override properties and methods.  It’s a huge time saver and encourages the best-practice of creating in-code documentation. Also, see sandcastle below.

VSCommands

http://vscommands.squaredinfinity.com/features

VS plugin – This tool adds a bunch of new functionality to Visual Studio.  (IMO, Microsoft needs to buy them and rool the tool into the next version of VS. Whatever.)  There are too many features to fully cover here, so check out their site (above).  My personal favorites are the ability to group project files, and the confirmation to move files within the solution.

WoVS Quick Add Reference

http://visualstudiogallery.msdn.microsoft.com/dc06b54c-b6c4-4cf5-8203-a09c6979e881

VS Plugin – Bad name, good extension.  This plugin lets you automatically add a reference library AND the using statement.  This is probably the number one missing feature in Visual Studio

Sandcastle Help File Builder

http://shfb.codeplex.com/

If you have ghost doc (or are stupid and manually type out your xml documentation) this is an amazing tool to publish in-code documentation to help files or MSDN style websites.  I have never used N-Doc, but I hear it’s similar.

Slow Cheetah

http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5

VS Plugin – Do less with more! (Less effort with more projects … ok, lame.) This plugin supports config file transforms for all project types, not just web applications. Want to change configurations for dev, test, and production. It does that! Want to preview the transform before deploying. Yup it does that too. Want to instantly write all of your code based on the config file. Well, maybe you can talk them into adding that in a future release.

Posted on November 15, 2011 at 8:07 am by Steve Konves · Permalink · Leave a comment
In: Development, Visual Studio

Linq Group by multiple columns + Aggregate Function

Because I refer to it so often …

http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/54f6ac70-e74c-4d9d-a9ee-6373714c0755/

Posted on November 14, 2011 at 10:21 pm by Steve Konves · Permalink · Leave a comment
In: C#

Windows 7 window modes

Problem:

Can’t pin application windows well in multiple monitor situations:

Windows 7 introduced the ability to “pin” application windows to the sides of the screen.  If you drag a window to the side of the screen, the application is automatically re-sized to fill half.  Every time I use that feature, my life gets just a little better.  Thank you Microsoft.

However, with multiple monitors, the mouse does not pick up the transition between monitors as an edge, so you are left with only the very outer edges of the screens to pin application windows.  This is the appropriate time to flaunt my 3 monitor array at the office:

Me looking at three monitors

 

(Actually, now I have 4. There are two landscape screens on the left side.)

Solution:

Windows/arrow keys

The solution, which I have spent far to much typing to lead up to, is to use the Windows and arrow keys to move the windows.  Mess with them yourself to find out exactly how it works.

Nerd Cred:

3pts

(Bonus points: Open several windows, then grab a window title bar with the mouse cursor and jiggle is back and forth. Neat.)

Posted on November 14, 2011 at 9:24 pm by Steve Konves · Permalink · Leave a comment
In: 1337 h4x

Control Alt Delete for Remote Desktop

Problem:

Ctrl+alt+del does not work in Remote Desktop

Using Ctrl+alt+del in remote desktop is always handled by the local machine.  As a side note, ctrl+shift+esc will open the remote task manager.

Solution:

Use ctrl+alt+end

Nerd cred: 5pts

Posted on November 14, 2011 at 9:08 pm by Steve Konves · Permalink · Leave a comment
In: 1337 h4x

What’s in YOUR snippet picker?

I have recently been adding new, custom snippets to quickly stub out stuff when developing in the MVVM pattern.  Pattern programming is a great idea, but spending hours hand-typing ICommand implementations or notification properties can make you want to disavow patterns entirely and just shove it all in the code-behind. (For those of you who aren’t super familiar with MVVM, that was a joke; it’s a bad idea).

Because I am not just a soulless code monkey (and because I’m selfish and want to be able to find my snippets later if my office burns down), I have provided some of my favorite ones here.  They are provided under the GSD licence (get stuff done) so feel free to use them yourself as long as doing so will help you feign some sort of productivity.

Here be snippets:

ICommand: cmd

<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>cmd</Title>
    <Author>Steve Konves</Author>
	<Shortcut>cmd</Shortcut>
    <Description>Creates a bindable ICommand</Description>
    <SnippetTypes>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Declarations>
      <Literal>
        <ID>name</ID>
        <Default>DoWork</Default>
      </Literal>
    </Declarations>
    <Code Language="CSharp">
      <![CDATA[#region $name$
        /// <summary>
        /// Executes the $name$ command.  Supports command binding.
        /// </summary>
        public void $name$()
        {
            if (Can$name$)
            {
                // TODO: Add functionality here.
            }
        }

        #region (Can$name$)

        /// <summary>
        /// Gets or sets a value indicating whether the $name$ command can be called.
        /// Also determines whether a button bound to this command is enabled.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if the $name$ command can be called; otherwise, <c>false</c>.
        /// </value>
        public bool Can$name$
        {
            get
            {
                // Note: Consider adding additional logic here.
                return _Can$name$;
            }
            set
            {
                if (_Can$name$ != value)
                {
                    _Can$name$ = value;
                    RaisePropertyChanged("Can$name$");
                }
            }
        }
        private bool _Can$name$;
        #endregion

        #region ($name$Command)
        /// <summary>
        /// Gets or sets the $name$ command.  Supports binding.
        /// </summary>
        public ICommand $name$Command
        {
            get
            {
                return _$name$Command;
            }
            set
            {
                if (_$name$Command != value)
                {
                    _$name$Command = value;
                    RaisePropertyChanged("$name$Command");
                }
            }
        }
        private ICommand _$name$Command = new Helpers.Command { Method = "$name$" };
        #endregion

        #endregion]]>
    </Code>
  </Snippet>
</CodeSnippet>

Notification Property: propn

<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>Notification Property</Title>
    <Author>Steve Konves</Author>
    <Shortcut>propn</Shortcut>
    <Description>Creates a property which implements a backing field a property change notification</Description>
    <SnippetTypes>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Declarations>
      <Literal>
        <ID>name</ID>
        <Default>MyProperty</Default>
      </Literal>
      <Literal>
        <ID>type</ID>
        <Default>int</Default>
      </Literal>
    </Declarations>
    <Code Language="CSharp">
      <![CDATA[#region $name$

        public $type$ $name$
        {
            get { return _$name$; }
            set
            {
                if (_$name$ != value)
                {
                    _$name$ = value;
                    OnPropertyChanged("$name$");$end$
                }
            }
        }
        private $type$ _$name$;

        #endregion]]>
    </Code>
  </Snippet>
</CodeSnippet>
Posted on November 9, 2011 at 7:40 am by Steve Konves · Permalink · One Comment
In: C#, Development, Silverlight, Visual Studio

GSD License*

PREAMBLE

The GSD (Get Stuff Done) License is a free, open source, copyright free license for software and other kinds of works.

This license exists to promote productivity.  Some licenses try to provide rights, but deny you the right of removing all rights to whatever from whatever, or whatever.  They can be very confusing.

This license is not about rights, but about productivity so that you can get stuff done.  If reading the rest of this license does not make you more productive, please consider using another license.

TERMS AND CONDITIONS

0. Definitions

“This License” refers to the document You are currently reading.

“You/Your” refers to the human being reading This License.

“Productivity” refers to a measure of the efficiency of production. Productivity is a ratio of what is produced to what is required to produce it. (plagiarized from Wikipedia)

“Licensed Work” refers to whatever you slap this license on in order to invite others to use it to do more work with less effort.

1. Basic Permissions

This License explicitly affirms Your unlimited permission to use the unmodified Licensed Work in any way deemed fit by You, except when explicitly forbidden by law.

2. Modification and Plagiarism

The Licensed Work may be modified or plagiarized by You or another party at any time as long as either A) the modified or unmodified Licensed Work is used in a way to increase the productivity of the You or the other party or B) the You or the other party forfeit all rights to Your/their respective souls to the original author(s) of the original Licensed Work.

This License becomes void upon modification of the Licensed Work or the blatant plagiarism of the Licensed Work by other party.  At any time, the License can be reinstated at Your discretion or at the discretion of the plagiarizing party.

3. Monitary Gain

You may use the License Work to make money unless explicitly prohibited by law.  This License does not grant you the right to unlawfully take the money that other parties made by using the Licensed Work.

4. Disclaimer of Warranty

THERE IS NO WARRANTY FOR THE LICENSED WORK, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LICENSED WORK “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LICENSED WORK IS WITH YOU. SHOULD THE LICENSED WORK PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

5. Limitation of Liability

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE LICENSED WORK AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LICENSED WORK (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LICENSED WORK TO OPERATE WITH ANY OTHER WORKS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS

*This license is provided under the GSD License

Posted on November 8, 2011 at 1:37 pm by Steve Konves · Permalink · Comments Closed
In: Development

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

Posted on November 5, 2011 at 3:57 am by Steve Konves · Permalink · One Comment
In: Silverlight