Handy Hints

Enable CORS on windows

Often i recognize that the PUT and DELETE http methods are not allowed and in these days of REST Apis this can be a problem. Often is enough to enable the support for CORS (Cross-origin resource sharing).

To do this you could add to the Global.asax the following Application_BeginRequest implementation.

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        var context = HttpContext.Current;
        var response = context.Response;

        // enable CORS
        response.AddHeader(
            "Access-Control-Allow-Origin", 
            "*");
            
        response.AddHeader(
            "X-Frame-Options", 
            "ALLOW-FROM *");

        if (context.Request.HttpMethod == "OPTIONS")
        {
            response.AddHeader(
                "Access-Control-Allow-Methods", 
                "GET, POST, PUT, DELETE");
            response.AddHeader(
                "Access-Control-Allow-Headers", 
                "Content-Type, Accept");
            response.AddHeader(
                "Access-Control-Max-Age", 
                "1728000");
            response.End();
            return;
        }
        
        //Here goes the other initializations
    }
}

Disable Java Update

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy] 
    "EnableAutoUpdateCheck"=dword:00000000

Another approach would be to delete the following key blocking the scheduler for Java updates

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\
 CurrentVersion\Run\SunJavaUpdateSched

Reset File Associations Windows 7/8

Restart Ms Download Manager

Simply run...

    %windir%\Downloaded Program Files\TransferMgr.exe

Show hide tabs and spaces VS2010-VS2012

The shortcut to toggle them is

CTR+R, CTRL+W

Castle Windsor-Component is not a typed factory

Facing an exception like...

System.ArgumentException: 
    Component MyPackaged.IMyTypedFactory is not a typed factory. 
    TypedFactoryInterceptor only works with typed factories.

Probably you have to force the order of registrations. You should register the Castle TypedFactoryFacility BEFORE registering the IMyTypedFactory.

Suppose your bootstrap works like the following

    var container = new WindsorContainer();
    container.Install(FromAssembly.This());

With two installers like the following

public class MyServicesInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(
            Component.For<IMyTypedFactory>()
            .ImplementedBy<MyTypedFactory>()
            .LifeStyle.Singleton);
    }
}
    
public class MyWindsorInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.AddFacility<TypedFactoryFacility>();
    }
}

To ensure the correct order of initialization you should create a new Castle InstallerFactory. This will take all the types founded and will reorder them. In our specific situation the first to install will be the MyWindsorInstaller!

public class MyCustomInstallerFactory : InstallerFactory
{
    public override IEnumerable<Type> Select(IEnumerable<Type> installerTypes)
    {
        var firstInstaller = installerTypes.FirstOrDefault(it => it == typeof(MyWindsorInstaller));

        var retVal = new List<Type>();
        retVal.Add(firstInstaller);
        retVal.AddRange(installerTypes
            .Where(it => 
                typeof(IWindsorInstaller).IsAssignableFrom(it) &&
                !retVal.Contains(it)
                ));

        return retVal;
    }
}

The bootstrapper would be then changed to:

    var myInstallerFactory = new MyCustomInstallerFactory();
    var container = new WindsorContainer();
    container.Install(FromAssembly.This(myInstallerFactory));

SQLServer Take Db Offline

This means force disconnection and take offline

ALTER DATABASE MyDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE MyDB SET OFFLINE WITH ROLLBACK IMMEDIATE

Download Metro Apps

New Way To Download Metro App In Win 8 And Install For Each computer

Prerequisites

Installation

Download

Sideload Apps in windows 8

Procedure

Windows 8 needs to be prepared before you can sideload apps. The first thing you need to do is enable "Allow all trusted applications to install" in the Group Policy. Keep in mind that the Group Policy is only available in Windows 8 Pro and Enterprise, and not Windows 8 or Windows 8 RT. Users on those systems can change a Registry setting instead.

In case of errors

After entering Windows Store Just click on the Repair button Then close the Windows Store Try running the game or program

Installing Sqitch on windows

If there are unknown errors, like "Verify script 'my script.sql' failed" probably you would need to add the binaries directory for your database to the machine path.

Installing WPS Office on Ubuntu 64 bit

Find the latest deb package (can check the last version on http://wps-community.org/downloads )

wget -O wps.office.deb http://kdl1.cache.wps.com/ksodl/download/linux/a21//wps-office_10.1.0.5707~a21_amd64.deb

Find the libpng12-0 deb package (can check the last version on https://packages.debian.org/jessie/amd64/libpng12-0/download )

wget wps.libpng12.deb http://ftp.us.debian.org/debian/pool/main/libp/libpng/libpng12-0_1.2.50-2+deb8u3_amd64.deb

Install the libpng and mesa, then wps office

sudo dpkg -i wps.libpng12.deb
sudo apt install libglu1-mesa
sudo dpkg -i wps.office.deb

Get and Install the fonts

wget -O wps.fonts.deb http://kdl.cc.ksosoft.com/wps-community/download/fonts/wps-office-fonts_1.0_all.deb
sudo dpkg -i wps.fonts.deb

Get and Install the equation fonts (the last command will take a while)

wget -O wps.equation.zip https://github.com/udoyen/wps-fonts/archive/master.zip
unzip wps.equation.zip
sudo mkdir /usr/share/fonts/kingsoft
sudo cp -r wps-fonts-master/* /usr/share/fonts/kingsoft/
sudo chown -R $USER:$USER /usr/share/fonts/kingsoft
sudo chmod -R o+rw,g+rw /usr/share/fonts/kingsoft
sudo fc-cache -vfs

Remove temporary files

rm wps.*

Last modified on: October 26, 2017