Vincent Leung .NET Tech Clips

The latest tech clips from the .NET community

Knockout 2.0.0 released

image

Knockout is an MVVM library for JavaScript – it makes rich dynamic web UIs easier and cleaner to build. The best place to start learning is with the interactive tutorials.

January 3, 2012 Posted by | JavaScript, Knockout | Leave a Comment

Html JavaScript Development using MVVM

Shawn Wildermuth talks about using KnockoutJS framework to develop a MVVM application:

KnockoutJS is a framework that allows me to use HTML-based data binding markup to describe my UI, CSS to describe what the design looks like and JavaScript to tie the data to the data binding. The is chiefly accomplished through the concept of observable objects. For example, I created a new JavaScript ‘class’ called gameModel in my view.js by creating members using the observable method on the knockout (e.g. ko) object:

// view.js
$(document).ready(function () {

  function gameModel() {
    this.name = ko.observable();
    this.id = ko.observable();
    this.genre = ko.observable(); this.releaseDate = ko.observable();
    this.price = ko.observable();
    this.imageUrl = ko.observable();
  };
  …
});

 
The observable call returns an object that not only can store a property, but let the KnockoutJS binding stack know when the property changes (two way binding). In order to use the gameModel ‘class’, I created a view model to store a collection of gameModels like so:
 
// Define Main ViewModel
var theViewModel = {
  games: ko.observableArray([]),
  ...
};

The games property of the view models ‘class’ will hold the current list of games that are shown in the UI. The observableArray object is like the observable object but it notifies the data binding stack when a collection changes. The goal here is to have the view model load the games from the REST service and as the collection changes, the HTML should change to react to that. No more manually creating/destroying parts of the markup.

In order to make this work, we must use the data binding syntax in the HTML code:

<div data-bind="foreach: games">
  <div class="game-block">
    <div>
      <img data-bind="attr: { src: imageUrl, alt: name }" /></div>
    <div class="game-name" data-bind="text: name">
    </div>
  </div>
</div>

For more: http://wildermuth.com/2011/11/20/Using_MVVM_on_the_Web_with_KnockoutJS

December 1, 2011 Posted by | HTML5, JavaScript, Knockout, MVVM | Leave a Comment

31 Days of Refactoring

 

Refactoring is an integral part of continually improving your code while it moves forward through time. Without refactoring you accrue technical debt, forget what portions of code do and create code that is resistant to any form of testing. It is an easy concept to get started with and opens the door to much better practices such as unit testing, shared code ownership and more reliable, bug-free code in general.

Day 1 : Encapsulate Collection

Day 2 : Move Method

Day 3 : Pull Up Method

Day 4 : Push Down Method

Day 5 : Pull Up Field

Day 6 : Push Down Field

Day 7 : Rename (method, class, parameter)

Day 8 : Replace Inheritance with Delegation

Day 9 : Extract Interface

Day 10 : Extract Method

Day 11 : Switch to Strategy

Day 12 : Break Dependencies

Day 13 : Extract Method Object

Day 14 : Break Responsibilities

Day 15 : Remove Duplication

Day 16 : Encapsulate Conditional

Day 17 : Extract Superclass

Day 18 : Replace exception with conditional

Day 19 : Extract Factory Class

Day 20 : Extract Subclass

Day 21 : Collapse Hierarchy

Day 22 : Break Method

Day 23 : Introduce Parameter Object

Day 24 : Remove Arrowhead Antipattern

Day 25 : Introduce Design By Contract Checks

Day 26 : Remove Double Negative

Day 27 : Remove God Classes

Day 28 : Rename boolean methods

Day 29 : Remove Middle Man

Day 30 : Return ASAP

Day 31 : Replace Conditional with Polymorphism

You can find all of the sample code available for download here: http://github.com/schambers/days-of-refactoring/tree/master

Via 31 Days of Refactoring – Sean Chambers – Los Techies : Blogs about software and anything tech!

October 28, 2009 Posted by | C#, Language | Leave a Comment

Running IronPython Scripts from a C# 4.0 Program

 

Running IronPython Scripts from a C# 4.0 Program

Before you read this you may want to check out my other post.

IronPython is a scripting language hosted on the .NET platform. This posts shows how you can use the Dynamic Language Runtime (DLR) and the new C# 4.0 dynamic keyword to call an IronPython script from a C# program.

image

Test.py

import sys

def Simple():
    print "Hello from Python"
    print "Call Dir(): "
    print dir()
    print "Print the Path: " 
    print sys.path

 

using System;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;

public class dynamic_demo
{
    static void Main()
    {
        var ipy = Python.CreateRuntime();
        dynamic test = ipy.UseFile("Test.py");
        test.Simple();
    }
}

image

