Showing posts with label framework. Show all posts
Showing posts with label framework. Show all posts

Dec 9, 2013

LESS CSS - Dynamic Stylesheet



LESS is a dynamic stylesheet language.


LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions.

LESS runs on both the server-side (with Node.js and Rhino) or client-side (modern browsers only).

You can download LESS file(s) from here.


Repetition of information: In CSS, we often repeat color calues or height values in multiple places. One can eliminate these kind of issues using LESS.

Variables

Variables allow you to specify widely used values in a single place, and then re-use them throughout the style sheet, making global changes as easy as changing one line of code.

Example:

/* Compiled CSS */
#header {
  color: #4D926F;
}
h2 {
  color: #4D926F;
}

 // LESS
@color: #4D926F;

#header {
  color: @color;
}
h2 {
  color: @color;
}

Mixins


Mixins allow you to embed all the properties of a class into another class by simply including the class name as one of its properties. It’s just like variables, but for whole classes. Mixins can also behave like functions, and take arguments, as seen in the example below.

Example:

/* Compiled CSS */
#header {
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  -ms-border-radius: 5px;
  -o-border-radius: 5px;
  border-radius: 5px;
}
#footer {
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  -ms-border-radius: 10px;
  -o-border-radius: 10px;
  border-radius: 10px;
}


// LESS
.rounded-corners (@radius: 5px) {
  -webkit-border-radius: @radius;
  -moz-border-radius: @radius;
  -ms-border-radius: @radius;
  -o-border-radius: @radius;
  border-radius: @radius;
}

#header {
  .rounded-corners;
}
#footer {
  .rounded-corners(10px);
}


Functions & Operations


Are some elements in your style sheet proportional to other elements? Operations let you add, subtract, divide and multiply property values and colors, giving you the power to create complex relationships between properties. Operations should only be performed within parentheses in order to ensure compatibility with CSS. Functions map one-to-one with JavaScript code, allowing you to manipulate values however you want.

Example:

/* Compiled CSS */
#header {
  color: #333;
  border-left: 1px;
  border-right: 2px;
}
#footer {
  color: #114411;
  border-color: #7d2717;
}

// LESS
@the-border: 1px;
@base-color: #111;
@red:        #842210;

#header {
  color: (@base-color * 3);
  border-left: @the-border;
  border-right: (@the-border * 2);
}
#footer {
  color: (@base-color + #003300);
  border-color: desaturate(@red, 10%);
}

Setting up LESS in ASP.NET MVC
One can use below sample code to call LESS-CSS code.
<link content="" href="@Url.Content(" less="" mysite.less="" rel="stylesheet/less" type="text/css"></link>
<script content="" less-1.3.3.min.js="" scripts="" src="@Url.Content(" type="text/javascript"></script>

Aug 26, 2013

OWIN and Katana



OWIN defines a standard interface between .NET web servers and web applications. The goal of the OWIN interface is to decouple server and application, which makes OWIN ideal for self-hosting a web application in your own process, outside of IIS.

An OWIN-compatible Web server is responsible for populating the environment dictionary with data such as the body streams and header collections for an HTTP request and response. It is then the responsibility of the application or framework components to populate or update the dictionary with additional values and write to the response body stream.

What is the difference between OWIN/Katana?

OWIN defines the structure and requirements of HTTP request and response interactions. The assembly codifies the definitions in the spec to allow you to avoid using type aliases in all of your files.

Katana is a flexible set of components for building and hosting OWIN-based web applications. It supports the Microsoft hosts and frameworks and provides a command line tool for running OWIN applications from the command line.

You need below components: 
Microsoft.Owin.Host.HttpListener package from NuGet. 

This is supported in Visual Studio 2012 and above.

Jun 19, 2013

Fundamentals of Garbage Collection

In the common language runtime (CLR), the garbage collector serves as an automatic memory manager. It provides the following benefits:

  • Enables you to develop your application without having to free memory.
  • Allocates objects on the managed heap efficiently.
  • Reclaims objects that are no longer being used, clears their memory, and keeps the memory available for future allocations. Managed objects automatically get clean content to start with, so their constructors do not have to initialize every data field.
  • Provides memory safety by making sure that an object cannot use the content of another object.
