Roel van Lisdonk on February 27th, 2015

Windows with a couple of development tools takes up about 126GB of my 128GB SSD, to free-up some space I followed the guide at: http://www.hanselman.com/blog/GuideToFreeingUpDiskSpaceUnderWindows81.aspx

 

Then I moved the "C:\ProgramData\Package Cache" used by Visual Studio to D:\.

 

I did this by following the instructions at: http://superuser.com/questions/455853/can-i-delete-the-the-folder-c-programdata-package-cache

 

1. Move folder from C:\ProgramData to D:\ProgramData

This must be a move of the complete “Package Cache” folder, so after move you will have a folder C:\ProgramData, that does NOT contain the folder “Package Cache”.

2. Create a filesystem junction: mklink /J "C:\ProgramData\Package Cache" "D:\ProgramData\Package Cache"

This will create a filesystem junction, that will point all software that wants to access  "C:\ProgramData\Package Cache" to "D:\ProgramData\Packa Cache".

 

That alone saved me about 6GB.

Tags:

On my home network I wanted to set up a Remote Desktop connection to a Windows 10 machine from a Windows 8.1 machine, by using the credentials of a Microsoft account. Both machines were using the same Microsoft account to login.

 

Turns out I had 2 problems, first on the Windows 10 machine I had not turned on sharing.

When I went to Control Panel\Homegroup, on the right of the screen a text appeared to enabled sharing, when I clicked OK, I could connect with Remote Desktop to the machine, but then I had to enter credentials.

 

Assuming my email address, used to login with my a Microsoft Account is: john@tools.com then you should enter the username as: MicrosoftAccount\john@tools.com

 

Yes you really have to put the text “MicrosoftAccount” in front of the email address.

 

 

image

Tags:

By default C# and JavaScript pass object references by value not by reference, but what does that mean?

Well if you assign an object to a variable, this variable is just a pointer to that object in memory.

(Examples in C#)

var person = new Person
            {
                Id = 2,
                Name = "John"
            };

The variable person is just a pointer to the object in memory, the memory contains the object { Id = 2, Name = “John”}

When passed to a function, a copy of this pointer is supplied to the function, not the object itself.

So when you update properties of the object in the function, the variable outside the function will get updated.

 

But when you set the object to NULL in the function, the variable outside the function will NOT be set to NULL.

 

In C# you can override this by adding the “ref” keyword before the parameter, in that case the pointer of the variable will be passed and thus setting the object to null in the function will set the variable outside the function to NULL.

 

Some unit test to explain this:

namespace Test
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;      

[TestClass]
public class Research
{

[TestMethod]
public void Update_object_properties_should_update_variable()
{

    var person = new Person
    {
        Id = 2,
        Name = "John"
    };

    UpdateObjectProperties(person);

    Assert.IsTrue(person.Name == "Mike");
}

public void UpdateObjectProperties(Person person)
{
    person.Name = "Mike";
}

[TestMethod]
public void Update_object_pointer_should_not_update_variable()
{

    var person = new Person
    {
        Id = 2,
        Name = "John"
    };

    UpdateObjectPointer(person);

    Assert.IsTrue(person.Name == "John");
}

public void UpdateObjectPointer(Person person)
{
    person = null;
}
}

public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
}
}

 

image

 

More info can be found at:

http://stackoverflow.com/questions/9717057/c-sharp-passing-arguments-by-default-is-byref-instead-of-byval

http://jonskeet.uk/csharp/parameters.html

http://jonskeet.uk/csharp/references.html

Tags: ,

Roel van Lisdonk on January 26th, 2015

When updating Google Chrome 39 64 bit on Windows 8.1 I was getting the error:

Update failed (error: 7) An error occurred while checking for updates: Google Chrome or Google Chrome Frame cannot be updated due to inconsistent Google Update Group Policy settings. Use the Group Policy Editor to set the update policy override for the Google Chrome Binaries application and try again; see http://goo.gl/uJ9gV for details.

 

