Monday, April 4, 2011

Zune - No installation Media

This fix worked for me

http://support.microsoft.com/kb/910336

Tuesday, March 29, 2011

find Missing int - amazon question

static private void findMissing(int[] intArray, int n)
{
bool[] bitArray = new bool[n];

if (intArray == null)
throw new Exception("findMissing - intArray is null");

for (int i = 0; i < n; i++)
bitArray[i] = false;

foreach (int x in intArray)
{
if (x < 0 || x >= n)
throw new Exception("findMissing - x is out of range - x=" + x);
bitArray[x] = true;
}
for (int i = 0; i < n; i++)
{
//Console.WriteLine("i=" + i + " bit=" + bitArray[i].ToString());
if (!bitArray[i])
Console.WriteLine("Missing element at i=" + i);
}
}

static private void testFindMissing()
{
int[] intArray = new int[]{ 1, 2, 4, 7, 3, 5, 6, 0, 9, 10 };
findMissing(intArray, 11);
Console.ReadLine();
}

amazon question find min diff in a list of int

static private void minDiff(int[] intArray)
{
if (intArray == null)
throw new Exception("minDiff - intArray is null");

var query = intArray.OrderBy(x1 => x1);
List intList = query.ToList();
if (intList.Count <= 1)
throw new Exception("minDiff - must have at least 2 elements in list");

int minDiff = int.MaxValue;
int x = -1;
int y = -1;
for (int i = 1; i < intList.Count - 1; i++)
{
if (intList[i] - intList[i - 1] < minDiff)
{
x = intList[i];
y = intList[i - 1];
minDiff = x - y;
}
}
Console.WriteLine("x=" + x + " y=" + y + " minDiff=" + minDiff);
Console.ReadLine();
}

static private void testMinDiff()
{
int[] intArray = new int[] { 3, 9, 6, 17, 33, 1, 16 };
minDiff(intArray);
}

Wednesday, March 23, 2011

Nesting Functions vs Intermediate Variables

Unless you really love looking at the call stack, create intermediate variables and un-nest your function. The compiler will compile away these variables anyways, so no loss in efficiency. They will be handy for debugging and make the code clearer.

Tuesday, March 22, 2011

Delete a Project from Team Foundation Server

Answer: go to the Visual Studio 2010 command prompt and use “TfsDeleteProject.exe“.

Example:


TfsDeleteProject /collection:http://larry-pc:8080/tfs “Fret Project“

You can get the url, if you've forgotten it, by going to
Team -> Connect to Team Foundation Servers -> Servers ..

Forcing DataGridView to Refresh when changed

This works - save DataSource, save scroll position, restore datasource, restore scroll position, e.g.

private void forceRefresh()
{
int x = dgvMusicalScaleList.FirstDisplayedScrollingRowIndex;
dgvMusicalScaleList.DataSource = null;
dgvMusicalScaleList.DataSource = musicalScaleList;
dgvMusicalScaleList.FirstDisplayedScrollingRowIndex = x;
}

Monday, March 21, 2011

You forgot to make it public, dummy!

Microsoft has a convoluted way of saying this;

Error 1 Inconsistent accessibility: property type 'System.Collections.Generic.List' is less accessible than property 'Frets.MusicalScale.notes' J:\Users\Larry\Documents\Visual Studio 2008\Projects\Frets\Frets\Classes\MusicalScale.cs 44 41 Frets