Thursday, December 10, 2015

ASP.Net 5 - Simple Html Page App

Motivation

As part of a recent undertaking to learn Angular JS I started using the beta version of ASP.Net 5.   I figured why not introduce lots of new things at once and hope for the best.    As you might expect learning a new framework while trying to learn a new (to me) technology did prove a bit tough and required a few extra google searches and test programs.   ASP.Net 5 is pretty straight forward, the changes to Visual studio are well documented and there are lots of examples to help get started.   I had trouble finding simple examples that demonstrated one idea or task.   Hopefully the examples I create here will help.

Serve up Basic Html file


This example will show how to create a simple app to server up an html file;  test1.html.

Step 1a)   Create new Web Application


Start up Visual Studio 2015 and choose start new project.
Choose  Templates - c# -  Web


 Choose an empty ASPNET 5 Preview Template


Step 1b) Build & Run

Build and run the application. 


Step 2) Add support for static files

ASP.Net 5 uses the new application framework to process an http request.   The request is passed through a pipeline of middleware components.  See  http://docs.asp.net/en/latest/conceptual-overview/aspnet.html#middleware in the overview document to get more details.

The StaticFiles middleware component is required to serve up html files.   

The initial Configure method in the Startup class adds two items to the request pipleline; UseIISPlatformHandler() and app.Run() with a fixed action of returning the message Hello World.

Initial Startup Class

    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
        }

        public void Configure(IApplicationBuilder app)
        {
            // Add the platform handler to the request pipeline.
            app.UseIISPlatformHandler();

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
    }


To server up static files you need to change the app.Run() middleware to app.UseStaticFiles()
// Add static files to the request pipeline.
  app.UseStaticFiles();
The Configure method will have two handlers.

public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
        }

        public void Configure(IApplicationBuilder app)
        {
            // Add the platform handler to the request pipeline.
            app.UseIISPlatformHandler();

            app.UseStaticFiles();
        }
    }

The UseStaticFiles middleware is defined in the Microsoft.AspNet.StaticFiles library.   Add this library using nuget.


Nuget will modify the project.json file adding the Microsoft.AspNet.StaticFiles package.


You can modify the project.json file directly if you prefer.

Step 3) Add Test1.html

Add an html file to the project.    Right click on wwwroot and choose add new item.   Then add test1.html or whatever your favorite name may be.



Step 4) Run

Build and run the application again and navigate to the new html page.


Conclusion

My goal in creating this simple program was to investigate a client side app that didn't include any unnecessary C# libraries.   It turns out its easy and it works well.  I would like to build an Angularjs app using my IDE of choice and serve it up in IIS.  Before adding Angularjs I thought it would be good to understand and create a base program first and this is about as simple as it gets.    With Asp.Net 5 you can create a client side program without including MVC or any other unnecessary libraries and I think that's cool.   (But Im biased).

---
The code is available at https://github.com/JayJohnson29/AspNet5



   

Friday, October 17, 2014

XOR Neural Network using Backpropagation; c# Examples

Artificial Neural Network for XOR function

Recently I was reading about Machine Learning in MSDN Magazine and thought it would be fun to revisit the classic XOR Neural Network example problem before moving on to more complicated problems like image recognition for the MINST data set.  The goal of the XOR problem is to train a network to learn the XOR function using backpropagation to adjust the weights.     Recall that XOR returns true if either one of the inputs is true but not both.

The point of this post is not to explain how backprogation works but to introduce two sample Neural Network programs that learn the XOR function.

In my first attempt, the program had one hidden layer of nodes with no bias nodes.     This was the basic configuration we used in my first AI course back in the day.

This proved to be a fragile configuration.    With two hidden nodes the network never learned the function.   With three it took close to 60,000 iterations.    The learning rate and the initial values of the weights also affected whether or not it succeeded.

In my second attemp, I added a bais node.  I noticed all the recent papers I read used a bias node so I modified the program to include a bias node at the input and hidden layers.

This configuration learned the XOR function in 10,000 iterations and was more flexible with regard to initial weight values and the Learning Rate.

When I was in school in the early 90s we just recieved a bunch of new workstations from IBM, Sun and HP.   They were all unix workstations running some type of RISC processor.  They were very cool and we felt very fortunate to have them.    Running the neural network training programs took minutes.    My ThinkPad laptop has an 8 core processor with 8 Gb of RAM and the programs run in seconds.   I dont consider my laptop very cool and while I'm glad to have it, I dont feel execptionally fortunate.    Im not sure if this is part of Moore's law in action but computers and networks have become so fast its easy to take them for granted.

Code

The progams are written in c# using Visual Studio 2013. The code for both programs can be downloaded from git hub.

