Wednesday 30 July 2014

Device Unauthorized when debugging android on a new PC

When you connect a new PC to a device for debugging android apps, it doesn't initially work.

In Android Device Chooser, the window displays the device serial number and Target shows 'unknown'.

This is because the PC needs to be registered with the device. Disconnect the USB cable and reconnect it. On the device the window should appear.

Click OK to register and authorize the PC.

Wednesday 23 July 2014

Deploying to Production IIS 8 on Windows 2012

I had problems deploying a new Web application to IIS 8 on Windows 2012.

Firstly the Web site just returned a 404 error. So to increase the verbosity (by following this post) the Web application was reconfigured through web.config:

        <httperrors errormode="Detailed">
        <customerrors mode="Off">
        <compilation debug="true">

Then an error showed itself:

Detailed Error Information:
Module   IIS Web Core
Notification   BeginRequest
Handler   Not yet determined
Error Code   0x80070021
Config Error   This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
Config File   \\?\C:\inetpub\wwwroot\Monitor Web Site\web.config

This was fixed by running:

%windir%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/handlers

Then another error showed itself:
HTTP Error 500.21 - Internal Server Error
Handler "ExtensionlessUrlHandler-Integrated-4.0" has a bad module "ManagedPipelineHandler" in its module list

Most likely causes:
Managed handler is used; however, ASP.NET is not installed or is not installed completely.
There is a typographical error in the configuration for the handler module list.
During application initialization, either the application initialization feature has set skipManagedModules to true, or a rewrite rule is setting a URL that maps to a managed handler and is also setting SKIP_MANAGED_MODULES=1.

This was fixed with this post:
The Web Server (IIS) and Application Server should be installed, and you should also have the optional Web Server (IIS) Support under Application Server.

Solution: I had to install "application server" to server roles and add the Web Server IIS support subsection.

Thursday 17 July 2014

Code for calculating pension projections

void Main()
 // This projection works for personal pensions
 // var performance = 1.0489m;
 var performance = 1.05m;
 // performance = 1.0196m;
 // performance = 1.0782m;
 var inflation = 1.025m;
 var initialFund = 35370;
 var fund = initialFund;
 // See the Fisher equation
 var nominalRate = performance / inflation;
 var nominalDisplayRate = ((nominalRate) - 1) * 100;
 string.Format("Projection: {0:0.##}%", nominalDisplayRate).Dump();
 var year1 = (nominalRate * initialFund);
 year1 = (int)(year1/100) * 100;
 string.Format("Year 1: {0:0.##}", year1).Dump();
 var year3 = (nominalRate * nominalRate * nominalRate * initialFund);
 year3 = (int)(year3/100) * 100;
 string.Format("Year 3: {0:0.##}", year3).Dump();
 var year5 = (nominalRate * nominalRate * nominalRate * nominalRate * nominalRate * initialFund);
 year5 = (int)(year5/100) * 100;
 string.Format("Year 5: {0:0.##}", year5).Dump();
 var yearX = Math.Pow((double)nominalRate, 10) * initialFund;
 yearX = (int)(yearX/100) * 100;
 string.Format("Year 10: {0:0.##}", yearX).Dump();
// for (var i = 1; i<=365; i++)
// {
//  49500m
// }