Productivity

LINQ: Any() vs. Count()

In most code that you find that uses lists you will find something like this: 

if(products.Count() > 0)
            {
                // Do stuff
            }

Personally, I’ve seen this literally thousands of times. While this works and gets the job done, there is one issue with this method. It enumerates the entire enumerable collection. What if you have 10,000 items in your collection? What if that collection has a bunch  of other nested LINQ queries that must be executed prior to the actual count can be evaluated?

A simpler way to identify if the sequence contains any elements is to use the .Any() method. From the .Any() MSDN article:

Determines whether a sequence contains any elements.”

Later in the article it states:

“The enumeration of source (the source enumeration) is stopped as soon as the result can be determined.”

In English .. the Any() method  stops enumerating the enumeration as soon as it finds the first element. This is the same for the overload of the function as well.

Therefore you could do this:

var products = productService().GetProducts();
            if(products.Any())
            {
                // Do Stuff
            }

… and you would get the same effect as Count() without the overhead of processing the entire enumeration.

Setting up a Default Sequence Template for the MPC1000

I make music with the MPC1000 and every time I start a new sequence I find myself naming my tracks the same, over and over and over. This takes a few minutes each time I start and is productivity play dough (it slows me down). 90% of the songs I create have the same track order and track name, simply for organization (for track mutes, tracking, etc).

Example:

Track# – Track Name

1-Hat
2-Snare1
3-Kick1
4-Kick2
5-Hat2
6-Cymbal1
7-String1
8-Shaker1
9-Empty
10-Empty
11-Empty
12-Empty
13-Empty
14-Empty
15-Sample1
16-Sample2
17-Empty
18-Empty
19-Empty
20-Loop1
21-Loop2

I wanted to set this up as a default template when I start the MP1000. Therefore I can start sampling or programming beats as soon as I turn it on. This would save me a lot of time. Here’s how to do it:

Start your MPC and name your tracks (as I have done above).

MPC1K_001

Now save this sequence to your CF card via [MODE] –> PAD3 (SAVE).

MPC1K_003

If you do not have an AUTOLOAD folder create one. Anything in the AUTOLOAD folder will be loaded when the MPC1000 starts up (if this does not happen, see the bottom of this post for how to enable the AUTOLOAD feature).

Save the sequence (in this case, Sequence01) to the AUTOLOAD directory.

MPC1K_004

Now, when your MPC1000 boots up, it will load Sequence01 as your default sequence. All of your tracks will have names and you can start programming your beats right away.

If you restart your MPC and your new sequence does not AUTOLOAD, its most likely that you do not have AUTOLOAD enabled. To enable this you must go to the load window: [MODE] –> PAD2 (LOAD) and hit F4 to enter the A.LOAD window (I’m using the JJOS1 for this, if you’re using another OS, it could be different for you).

MPC1K_005

Once in this window select “MEMORY CARD AUTOLOAD” as shown below. This will enable the AUTOLOAD feature to load from the memory cards AUTOLOAD directory. (You can also define your own folder if you want to).

MPC1K_006

That’s it, you should have your track names loading upon start of of the MPC, as shown below. :)

MPC1K_001

Enjoy

Productivity Boost: The SVN Switch Command

If you’re working in a shop that uses SubVersion and also utilizes any form of branching you will probably run into a point in time where you have 10 different copies of your source tree on your disk. Usually you will have one copy per branch. If your project is small this usually isn’t a problem, but if your project is large it is a royal pain. At my current gig our project contains well over 35K files. That’s not lines of code, that’s actual number of files. It’s _huge_.

Solution: Use the svn switch command.

The svn switch command does the following:

This subcommand updates your working copy to mirror a new URL—usually a URL which shares a common ancestor with your working copy, although not necessarily. This is the Subversion way to move a working copy to a new branch. [source]

In english: If you branch from the same location each time you can switch between where your local copy points. At this point your local copy is acting as a local pointer to a particular location in source control. Maybe today you’re working on the trunk, then maybe tomorrow you’re working on a few bugs for the version 2 branch, etc. You can easily switch between them using this command.

Switching with Tortoise SVN

This is super easy.

Right click the source of where you would like to branch.

image

 

Select the Url (click the ellipses)

image

Select your location of your branch (click to enlarge):

image

Then click ok on the “Switch To Branch/Tag” window.

The switch dialog will appear informing you what files it has downloaded/updated/deleted to get you to the current state of that branch (click to enlarge):

image

That’s it! Now you’re connected to your branch!

 

Benefit

The benefit here is simple: Productivity. If you have a very large tree (as I noted above) you can run into instances where downloading the entire tree can take 5-10 minutes. If you’re doing a lot of branch switching this can be a major time drain. Switching nearly eliminates this slow down from 5-10minutes to 10-15 seconds. Plus, you only have _one_ copy of the tree on your machine at any time. That’s also very nice as otherwise you could have a major file party happening on C:\.   :)

Enjoy

Dual Monitor Support for Windows 7 RC Dell D630

I installed Windows 7 RC last night and my dual monitor support was not working. I queried a few people at my employer and Anthony Handley pointed me in the right direction.

If you’re using a Dell D630 laptop and you’re running Windows 7 RC and need a video driver to support dual monitors, we’ve found this one to work out quite well:

Download the driver on Dell.com

Notes: The install requires a reboot, but afterwards the dual monitor support works without an issue.

A Very Cool WCF Tool: WCFTestClient.exe

This an oldie, but a goodie. Not many people use this tool, much less know about it or where it exists.

By default when you install VS2008 (I’m not sure if its part of 2005 or not) you have a tool at your disposal in the Visual Studio install path:

My Path: c:\Program Files\Microsoft Visual Studio 9.0\Common7\ide\

In this path, you’ll find a tool called “WcfTestClient.exe”

It is located here: c:\Program Files\Microsoft Visual Studio 9.0\Common7\ide\WcfTestClient.exe

Fire this bad boy up and here’s the screen you get:

image

You can add a service endpoint by right clicking on “My Service Projects” and clicking Add Service

image 

Then paste in your service location (I’m using an open one I found on xmethods.net that generates prime numbers):

image

Click Ok, and the service contract, config, etc will be generated for you and you’ll have something that looks like this:

image

Double click on “GetPrimeNumbers” and you’ll see the following:

image

Open the body of the request (as it looks like this service uses message contracts) and where it says “(null)” select “GetPrimeNumbersRequestBody”

image

Then expand the body and the request what is the highest number the service should search for prime numbers (in english – give me all the prime numbers up to 50):

image

Click “Invoke”, wait a few seconds and your response will come back.

image

 

All Done!

 

You have now tested a WCF Service without creating an application, generating a proxy, running the app, etc. Super easy!

 

Other Uses

You could use this to test your own in house services or even to debug a service running on your machine during development (if you wanted to test full end to end). Simply paste in the address of your local service (http://localhost:someport/myservice.svc) and then start testing. This is a HUGE time saver to see if your service works or not. Otherwise you’d have to generate a client, perform a service reference or generate a service proxy, etc.