To solve this problem:

  • Close all Google Chrome instances
  • Start > Run > regedit
  • Find and open HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Update\

If you have the following values listed under the above key then all attempts to update Google Chrome and/or Google Chrome Frame will fail:

  • Update{8A69D345-D564-463C-AFF1-A69D9E530F96}
  • Update{8BA986DA-5100-405E-AA35-86F34A02ACBF}

In my case it was only: Update{8A69D345-D564-463C-AFF1-A69D9E530F96}

After removing this registry key and restarting Google Chrome I was able to update to Chrome 40

Tags:

The Task Runner Explorer extension for Microsoft Visual Studio 2013 found the gulpfile.js in my project, but the task in that file where not listed, just beneath the gulpfile.js, (No tasks found) was displayed, this was caused by missing dependencies.

image

 

To fix this:

Just open a command prompt.

Change directory to the folder containing the file “gulpfile.js”

Then enter: npm install

All dependency for gulp should be installed, now when you op the project in Visual Studio 2013 the tasks should be shown.

 

image

Tags:

The code and live preview can be found here:

http://plnkr.co/edit/jdnRjO?p=preview

 

When no date is entered a “pink” border will be shown:

image

 

When a date is entered that’s before the “min” date a “pink” border will be shown:

 

image

 

When a date on or after the min date is entered, no border will be shown:

 

image

Tags: ,

Roel van Lisdonk on January 15th, 2015

 

If you want to rename an user in Active Directory by using C#, you can use the following code:

using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("This application will rename a user in active directory.");
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("Enter domain:");
                string domain = Console.ReadLine();

                Console.WriteLine("Connecting to domaincontroller.");
                using (PrincipalContext context = new PrincipalContext(ContextType.Domain, domain))
                {
                    if (context == null)
                    {
                        throw new ApplicationException("Domain not found.");
                    }

                    Console.WriteLine("Enter current username (e.g. john):");
                    string currentUserName = Console.ReadLine();
                                        
                    using (UserPrincipal user = UserPrincipal.FindByIdentity(context, currentUserName))
                    {
                        if (user == null)
                        {
                            throw new ApplicationException("User not found.");
                        }

                        Console.WriteLine("Enter new username (e.g. john2):");
                        string newUserName = Console.ReadLine();

                        using (DirectoryEntry entry = (DirectoryEntry)user.GetUnderlyingObject())
                        {
                            Console.WriteLine("Setting account properties in active directory.");
                            entry.InvokeSet("uid", newUserName);
                            entry.InvokeSet("sAMAccountName", newUserName);
                            entry.InvokeSet("userPrincipalName", string.Format("{0}@{1}", newUserName, domain));
                            entry.CommitChanges();

                            Console.WriteLine("Rename common-name (CN).");
                            entry.Rename("CN=" + newUserName);

                            Console.WriteLine("User successfully renamed.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            
            Console.WriteLine("Press enter to continue...");
            Console.ReadLine();
        }
    }
}

Tags:

See the plunker for the code: http://plnkr.co/edit/WroQIwLj4K8vUlVOCkDx?p=preview

 

When no text is entered, the kendo combo box should be invalid:

image

 

When a text is entered, that does not match a valid entry, the kendo combo box should be invalid:

 

image

 

When a text is entered, that does match a valid entry, the kendo combo box should be valid and the selected person should be shown:

 

image

Tags: ,

Roel van Lisdonk on January 8th, 2015

I created a simple plunker based on http://www.emberex.com/programmatically-setting-focus-angularjs-way/

 

When the user clicks on the button the textarea gets focused.

 

image

 

Here is the code:

http://plnkr.co/edit/eo7es1xZTdB274BQNXMV?p=preview

Tags:

If you have to support <= IE9, you should not use console.log without a polyfill. If you don’t use a polyfill, console.log will throw an error. Console.log will only be available if the developertools are open:

 

http://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function/5473193#5473193

Tags: