-
Best investments for developers
Optimizing the office setup can have a great impact on a developers performance. Here are some things that I wouldn’t want to miss ever again: Big Monitor or multiple Monitors Not having to worry about screen estate is a must. Developers use lots of information from different sources all the time, so you should have a really big…
-
See changed files between GIT commits
Problem You want to see the changed files between two commits in a GIT repository, e.g. to upload only changes to a webserver. Solution git diff –name-only SHA1 SHA2 Sample git diff –name-only 71d9def3c587ca8d26b8140560f6bb3c89ec9593 HEAD Sources http://stackoverflow.com/a/1552353
-
Compact and pretty GIT log
Problem You want to see all your commits of a git repository but the default “git log” output is not very nicely formatted and verbose. Solution Use the following command: git log –author=”Your Name” –pretty=”%C(yellow)%h%Cred%d%Creset %s%C(white), %C(green)%ar%Creset” The output will look like this: Of course you could also remove the –author parameter or add the –graph parameter…
-
checkstyle:check doesn’t use custom ruleset
Problem You use Checkstyle with custom rules in a Maven build. While the check via mvn install is performed with the custom ruleset, a check via mvn checkstyle:check or checkstyle:checkstyle is performed with the standard (Sun + Maven) ruleset. With some tinkering you can get it to check no rules, but not to use the custom ruleset.…
-
USB device not recognized / Unknown device / Device descriptor request failed
Problem A micro USB device (e.g. Smartphone) isn’t recognized by the USB host anymore. Yet the device still charges, so the USB port probably isn’t broken. Solution Use a needle and toothbrush to clean the micro USB port. Remember to turn the device off and ideally remove the battery before cleaning. If that didn’t work……
-
Cyborg R.A.T. Auto Profile Load
Situation Mad Catz Cyborg R.A.T. mouses can be programmed using Smart Technology profile editor. Problem The activated profile resets every time Windows starts. Solution The profile needs to be saved to a specific folder and marked as startup-profile. Locate the “SmartTechnology Profiles” folder. On a default Windows 8 install it can be found under C:\Users\Public\Public…
-
ntfs-3g can’t mount NTFS partition
Problem You can’t mount a NTFS partition using ntfs-3g and the error message states, that the partition is in an “unsafe state”. Solution Put the hard drives into a windows machine. In the power options set Sleep – Allow hybrid sleep to “Off”. Now shutdown the PC with the following command to perform a full…
-
CentOS Installation fails – “Unable to read package metadata.”
Problem CentOS installation fails with the message: “Unable to read package metadata. This may be due to missing repodata directory. Please ensure that your install tree has been correctly generated”. Solution 1 Add the corresponding repository server. In case of CentOS 6.5 64bit: http://mirror.centos.org/centos/6.5/os/x86_64/ Solution 2 See the following stackoverflow thread: http://stackoverflow.com/questions/21637068/unable-to-read-package-metadata-this-may-be-due-to-missing-repodata-directory
-
WampServer can’t start Apache
Situation and Problem WampServer can’t start Apache and the windows service (wampapache) can’t be started manually. Solution Make sure no other webserver is running. Check [WampServer context menu] > [Apache] > [Service] > [Test Port 80]. If Visual Studio, WebMatrix or anything similar is installed, IIS could be active. To really get rid of IIS…
-
Creating a single executable from multiple .NET assemblies
Problem You have a .NET application that uses multiple assemblies but you want it as a single executable. Solution Use ILMerge to merge the assemblies into one executable. Solution (with WPF support) Embed the required assemblies as embedded resources in your project and extend the assembly resolving to check the embedded resources (see second link…
-
WPF Text Rendering Optimization (Text of WPF application is blurry or pixelated)
Situation You’re building a WPF application. Problem Some text is rendered blurry or pixelated. Solution Modify the text render options corresponding to your needs. Properties you can set on any UIElement: TextOptions.TextFormattingMode TextOptions.TextRenderingMode TextOptions.TextHintingMode A settings that has worked for me very well is TextOptions.TextFormattingMode=”Display”. These settings are inherited by all sub-elements so it’s okay…
-
Mocking a generic method (that uses TResult) with Microsoft Moles
Situation There is a generic method that uses TResult which you want to mock using Microsoft Moles. Problem You can’t just assign a delegate like on a non-generic method. Solution Create a delegate that behaves like the mocked method should. Define the concrete expected parameter types. Instantiate a new MolesDelegates.Func with the corresponding type-parameters and…
-
Disable anti-aliasing in WPF
Situation You’re creating some kind of control that needs to be sharply visible. Problem WPF uses anti-aliasing on default so the control is rendered “soft”. Solution Deactivate anti-aliasing for the whole WPF application, the control or the specific part that needs to be sharp by setting the EdgeModeProperty to aliased. Sample /// <summary> /// Interaction…
-
“InitializeComponent() does not exist in the current context” after copying XAML files
Situation You copied XAML files in Visual Studio. Problem Visual Studio now can’t compile anymore, reporting that the InitializeComponent() method in the code-behind of your XAML files does not exist in the current context. Solution The build action of your XAML files has probably changed to “Resource”. Change it (back) to “Page”. Sources http://stackoverflow.com/questions/954861/why-can-visual-studio-not-find-my-wpf-initializecomponent-method
-
Localizing WPF controls with ResX files
Situation You want to localize a WPF control. Problem Books on WPF recommend to use Microsofts LocBaml.exe, which is actually just a sample that is, of course, not integrated anywhere. Solution Localize the WPF control using ResX files. create the ResX files set the scope of the ResX files to public add the Properties namespace…
-
Using a CLR-namespace of another assembly in XAML
Situation You want to use a CLR namespace of another assembly in your XAML. Problem A simple xmlns:custom=”clr-namespace:MyOtherAssembly.MyDesiredNamespace” won’t do the trick. Solution Identify the assembly within the namespace string. Example xmlns:custom=”clr-namespace:MyDesiredNamespace;assembly=MyOtherAssembly” Sources http://msdn.microsoft.com/en-us/library/ms747086.aspx
-
Setting the culture on WPF bindings
Situation You work on WPF bindings, for example a binding to a DateTime object. Problem The DateTime object is displayed in en-US culture format. Solution Set the current culture on the root element, which is most probably the outer most Grid element, of your XAML. For example: Set the culture in the corresponding ViewModel constructor…
-
“QTAgent32.exe reagiert nicht mehr” appears when running unit-tests
Situation You are writing unit-tests and maybe are refactoring the implementation along the way. Problem “All of a sudden” QTAgent32.exe crashes when you run the tests. Solution A unit-test (or changed implementation) most probably caused a stack overflow. Attach the debugger to QTAgent32.exe (use the “Debug” button on the crash-window), so you can see the…
-
WPF localization
Sources ResX: http://compositeextensions.codeplex.com/discussions/52910?ProjectName=compositeextensions MarkupExtension: http://www.wpftutorial.net/LocalizeMarkupExtension.html
-
Get PublicKeyToken of an assembly reference from within Visual Studio
Situation You need the public key token of an assembly reference. E.g. to set the InternalsVisibleTo() attribute for a Unit-Test. Problem There is no standard mechanism embedded in Visual Studio (2010). Solution Create a “external tool” entry that calls sn.exe and redirects the output to the output window. Dialog: [Tools] – [External tools…] – [Add]…
-
XmlSerializer throws FileNotFoundException when debugging
Situation You are using a XmlSerializer. Problem The constructor XmlSerializer(Type) throws a FileNotFoundException when debugging. Solution Pre-Compile the Serializer. See http://msdn.microsoft.com/en-us/library/ee704594.aspx for details. Alternative Configure Visual Studio not to break on System.IO.FileNotFoundException thrown by the CLR through opening the dialog [Debug] – [Exceptions] and unchecking the checkbox for “Common Language Runtime Exceptions” – “System.IO” – “System.IO.FileNotFoundException” Sources…
-
The invocation of the constructor on type X that matches the specified binding constraints threw an exception
Situation You want to edit a WPF application using Visual Studio. Problem Visual Studio throws a XamlParseException that says ‘The invocation of the constructor on type X that matches the specified binding constraints threw an exception’. Solution Open the dialog [Debug] – [Exceptions] (CTRL+D, E) and check the ‘Thrown’ checkbox for ‘Common Language Runtime Exceptions’.…
-
Using Microsoft Moles and dynamics (DLR)
Situation You want to use the ‘dynamic’ type in your unit-test. Problem An InvalidOperationException that says ‘Dynamic operations can only be performed in homogenous AppDomain.’ is thrown. Solution Changed the attribute ‘enabled’ of the node ‘legacyCasPolicy’ to ‘false’ in the following configuration file: C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEPrivateAssembliesMicrosoft.Moles.VsHost.x86.exe.config Sources http://weblogs.asp.net/mjarguello/archive/2011/04/26/using-moles-with-dlr.aspx http://www.cameronfletcher.com/post/InvalidOperationException-Dynamic-operations-can-only-be-performed-in-homogenous-AppDomain.aspx http://social.msdn.microsoft.com/Forums/en/pex/thread/0a931fc1-9049-482a-bf2d-5499ccf65b82 http://stackoverflow.com/questions/4230909/odd-exception-in-mvc-3-project
-
MessageBox in a unit-test
Situation You want to unit-test a method which uses a MessageBox. Problem The MessageBox will pop up and stop the execution of all tests until the user chooses an action (e.g. presses “OK”). Solution One way around this issue is mocking the MessageBox class to just return the expected DialogResult, which can be done using…
-
FxCop ignores GlobalSuppressions
Problem FxCop ignores the GlobalSuppressions file. Solution Open the build properties of the project ([Menu] – [Project] – [Properties] – [Build]) Add “CODE_ANALYSIS” to field [Conditional compilation symbols]. Hint: This field may be different between Debug and Release mode.
-
Using reflection to unit-test private methods
Situation There is a class called “MyClass” which has a private method called “MyPrivateMethod” (which expects a single string parameter) that you want to unit-test. Problem You can’t access private methods from the test class by just calling them. Solution Use reflection to invoke the method. typeof(MyClass).GetMethod(“MyPrivateMethod”, BindingFlags.NonPublic | BindingFlags.Instance) .Invoke(null, new object[] { “MyStringParameter” }); Hint: Static methods require the BindingFlag…