How to set AWS Command Line Interface

pip install awscli

Usage

The AWS Command Line Interface User Guide walks you through installing and configuring the tool. After that, you can begin making calls to your AWS services from the command line.
$ aws ec2 describe-instances

$ aws ec2 start-instances –instance-ids i-1348636c

$ aws sns publish –topic-arn arn:aws:sns:us-east-1:546419318123:OperationsError –message “Script Failure”

$ aws sqs receive-message –queue-url https://queue.amazonaws.com/546419318123/Test

You can get help on the command line to see the supported services,
$ aws help
the operations for a service,
$ aws autoscaling help
and the parameters for a service operation.
$ aws autoscaling create-auto-scaling-group help

Using Knockout.js with PHP: Best Practices

I recently had a project that made me temporarily shift from my more native c#/asp.net environment and use php on the backend instead. As by more and more asp.net developers these days I have become accustomed to doing just about everything in the front end with the JavaScript library Knockout. Of course knockout.js is completely compatible with php being that it is on the front end while php is on the back end, but in combining php with knockout there are a few things that I have found make the match just a bit smoother.

Use json_encode() to pass PHP arrays to knockout

<?php 
function getOrders() {
include_once 'mysql_connect.php'; 
$email = $_SESSION['Email'];

$query = sprintf("SELECT * FROM `Order` WHERE `Email` = '%s' order by id desc",
		mysqli_real_escape_string($con, $email));
		
$result = mysqli_query($con, $query);
$data = array();
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
  $data[] = $row;
  }

mysqli_close($con);
return json_encode($data);//json_encode() is the key
}
?>

Then on on the front-end:


$(document).ready(function () {
    //Pass JSON encoded data directly into javascript variable
    var data = <?php getOrders(); ?> ;
    var vm = new ViewModel(data);	
    ko.applyBindings(vm);
});

function ViewModel (data){
	self = this;
	self.Orders = ko.mapping.fromJS(data);
}

Use ko.toJS() to send data from your ViewModel to PHP

 
function ViewModel (){
    self = this;
    self.Order = {
		Email:ko.observable(),
		FirstName : ko.observable(),
		LastName : ko.observable(),
		URL : ko.observable(),	
		Comments : ko.observable()	
	};
    self.CreateOrder = function() {
        //Here is where you convert the data to something php can swallow
        var data = ko.toJS({"Data":order});
        $.ajax({
            url: "CreateOrder.php",
            type: 'post',
            data: data,
            success: function (result) {
                console.log(result);
            }		
        });
    };
}

And then on the back end:

<?php
include_once 'mysql_connect.php'; 
//recieve raw data into php variable
$data = $_POST['Data'];

//extract each field from raw data
$email = $data['Email'];
$firstName = $data['FirstName'];
$lastName = $data['LastName'];
$comments = $data['Comments'];
...
?>

How to Add Knockout Computed Observables With the Knockout Mapping Plugin

The knockout Mapping Plugin is a great way to save time, and write less code when creating view models in knockout. When I first started using knockout I was hesitant to use the mapping plugin because I was afraid that I would lose some control over the customization of my view model. But after staring at the documentation for a while, and then tinkering in jsFiddle, I found that it is possible to have full control over the model that the mapping plugin generates.

The following example demonstrates how to manually insert knockout computed observables into an observableArray that is generated with the Knockout Mapping Plugin.

Knockout.js

Knockout.js released by Steve Sanderson in summer of 2010. Although Steve works for Microsoft the decision to release knockout.js as an open source project was right.

It is a standalone javascript library relying on MVVM and Observable patterns. The key principles of knockout.js are:

* a clear separation between domain data, view components and data to be displayed
* the presence of a clearly defined layer of specialized code to manage the relationships between the view components

These features streamline and simplify the specification of complex relationships between view components, which in turn make the display more responsive and the user experience richer.

Knockout.js includes the following features:

