Wednesday, September 17, 2014

Disconnect users' RDP connection from a remote server

Sometimes you get the message "too many users connected", or you just want to disconnect a hanging session of yourself, and can't access the remote servers desktop, command line tools exist :

To check how many users are connected (and get the session Id of the session you want to kick:

qwinsta /server:[server name/ip]

This will show a list containing sessionname, username, id, etc. 
It's the Id we need for the next step :

rwinsta /server:[server name/ip]  [SessionId]

If you have the necessary rights the session will then be disconnected.

Tuesday, March 4, 2014

Force windows 7 to use Wired LAN connections over wifi connections

I noticed on my Windows 7 pc that the pc connects to WiFi even when connected by a wired LAN. This causes some inconveniences, so I had to find how to turn it of.
To make sure windows 7 prefers LAN, follow these steps :


  • Open the control panel
  • Click Network and Internet
  • Network and Sharing Center
  • (left) Change Adapter Settings
  • Hold the Alt key to make the menus appear and click Advanced
  • Click Advanced settings
  • On the Adapters and Binding tabs :
  • Select the Local Area Connection (names might differ)
  • Push the up arrow next to the list until the Local Area Connection is first in the list













Now just click OK and close all opened screens. Reboot might be needed. 

Tuesday, February 11, 2014

Formatting all files in a solution in Visual Studio

When I had to format all files in a solution,
all I could find at first were macros. Since Visual Studio 2012 doesn't have the macro explorer anymore,
I had to find an other way to accomplish this.

Thanks to this github page I found the follow code that accomplishes just what I need.
Open the Nuget package manager console and paste in (2 lines) :

function f($projectItems) { $projectItems | ? { $_.Name.EndsWith( ".cs" ) } | % { $win = $_.Open('{7651A701-06E5-11D1-8EBD-00A0C90F26EA}') ; $win.Activate() ; $DTE.ExecuteCommand('Edit.FormatDocument') } ; if ($projectItems) { $projectItems | % { f($_.projectItems) } } }

$dte.Solution.Projects | % { f($_.ProjectItems) }
Thanks JayBazuzi!

Wednesday, February 27, 2013

Visual studio locking files on build

More and more I got a problem with visual studio blocking files on build, (Could not copy dll from debug to bin) mostly in web projects (MVC).
A solution was to clean the solution (getting the same error),
waiting a few seconds, cleaning again,
and then building.
Now I found a solution that seems to work,
right click the project,
properties,
Build steps,
and add to the pre build command line :
if exist "$(TargetPath).locked" del "$(TargetPath).locked" if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

(You need to copy the double quotes too).
It might be needed to add this to more than one project in your solution, just look at the error you get when building.

Wednesday, October 13, 2010

Some handy Javascript array methods

Working with javascript arrays today, I found some handy functions:

- Creating an array :
var ray = [];

- Joining two arrays :
var resultArray = ArrayOne.concat(ArrayTwo);

- Getting only unique items in an array :
(Jquery has a unique function, but it does not work on strings / numbers)
Array.prototype.unique = function() {
var result = new Array();
o: for (var i = 0, n = this.length; i < n; i++) {
for (var x = 0, y = result.length; x < y; x++) {
if (result[x] == this[i]) {
continue o;
}
}
result[result.length] = this[i];
}
return r;
}


- For each in JavaScript(using JQuery):
(although JavaScript has for (item in collection) functionality, it is not useful as it also iterates through the methods of the object.)
$.each(collection, function(index, value) { alert(index + ' : ' + value); });




- Bonus JavaScript : Splitting a string by multiple delimiters :
use a regular expression :
var result = myString.split(/[DELIMITERS]+/);
just replace DELIMITERS with the delimiters you want (one character delimiters)

Thursday, October 8, 2009

IE 6 not showing borders

We had a site that did not show the borders around a div in IE6,
After a while (and using google) I found out that I only needed to add
position: relative; on the element or its ancestors (only that element and descendants are fixed)

I found it Here.

Tuesday, October 6, 2009

Good old VB functions in c# Left, Mid, Right

Missing the good old string functions in c# I wanted to recreate them.
This is my solution where they are resurrected as extension methods.


public static class StringHelper
{
    public static string Right(this String source, int length)
    {
        if (source.Length == 0 || length <= 0)
        {
        return "";
        }

        return source.Substring(source.Length - length, length);
    }

    public static string Left(this String source, int length)
    {
        if (source.Length == 0 || length <= 0)
        {
        return "";
        }

        return source.Substring(0, length);
    }

    public static string Mid(this string source, int startIndex, int length)
    {
        if (source.Length == 0 || length <= 0 || startIndex < 0)
        {
        return "";
        }
        return source.Substring(startIndex, length);
    }

    public static string Mid(this string source, int startIndex)
    {
        if (source.Length == 0 || startIndex < 0)
        {
        return "";
        }
        return source.Substring(startIndex);
    }
}


To keep the code from giving errors I check for the length parameter,
if this is not what you want, you can throw an argumentexception for example ...