Monday, September 28, 2015

TestClass could not be found -- or -- cannot find Microsoft.VisualStudio.TestTools.UnitTesting

Severity Code Description Project File Line
Error CS0246 The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?)

And other errors having to do with not being able to find things in the Microsoft.VisualStudio.TestTools.UnitTesting namespace.

This started happening to me after I upgraded from VS2013 to VS2015 Community.

To troubleshoot, I created a new unit test project to see what reference that would have. It has a reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll, which is located here:

1. Remove the current reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
2. Add reference to <driveletter>:\VisualStudioCommunity\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

Sunday, September 27, 2015

Maintaining syntax coloring when pasting code on blogger

What code looks like when it doesn't maintain syntax coloring on blogger:
    private static void removeChildrenOfEmptyParents() {
        for (String parent : reverseIndex.keySet()) {
            if (map.containsKey((parent))) {
                for (String child : reverseIndex.get(parent)) {

When it looks like with syntax coloring:
private static void removeChildrenOfEmptyParents() { for (String parent : reverseIndex.keySet()) { if (map.containsKey((parent))) { for (String child : reverseIndex.get(parent)) { map.remove(child); } } } }

1. Get Notepad++ (NPP):
2. Paste code into NPP, or open the source file
3. Set the appropriate language in the Language menu
4. Plugins > NppExport > Export to HTML
5. Open the HTML file in a browser
6. Copy and paste into blogger


IronPython: creating a GUI in Visual Studio

#Here's how you create a window with IronPython in Visual Studio

import sys import clr clr.AddReference("System.Drawing") clr.AddReference("System.Windows.Forms") from System.Drawing import Point from System.Windows.Forms import Application, Button, Form, Label, TextBox class MacsTest(Form): def __init__(self): self.Text = "GUI Tutorial" self.Height, self.Width = 250, 250 self.label = Label(); self.label.Text = "Hello"; self.label.Location = Point(50, 50) self.label.AutoSize = True self.textbox = TextBox() self.textbox.Width,self.textbox.Height = 100, 50; self.textbox.Location = Point(100, 50) self.textbox.KeyUp += self.handleKeyPress self.lblCharCounts = Label(); self.lblCharCounts.Text = "No chars"; self.lblCharCounts.Location = Point(50, 100) self.lblCharCounts.AutoSize = True self.Controls.Add(self.label) self.Controls.Add(self.textbox) self.Controls.Add(self.lblCharCounts) def handleKeyPress(self, sender, args): self.lblCharCounts.Text = "{0} chars".format(len(self.textbox.Text)) Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) form = MacsTest() Application.Run(form)


Python: string formatting

input = raw_input("What's the word? ") length = len(input); #named arguments print "{input} has {length} chars".format(input=input, length=length) #positions print "{0} has {1} chars".format(input, length) #using function pointer output = "{0} has {1} chars".format print output(input, length)

Find all empty folders

I was cleaning up my computer and kept running into empty directories. So I created this small Java utility to find empty folders that I could delete.

package findemptyfolders; import*; import java.util.*; /** * Starting from a top folder, walks through all subdirectories and * outputs a list of directories are that are empty all the way down. * @author Mac */ public class FindEmptyFolders { static HashMap<String, String> map = new HashMap<String, String>(); static HashMap<String, LinkedList<String>> reverseIndex = new HashMap<String, LinkedList<String>>(); /** * @param args the command line arguments */ public static void main(String[] args) { File file = new File("D:/Temp"); walkDir(file); removeChildrenOfEmptyParents(); printResults(); } private static void removeChildrenOfEmptyParents() { for (String parent : reverseIndex.keySet()) { if (map.containsKey((parent))) { for (String child : reverseIndex.get(parent)) { map.remove(child); } } } } private static void printResults() { System.out.println(""); for (Map.Entry<String, String> kvp : map.entrySet()) { System.out.printf("Empty all the way down: Child:%s Parent:%s\r\n", kvp.getKey(), kvp.getValue()); } } public static boolean walkDir(File dir) { boolean hasFiles = false; try { for (File f : dir.listFiles()) { if (f.isFile()) { hasFiles = true; continue; } if (walkDir(f)) hasFiles = true; } if (!hasFiles) { //If you want to programmatically delete the empty folder do that right here updateMap(dir.getAbsolutePath(), dir.getParentFile().getAbsolutePath()); } } catch (Exception ex) { System.out.println("Error happened for " + dir.getName()); System.out.println(ex); } return hasFiles; } private static void updateMap(String dirPath, String dirParentPath) { if (reverseIndex.containsKey(dirParentPath)) { reverseIndex.get(dirParentPath).add(dirPath); } else { LinkedList<String> list = new LinkedList<String>(); list.add(dirPath); reverseIndex.put(dirParentPath, list); } map.put(dirPath, dirParentPath); } }

There was an error in this gadget