* Declarative bindings
* Automatic UI refresh (when the data model’s state changes, the UI updates automatically)
* Dependency tracking
* Templating (using a native template engine although other templating engines can be used

In this example, two text boxes are bound to observable variables on a data model. The “full name” display is bound to a dependent observable, whose value is computed in terms of the observables. When either text box is edited, the “full name” display is automatically updated, with no explicit event handling.

HTML code snippet:

   <p>First name: <input data-bind="value: firstName" /></p>
   <p>Last name: <input data-bind="value: lastName" /></p>
   <h2>Hello, <span data-bind="text: fullName"> </span>!</h2>

Javascript code snippet:

function ViewModel() {
    this.firstName = ko.observable("John");
    this.lastName = ko.observable("Smith");
    this.fullName = ko.computed(function() {
        return this.firstName() + " " + this.lastName();
    }, this);
}
 
ko.applyBindings(new ViewModel());

Installing CUDA Toolkit 5.0

Installing CUDA Toolkit 5.0 on Ubuntu 11.10 Linux

The following explains how to install CUDA Toolkit 5.0 on 64-bit Ubuntu 11.10 Linux. I have tested it on a desktop with AMD Phenom II X4 CPU, 4GB RAM, 1TB hard drive, 800W power supply, and NVIDIA GeForce GTX 650 graphics card. The instruction assumes you have the necessary CUDA compatible hardware support. Depending on your system configuration, your mileage may vary.

 Basic Video Driver

First of all, you have to reconfigure Ubuntu with the basic video driver. Enter the following in a terminal.

$ sudo apt-get –purge remove nvidia*

Then create a new file in /etc/modprobe.d with the following content in order to blacklist the built-in nouveau driver, which conflicts with the CUDA developer video driver that you will install later.

# /etc/modprobe.d/blacklist-nouveau.conf
blacklist nvidiafb
blacklist nouveau
blacklist rivafb
blacklist rivatv
blacklist vga16fb
options nouveau modeset=0

You may manually update the kernel image in a terminal afterward:

$ sudo update-initramfs -u

Now you can reboot the system at this point for the change to take effect.

 

Linux Development Tools

After you have successfully configured Ubuntu Linux with the basic video driver, you can install the Linux development tools.

$ sudo apt-get update
$ sudo apt-get install build-essential

 

OpenGL Developer Driver

To prepare for compiling the OpenGL code samples in the CUDA SDK, you will have to install the OpenGL developer environment as well.

$ sudo apt-get install freeglut3-dev libxi-dev libxmu-dev

 

OpenMPI Developer Driver

Since there is a new MPI sample in the CUDA SDK, you will have to install the OpenMPI environment as well.

$ sudo apt-get install mpi-default-dev

 

CUDA Toolkit

Download the CUDA Toolkit from the CUDA download site. The graphical display manager must not be running during the CUDA video driver install. Hence you should logout your Linux desktop and switch to console mode with the Alt+Ctrl+F2 keystroke. You then login the text console, and stop the graphical display manager.

$ sudo service lightdm stop

You may have to enter the same Alt+Ctrl+F2 keystroke again to resume the text console. Now install the CUDA Toolkit:

$ sudo sh cuda_5.0.35_linux_64_ubuntu11.10.run

And reboot afterward:

$ sudo reboot

 

Environment Variables

Assuming you have accepted the default install locations, you should add the following in the.bashrc file of your home folder.

export CUDA_HOME=/usr/local/cuda-5.0
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64 PATH=${CUDA_HOME}/bin:${PATH}
export PATH

 

CUDA SDK Samples

There should be a copy of the SDK samples in your home directory already, and you can proceed with the build process.

$ cd ~/NVIDIA_CUDA-5.0_Samples
$ make

If everything goes well, you should be able to verify your CUDA installation by running thedeviceQuery sample in bin/linux/release.

Loading Select Drop Down Options using Ajax and Knockout.js

The following shows how to use the knockout options binding when loading the option values from the server with AJAX.

In the following HTML the select box requires 4 bindings. The options binding specifies which variable in the Knockout ViewModel is used to generate the options. The optionsText specifies the name of element in the options array of for the text each option. The optionsValue is the name of the element in the options array for each option value. Finally, the value binding sets which option is selected. IMPORTANT: If you are loading the value from the server make sure the value you are loading matches exactly the optionsValue elements.

HTML:

<table>
  <thead>
     <tr>
        <th>Id</th><th>Security Level</th>
     </tr>
  </thead>
  <tbody data-bind="foreach: inspectors">
    <tr>
      <td><span data-bind="text: InspectorID" /> </td>
      <td>
        <select data-bind="
          options: $root.inspectorLevels, 
          optionsText: 'Description', 
          optionsValue: 'InspectorLevelID', 
          value: InspectorLevelID">
        </select>
      </td>
    </tr>
  </tbody>
</table>

Another important thing which seems to be only in the options binding is to set the $.ajax attribute “async” to false. If not, then the options may load after the values and thereby changing the observable values to the default option.

Javascript Knockout ViewModel:

 
<script>
    function Inspector(data) {
        this.InspectorID = ko.observable(data.InspectorID);
        this.InspectorLevelID = ko.observable(data.InspectorLevelID);
    }

    function InspectorListViewModel() {
        var self = this;
        self.inspectors = ko.observableArray([]);
        self.inspectorLevels = ko.observableArray([]);
    
        $.ajax({
            url:"@Url.Action("getInspectorLevels")",
            type: "post",
            contentType: "application/json",
            async:false,
            success:function (data) {
                var array = [];
                $.each(data, function (index, value) {
                    array.push(value);
                });
                self.inspectorLevels(array);
            }
        };
       
    }
    ko.applyBindings(new InspectorListViewModel());
</script>

How to configure SQL Server 2012 Express to allow remote connections

INTRODUCTION

When you try to connect to an instance of Microsoft SQL Server 2012 Express from a remote computer, you might receive an error message. This problem might occur when you use any program to connect to SQL Server.

For example, you receive the following error message when you use the SQLCMD utility to connect to SQL Server:

Sqlcmd: Error: Microsoft SQL Native Client: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2012, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.

This problem might occur when SQL Server 2012 Express is not configured to accept remote connections. By default, SQL Server 2012 Express Edition do not allow remote connections.

To configure SQL Server 2012 Express to allow remote connections, you must complete these steps:
•Enable remote connections on the instance of SQL Server that you want to connect to from a remote computer.
•Turn on the SQL Server Browser service.
•Configure the firewall to allow network traffic that is related to SQL Server and to the SQL Server Browser service.

To enable remote connections on the instance of SQL Server 2012 Express and to turn on the SQL Server Browser service, use the SQL Server 2012 Surface Area Configuration tool. The Surface Area Configuration tool is installed when you install SQL Server 2012.

Enable remote connections for SQL Server 2012 Express

You have to enable remote connections for each instance of SQL Server 2012 Express that you want to connect to from a remote computer. To do this, follow these steps:
1.Click Start, point to Programs, point to Microsoft SQL Server 2012 Express, point to Configuration Tools, and then click SQL Server Surface Area Configuration.
2.On the SQL Server 2012 Surface Area Configuration page, click Surface Area Configuration for Services and Connections.
3.On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Remote Connections, click Local and remote connections, click the appropriate protocol to enable for your environment, and then click Apply.

Note Click OK when you receive the following message:
Changes to Connection Settings will not take effect until you restart the Database Engine service.

4.On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Service, click Stop, wait until the MSSQLSERVER service stops, and then click Start to restart the MSSQLSERVER service.

Enable the SQL Server Browser service

If you are running SQL Server 2012 Express by using an instance name and you are not using a specific TCP/IP port number in your connection string, you have to enable the SQL Server Browser service to allow for remote connections. For example, SQL Server 2012 Express is installed with a default instance name of Computer Name\SQLEXPRESS. You only have to enable the SQL Server Browser service one time, regardless of how many instances of SQL Server 2012 Express you are running. To enable the SQL Server Browser service, follow these steps.

Important These steps may increase your security risk. These steps may also make your computer or your network more vulnerable to attack by malicious users or by malicious software such as viruses. We recommend the process that this article describes to enable programs to operate as they are designed to, or to implement specific program capabilities. Before you make these changes, we recommend that you evaluate the risks that are associated with implementing this process in your particular environment. If you choose to implement this process, take any appropriate additional steps to help protect your system. We recommend that you use this process only if you really require this process.
1.Click Start, point to Programs, point to Microsoft SQL Server 2012 Express, point to Configuration Tools, and then click SQL Server Surface Area Configuration.
2.On the SQL Server 2012 Express Surface Area Configuration page, click Surface Area Configuration for Services and Connections.
3.On the Surface Area Configuration for Services and Connections page, click SQL Server Browser, click Automatic for Startup type, and then click Apply. Note When you click the Automatic option, the SQL Server Browser service starts automatically every time that you start Microsoft Windows.

4.Click Start, and then click OK.
Note When you run the SQL Server Browser service on a computer, the computer displays the instance names and the connection information for each instance of SQL Server that is running on the computer. This risk can be reduced by not enabling the SQL Server Browser service and by connecting to the instance of SQL Server directly through an assigned TCP port. Connecting directly to an instance of SQL Server through a TCP port is beyond the scope of this article. For more information about the SQL Server Browser server and connecting to an instance of SQL Server, see the following topics in SQL Server Books Online:

•SQL Server Browser Service
•Connecting to the SQL Server Database Engine
•Client Network Configuration

Create exceptions in Windows Firewall

These steps apply to the version of Windows Firewall that is included in Windows OS. If you are using a different firewall, see your firewall documentation for more information.

If you are running a firewall on the computer that is running SQL Server 2012 Express, external connections to SQL Server 2012 are blocked unless SQL Server 2012 Express and the SQL Server Browser service can communicate through the firewall. You must create an exception for each instance of SQL Server 2012 Express that you want to accept remote connections and an exception for the SQL Server Browser service.

SQL Server 2012 Express uses an instance ID as part of the path when you install its program files. To create an exception for each instance of SQL Server, you have to identify the correct instance ID. To obtain an instance ID, follow these steps:
1.Click Start, point to Programs, point to Microsoft SQL Server 2012 Express, point to Configuration Tools, and then click SQL Server Configuration Manager.
2.In SQL Server Configuration Manager, click the SQL Server Browser service in the right pane, right-click the instance name in the main window, and then click Properties.
3.On the SQL Server Browser Properties page, click the Advanced tab, locate the instance ID in the property list, and then click OK.
To open Windows Firewall, click Start, click Run, type firewall.cpl, and then click OK.
Create an exception for SQL Server 2012 Express in Windows Firewall
To create an exception for SQL Server 2012 in Windows Firewall, follow these steps:1.In Windows Firewall, click the Exceptions tab, and then click Add Program.
2.In the Add a Program window, click Browse.
3. Click C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe, click Open, and then click OK.
4.Repeat steps 1 through 3 for each instance of SQL Server 2012 Express that needs an exception.

Create an exception for the SQL Server Browser service in Windows Firewall
To create an exception for the SQL Server Browser service in Windows Firewall, follow these steps:1.In Windows Firewall, click the Exceptions tab, and then click Add Program.
2.In the Add a Program window, click Browse.
3.Click the C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe executable program, click Open, and then click OK.

Note The path might be different, depending on where SQL Server 2012 Express is installed.

About Software Quality

Software companies that install the right kind of procedures have made enormous progress in avoiding failures. First of all successful companies do not ignore uncertainty – the address it. They also establish quality control mechanisms that simultaneously speed up the whole process. And they reach for new paradigms such as building software from reusable components.
These companies, however, are by far not the rule; in fact, they are exception.