Fundamentals of Memory
The following list summarizes important CLR memory concepts.

  • Each process has its own, separate virtual address space. All processes on the same computer share the same physical memory, and share the page file if there is one.
  • By default, on 32-bit computers, each process has a 2-GB user-mode virtual address space.
  • As an application developer, you work only with virtual address space and never manipulate physical memory directly. The garbage collector allocates and frees virtual memory for you on the managed heap.
  • If you are writing native code, you use Win32 functions to work with the virtual address space. These functions allocate and free virtual memory for you on native heaps.
  • Virtual memory can be in three states:
    • Free. The block of memory has no references to it and is available for allocation.
    • Reserved. The block of memory is available for your use and cannot be used for any other allocation request. However, you cannot store data to this memory block until it is committed.
    • Committed. The block of memory is assigned to physical storage.
  • Virtual address space can get fragmented. This means that there are free blocks, also known as holes, in the address space. When a virtual memory allocation is requested, the virtual memory manager has to find a single free block that is large enough to satisfy that allocation request. Even if you have 2 GB of free space, the allocation that requires 2 GB will be unsuccessful unless all of that space is in a single address block.
  • You can run out of memory if you run out of virtual address space to reserve or physical space to commit.

    Few important points:


  • Generations
        • The heap is organized into generations so it can handle long-lived and short-lived objects. Garbage collection primarily occurs with the reclamation of short-lived objects that typically occupy only a small part of the heap. There are three generations of objects on the heap:
        • Generation 0. This is the youngest generation and contains short-lived objects. An example of a short-lived object is a temporary variable. Garbage collection occurs most frequently in this generation.
        • Newly allocated objects form a new generation of objects and are implicitly generation 0 collections, unless they are large objects, in which case they go on the large object heap in a generation 2 collection.
        • Most objects are reclaimed for garbage collection in generation 0 and do not survive to the next generation.
        • Generation 1. This generation contains short-lived objects and serves as a buffer between short-lived objects and long-lived objects.
        • Generation 2. This generation contains long-lived objects. An example of a long-lived object is an object in a server application that contains static data that is live for the duration of the process.
      • Configuring Garbage Collection
        • You can use the element of the runtime configuration schema to specify the type of garbage collection you want the CLR to perform. When this element's enabled attribute is set to false (the default), the CLR performs workstation garbage collection. When you set the enabled attribute to true, the CLR performs server garbage collection.
        • Concurrent garbage collection is specified with the element of the runtime configuration schema. The default setting is enabled. Concurrent garbage collection is available only for workstation garbage collection and has no effect on server garbage collection.
      • Concurrent Garbage Collection
        • In workstation or server garbage collection, you can enable concurrent garbage collection, which enables threads to run concurrently with a dedicated thread that performs the garbage collection for most of the duration of the collection. This option affects only garbage collections in generation 2; generations 0 and 1 are always non-concurrent because they finish very fast.
        • Concurrent garbage collection enables interactive applications to be more responsive by minimizing pauses for a collection. Managed threads can continue to run most of the time while the concurrent garbage collection thread is running. This results in shorter pauses while a garbage collection is occurring.


      AGENT Smart Watch Emulator and managed .NET code


      A Kickstarter campaign for the Agent smartwatch kicked off today, promising to deliver a device with better battery life than its competitors and a developer-friendly environment to attract some all-important apps (it's using the .NET Micro Framework, with apps able to be written in in C# using Visual Studio 2012).


      What is AGENT Smart Watch: The next generation smartwatch with brand-new technology. World-class developer tools, unparalleled battery life, Qi wireless charging.

      What is .Net Micro Framework: The .NET Micro Framework is the smallest version of .NET for very resource-constrained devices. It offers a complete and innovative development and execution environment that brings the productivity of modern computing tools to embedded programming. Even though it’s offered under an Open Source License (Apache 2.0) it is still under active development inside Microsoft in coordination with active community contributions.

      • Easily develop powerful, interactive, and complex embedded applications.
      • Securely connect devices over wired or wireless protocols.
      • Develop reliable solutions faster at lower cost.
      • Develop the endpoints of your solution for connected devices using the same tools that are used on the servers and in the cloud.



      May 21, 2013

      JavaScript Frameworks

      Few JavaScript Frameworks:
      • Backbone.js: Provides models with key-value binding and custom events, 
      • collections, and connects it all to your existing API over a RESTful JSON interface.
      • AngularJS: A toolset based on extending the HTML vocabulary for your application.
      • Ember.js: Provides template written in the Handlebars templating language, views, controllers, models and a router.
      • Knockout: Aims to simplify JavaScript UIs by applying the Model-View-View Model (MVVM) pattern.
      • Agility.js: Aims to let developers write maintainable and reusable browser code without the verbose or infrastructural overhead found in other MVC libraries.
      • CanJS: Focuses on striking a balance between size, ease of use, safety, speed and flexibility.
      • Spine: A lightweight framework that strives to have the most friendly 
      • documentation for any JavaScript framework available.
      • Maria: Based on the original MVC flavor as it was used in Smalltalk - aka "the Gang of Four MVC".
      • ExtJS: Amongst other things offers plugin-free charting, and modern UI widgets.
      • Sammy.js: A small JavaScript framework developed to provide a basic structure for developing JavaScript applications.
      • Stapes.js: A tiny framework that aims to be easy to fit in an existing codebase, and because of its size it's suitable for mobile development.
      • Epitome: Epitome is a MVC* (MVP) framework for MooTools.
      • soma.js: Tries help developers to write loosely-coupled applications to increase scalability and maintainability.
      • PlastronJS: MVC framework for Closure Library and Closure Compiler.
      • rAppid.js: Lets you encapsulate complexity into components which can be easy used like HTML elements in your application.
      • Serenade.js: Tries to follow the ideas of classical MVC than competing frameworks.
      • Kendo UI: Combines jQuery-based widgets, an MVVM framework, themes, templates, and more.