https://github.com/JayJohnson29/XorNeuralNetwork





Friday, November 15, 2013

Git Commands


Create and checkout a branch

git checkout -b

This command creates a branch locally and then checks it out.


Create Branch

git branch

This command creates the branch in the local repository


Checkout Branch

git checkout

This command sets the current branch to


Check if a branch exists

git show-ref --verify --quiet refs/heads/int-2013.3
echo $?

git show-branch int-2013.3
echo $?


Sunday, February 24, 2013

diskpart

Diskpart is a utility to configure disks.    Once you know the tricks its relatively easy to use.

The way it works you first select a disk and then all operations are applied to the selected disk.   The command is below (note disk 1 was already selected, indicated by the *)


DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online         1862 GB      0 B
* Disk 1    Offline        1862 GB      0 B


DISKPART> select disk=1

Disk 1 is now the selected disk.


Tuesday, October 11, 2011

Stored Proc References

Q) How do I find all the stored procs that reference tables containing the column named CompanyID

A)

select
cols.table_name,
so.name
from
information_schema.columns cols ,
syscomments sc
INNER JOIN sysobjects so ON sc.id=so.id
where
cols.column_name = 'CompanyID'
and sc.TEXT LIKE '%' + cols.table_name + '%'


The first thing is to find all the tables with company id

select * from information_schema.columns where column_name = 'CompanyID'

The second thing is to find all the stored procs that reference a table

----Option 1
SELECT DISTINCT so.name
FROM syscomments sc
INNER JOIN sysobjects so ON sc.id=so.id
WHERE sc.TEXT LIKE '%tablename%'
----Option 2
SELECT DISTINCT o.name, o.xtype
FROM syscomments c
INNER JOIN sysobjects o ON c.id=o.id
WHERE c.TEXT LIKE '%tablename%'

thanks to pinal dave
http://blog.sqlauthority.com/2006/12/10/sql-server-find-stored-procedure-related-to-table-in-database-search-in-all-stored-procedure/


The last thing is to combine the two queries which was the select at the top

select
cols.table_name,
so.name
from
information_schema.columns cols ,
syscomments sc
INNER JOIN sysobjects so ON sc.id=so.id
where
cols.column_name = 'CompanyID'
and sc.TEXT LIKE '%' + cols.table_name + '%'

Wednesday, June 22, 2011

WCF - Error in deserializing body of reply message

I used WCF services to connect to a SOAP service at Cyber Source.

Visual Studio takes care of most details which is great but the code didnt work. The reply threw a CommunicationException with the message:

"Error in deserializing body of reply message for operation 'runTransaction'."

The problem (for me) is that the buffer sizes are too small. I needed to increase the size of the maxTableCharCount parameter in the config file.

<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />


I found the answer here:

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/9bce995f-21d6-4898-9c17-31d6b10587cb/

Thursday, May 19, 2011

Change Database Connection for EF Model in VS

Q) How do I connect my EF Entity Model to a different database?


When you add an entity Model to your project a db connection wizard is presented where you specify the connection details. If you want to change the database name or server at some point you can edit the connection string in the app.config file for the project containing your entity model.

Tuesday, May 17, 2011

Windows Server 2008 Sql Server 2008 Firewall Configuration

After installing Sql Server 2008 an exception needs to be added to the firewall.

Sql Server uses the following Ports as noted here
I only opened up 1433.

Beyond using SQL Browser, you can perform a network scan looking for services listening on default ports for any of the SQL components. These default ports are

Database Engine

1433

SQL Browser

1434 for DB engine

SQL Broker

4022, by convention

Analysis Services

2383

Reporting Services

80/443



I found some instructions here http://msdn.microsoft.com/en-us/library/cc646023.aspx

I ran this command.

PS C:\Users\Jimmy>netsh firewall set portopening protocol = TCP port = 1433 name = SQLPort mode = ENABLE scope= SUBNET profile = CURRENT

IMPORTANT: Command executed successfully.
However, "netsh firewall" is deprecated;
use "netsh advfirewall firewall" instead.
For more information on using "netsh advfirewall firewall" commands
instead of "netsh firewall", see KB article 947709
at http://go.microsoft.com/fwlink/?linkid=121488 .

Ok.

PS C:\Users\Jimmy>

Tuesday, April 26, 2011

Who's Logged into that Server

Q) How can I determine who's logged into a remote computer

qwinsta /server:utility2

Q) How can I close one of the sessions

PS C:\> rwinsta /server:utility2 3

I found this information at the following link

ASP.Net 5 - Simple Html Page App

Motivation As part of a recent undertaking to learn Angular JS I started using the beta version of ASP.Net 5.   I figured why not introdu...