Via Charlie Calvert’s Community Blog : Running IronPython Scripts from a C# 4.0 Program

October 27, 2009 Posted by | .NET 4, Python | Leave a Comment

Getting Started with IronPython

 image

I recently spent some time getting IronPython up and running on my system; I will review what I learned in this post.

IronPython can be hosted inside a C# program as a scripting language. Nonetheless, Python is a powerful standalone language frequently used as the glue in web based applications. In this post Charlie explore the simple steps needed to run IronPython as a standalone tool from the command prompt. In other posts coming up he will show how to call Python from inside a C# application.

Via Charlie Calvert’s Community Blog : Getting Started with IronPython

October 26, 2009 Posted by | Language | 1 Comment

Using the Microsoft Ajax Minifier to reduce the size of any JavaScript file

 

The Microsoft Ajax Minifier enables you to reduce the size of a JavaScript file by removing unnecessary content from the JavaScript file. The tool supports two modes: normal crunching and hypercrunching.

When you use normal crunching, the Microsoft Ajax Minifier strips all comments, unnecessary whitespace, curly-braces, and semicolons from a JavaScript file. Surprisingly, just removing all of this unnecessary code fluff can make a significant difference to the size of a JavaScript file.

When you use hypercrunching, the Microsoft Ajax Minifer gets more aggressive about reducing the size of a JavaScript file. In hpercrunching mode, the Microsoft Ajax Minifier shortens the names of local variables (variables in functions but not global variables) and it removes unreachable code.

The article also shows how to use the Microsoft Ajax Minifier from the Command-Line and how to integrate the Microsoft Ajax Minifier directly into the Visual Studio build process.

Using the New Microsoft Ajax Minifier

October 17, 2009 Posted by | JavaScript | Leave a Comment

Functional Programming for Everyday .NET Development

 Jeremy Miller

In this article we will examine in particular how the new support for functional programming techniques in .NET 3.5 can help you do the following:

  1. Make your code more declarative.
  2. Reduce errors in code.
  3. Write fewer lines of code for many common tasks.

The Language Integrated Query (LINQ) feature in all of its many incarnations is an obvious and powerful use of functional programming in .NET, but that’s just the tip of the iceberg.

For more visit Functional Programming for Everyday .NET Development

October 2, 2009 Posted by | C#, Language | Leave a Comment

What is the difference between a.Equals(b) and a == b?

Value Types:
For value types, “==” and Equals() works same way : Compare two objects by VALUE
Example:
int i = 5;
int k= 5;
i == k > True
i.Equals(k) > True

Reference Types:
For reference types, both works differently :
“==” compares REFERENCE – returns true if and only if both references point to the SAME object.

Equals method compares object by VALUE.

Example:
StringBuilder sb1 = new StringBuilder(”Mahesh”);
StringBuilder sb2 = new StringBuilder(”Mahesh”);
sb1 == sb2 > False
sb1.Equals(sb2) > True

However

String s1 = “zzz”;
String s2 = “zzz”;
In above case the results will be,
s1 == s2 > True
s1.Equals(s2) > True

Why? Does that mean String a Value Type?

No, String IS a Reference Type. Although string is a reference type, the equality operators (== and !=) are defined to compare the values of string objects, not references. This makes testing for string equality more intuitive. For example:

September 28, 2009 Posted by | .NET, C# | 1 Comment

Small Basic

 

SmallBasic

Small Basic is a project that’s aimed at bringing “fun” back to programming. By providing a small and easy to learn programming language in a friendly and inviting development environment, Small Basic makes programming a breeze. Ideal for kids and adults alike, Small Basic helps beginners take the first step into the wonderful world of programming.

  • Small Basic derives its inspiration from the original BASIC programming language, and is based on the Microsoft .Net platform. It is really small with just 15 keywords and uses minimal concepts to keep the barrier to entry as low as possible.
  • The Small Basic development environment is simple, yet provides powerful modern environment features like Intellisense™ and instant context sensitive help.
  • Small Basic allows third-party libraries to be plugged in with ease, making it possible for the community to extend the experience in fun and interesting ways.

Getting Started Guide

Forums

FAQ

Small Basic Blog

Samples

Microsoft Small Basic aims to make computer programming accessible to beginners.

Download

Getting Started

  1. Download and install Small Basic
  2. Follow the Getting Started guide (docx or pdf) to build your first application

December 13, 2008 Posted by | Hobbies, Language | Leave a Comment

DHTML JavaScript Tooltips, Balloon Library

 

JavaScript, DHTML Tooltips/Bubble/Popup Balloon
JavaScript Cross Browser Library.

Developed by Walter Zorn

Via DHTML JavaScript Tooltips

August 13, 2008 Posted by | JavaScript | Leave a Comment

Follow

Get every new post delivered to your Inbox.