by David Loo | Jul 6, 2014 | AngularJS
What is AngularJS?
AngularJS is web development framework maintained by Google and a large community of developers. It uses MVC (Model View Controller) capabilities to make both development and testing easier. It takes away all of the UI manipulation away while you can concentrate on working on the business logics.
Your First AngularJS
To demonstrate the basic AngularJS usage by making a simple page which allow the user to enter a name and the page will display a message follow by a message “Hello David”.
To get started we need to download the library from the web site or we can reference the library directly from Google’s CDN (Content Delivery Network) server. I am going to be referencing the CDN for all my demonstrations. (more…)
by David Loo | Jul 6, 2014 | Python
So repetition on Python is very similar to other programming languages, you have the choice of a For and While loop.
For Loop
If you are familiar with foreach statement in C# then this will be easy to understand. Below I have a list of numbers from 1 to 5, then I use the for statement to get each number from numbers and print it.
numbers = [1, 2, 3, 4, 5]
for number in numbers:
print number
While Loop
While loop code snippet below I have created a list of numbers from 1 to 5 and I have an index variable of 0. I will be using the index to iterate through the numbers list and at the same time I increment the index. The while loop will be validating if the index is less than 5, if it is true continue to print the number. If the index is greater than 5 exit out of the while loop.
numbers = [1, 2, 3, 4, 5]
index = 0
while index < 5:
print numbers[index]
index += 1
Download the source code for this blog from my GitHub repository:
https://github.com/csharpguy76/LearnPython
by David Loo | Jul 6, 2014 | Python
Creating a function in Python allows you to reuse code throughout your project. You can create a library of useful functions that can make your coding simplified.
To create a function use the def statement follow by the name of the function and then an open parenthesis and then follow by a list of parameters and then a closing parenthesis and a colon. Then the next line you press TAB to indent your function’s code.
Your function can return a value by specifying the return statement follow by some value.
Create a new file called Functions.py with the following code, or enter the code in your interpreter:
def add(a, b):
return a + b
result = add(2,5)
print result
In the code above I have defined my function called Add with two parameters a and b which will take in an integer value. Then in the function body I am adding a and b together and return the result.
The next line I call the function Add and give it a value of 2 and 5 to be added and then assign the returned value to a variable called result, then I use the print statement to display the result. The expected value return should be displayed is 7.
Download the source code for this blog from my GitHub repository:
https://github.com/csharpguy76/LearnPython
by David Loo | Jul 5, 2014 | Python
It’s always a good practice to add comments to your code, it describes the functionality of the code. It’s also useful for making small notes like To Do’s so that you can refer back to it later.
In Python there are two ways of using comments in your code.
For single line comments you use the # and follow by a comment:
# This is a single line comment
For multiple line or block comments you use the triple double quotes:
"""
this is a multi-line comment
line 1
line 2
"""
by David Loo | Jul 5, 2014 | Python
I have decided that I will blog about programming in Python and before we can start coding we need to install the interpreter on our operating system. Python is available on Linux, Windows and Mac OS X and you can download the installer from here.
If you are an Ubuntu user like myself use the following command in your terminal to install Python:
sudo apt-get install python
After you have installed Python, go and open your favourite text editor and enter the following code and save it as HelloWorld.py:
print "Hello, World"
From a command line or terminal enter the following command to execute the script to see the the output result:
python HelloWorld.py
Ok now you have written your first Python code!
by David Loo | Jun 17, 2014 | C#, Mono
Recently I have been playing with Entity Framework on Linux using Mono and my database server is MS SQL 2014. When I attempt to add an entity I receive the “System.Data.Entity.Core.ProviderIncompatibleException was thrown” exception and the following message was displayed:
An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application’s config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.
So I did some further investigation online and found the following post on how to work around it:
https://entityframework.codeplex.com/discussions/538142
(more…)
by David Loo | Jun 14, 2014 | C#, Mono
So you have been using Entity Framework on Visual Studio and now you would like to code in Linux using Mono and still be able to use Entity Framework. Well this post will give you some basic steps to setup your SQL server and Mono project to get a simple database going.
Setting SQL Express
Before we can go any further we need to have Microsoft SQL Server Express installed on a Windows server. For my own setup I already have a virtual machine with Windows Server 2012 running and SQL Server Express 2014 installed. It’s up to you to choose own setup, and it doesn’t have to be the same as mine.
Create Your SimpleDatabase
Now we need to create our test database on SQL Server by running the following SQL statement on your script editor of choice:
CREATE DATABASE SimpleDatabase

Now you should have a brand spanking new database created and ready to be populated with data. (more…)
by David Loo | May 31, 2014 | General
ChromeCast is now available in Australia for only $49 and current available at JB Hi Fi, Dick Smith and Google store. When it was released I had to buy one on the next day.
Connecting To Your TV
Connecting the device is very simple, you just plug it into one of your available HDMI ports at the back of the TV and if you have a USB port connect the USB to it so that it can power the ChromeCast. But if you don’t have a USB port on your TV you can use the power supply that came with it. I also like how it’s tucked away behind my TV so that it doesn’t use up space. (more…)
by David Loo | May 10, 2014 | jQuery, Web Development
If you are planning to use jQuery on your web page and there is already another version being used, to prevent any conflict between the two here is what you can do:
var j = jQuery.noConflict();// Do something with jQuery
j( "div p" ).hide();
// Do something with another library's $()
$( "content" ).style.display = "none";
The code above creates a new alias instead of jQuery called j and while the other library is using the $.
by David Loo | May 9, 2014 | Linux Development, Mono
Since the recent release of Ubuntu 14.04 I was surprised to see a new version of MonoDevelop, so I wanted to try creating an ASP.NET MVC 3 (Razor) project but it failed and threw the following exception:
System.IO.FileNotFoundException:Could not find file "/usr/lib/monodevelop/AddIns/MonoDevelop.AspNet.Mvc/Templates/Common/Index.cshtml".File name:'/usr/lib/monodevelop/AddIns/MonoDevelop.AspNet.Mvc/Templates/Common/Index.cshtml'
So while searching on the Internet for hours I found the following solution and hope this will solve your problem too. (more…)