Thursday 23 May 2013

Working with Knockout.js


Knockout(KO) is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model. KO provides a simple two-way data binding mechanism between your data model and UI means any changes to data model are automatically reflected in the DOM (UI) and any changes to the DOM are automatically reflected to the data model.

Since Knockout is a purely client-side library, it has the flexibility to work with any server-side technology (e.g., ASP.NET, Rails, PHP, etc.), and any architectural pattern, database, whatever. As long as your server-side code can send and receive JSON data — a trivial task for any half-decent web technology

Key Concepts:
  • Declarative Bindings - Easily associate DOM elements with model data using a concise, readable syntax.
  • Automatic UI Refresh - When your data model's state changes, your UI updates automatically.
  • Dependency Tracking - Implicitly set up chains of relationships between model data, to transform and combine it.
  • TemplatingQuickly generate sophisticated, nested UIs as a function of your model data.

Additional benefits:
  • Declarative Bindings - Pure JavaScript library - works with any server or client-side technology.
  • Can be added on top of your existing web application without requiring major architectural changes.
  • Comprehensive suite of specifications (developed BDD-style) means its correct functioning can easily be verified on new browsers and platforms.
More Features:
  • Free, open source.
  • Pure JavaScript — works with any web framework
  • Small & lightweight — 40kb minified. (... reduces to 14kb when using HTTP compression)
  • No dependencies
  • Supports all mainstream browsers
    IE 6+, Firefox 2+, Chrome, Opera, Safari (desktop/mobile)

Knockout.js uses a Model-View-ViewModel (MVVM) design pattern in which the model is your stored data, and the view is the visual representation of that data (UI) and ViewModel acts as the intermediary between the model and the view.

                                         Model   <---------> View Model <---------> View

ViewModel is a JavaScript representation of the model data, along with associated functions for manipulating the data. Knockout.js creates a direct connection between the ViewModel and the view, which helps to detect changes to the underlying model and automatically update the right element of the UI.

Simple Example

1. View(HTML)
<h2>Your Seat reservations</h2>
<table>
    <thead><tr>
        <th>Passenger name</th><th>Meal</th><th>Surcharge</th><th></th>
    </tr></thead>
    <tbody data-bind="foreach: seats">
    <tr>
        <td data-bind="text: name"></td>
        <td data-bind="text: meal().mealName"></td>
        <td data-bind="text: meal().price"></td>
    </tr> 
</tbody>
</table>

2. View Model(Javascript)
// Class to represent a row in the seat reservations grid
function SeatReservation(name, initialMeal) {
    var self = this;
    self.name = name;
    self.meal = ko.observable(initialMeal);
}
// Overall viewmodel for this screen, along with initial state
function ReservationsViewModel() {
    var self = this;
    // Non-editable catalog data - would come from the server
    self.availableMeals = [
        { mealName: "Standard (sandwich)", price: 10.11 },
        { mealName: "Premium (lobster)", price: 34.95 },
        { mealName: "Ultimate (whole zebra)", price: 290 }
    ]; 

    // Editable data
    self.seats = ko.observableArray([
        new SeatReservation("Steve", self.availableMeals[0]),
        new SeatReservation("Bert", self.availableMeals[1])
    ]);
}

ko.applyBindings(new ReservationsViewModel());

3. OUTPUT

Wednesday 15 May 2013

SQL Query to find starting and ending date of every week in a month


DECLARE @iloop int
DECLARE @Tot_Weeks Int
DROP TABLE #Weeks
CREATE TABLE #Weeks(Weekno int identity(1,1),[Start Of Week] date, [End Of Week] date )
---Input the date Here
declare @dt date = cast('2013-06-01' as date);
declare @dtstart date =  DATEADD(day, -DATEPART(day, @dt) + 1, @dt);
declare @dtend date = dateadd(DAY, -1, DATEADD(MONTH, 1, @dtstart));
--Find the Total Number of Weeks
SELECT @Tot_Weeks = DATEDIFF (week, DATEADD (m, DATEDIFF (m, 0, @dtend), 0), @dtend) + 1
Set @iloop = 0
WHILE (@iloop < @Tot_Weeks)
BEGIn
PRINT @iloop
If(@iloop = 0)
Begin
INSERT INTO #Weeks
SELECT @dtstart as [Start Of Week] , Cast( DATEADD(s,-1,DATEADD(WK, DATEDIFF(WK,0,CAST(@dtstart AS DATE))+1,0))-1 as DATE) as [End Of Week]
End
ELSE IF(@iloop = (@Tot_Weeks-1))
BEGIN
INSERT INTO #Weeks
SELECT  Cast( DATEADD(WK, DATEDIFF(WK,0,CAST(@dtstart AS DATE)),-1) as Date) as [Start Of Week] ,  @dtend as [End Of Week]
END
Else
Begin
INSERT INTO #Weeks
SELECT  Cast(DATEADD(WK, DATEDIFF(WK,0,CAST(@dtstart AS DATE)),-1) as Date) as [Start Of Week] , Cast( DATEADD(s,-1,DATEADD(WK, DATEDIFF(WK,0,CAST(@dtstart AS DATE))+1,0))-1 as DATE) as [End Of Week]
End
Set @dtstart = DATEADD(DD,7,CAST(@dtstart AS DATE))
Print @dtstart
SET @iloop = @iloop + 1
END

Select * from #Weeks

Monday 6 May 2013

What is .Net ?


What is .Net 

.Net is a software development platform developed by Microsoft. It is developed by microsoft to compete Java in the market. Using .net there is no need to learn new programming language. It supports 48 programming languages like as C, C++, C#, J#, VB etc. Hence we can do programming in any programming language in which you feel comfortable to yourself. Infact .Net is a collection of :
  1. .Net products :

    Visual Studio 2001, 2003, 2005, 2008, 2010, 2012
  2. .Net Service :

    Webservices, Window comunication foundation (WCF), Web API
  3. .Net framework :

    Integrated development environment (IDE), Software development kit (SDK)

.Net versions released

  1. 1.0 released on 13 feb 2002.
  2. 1.1 released in apr 2003.
  3. 2.0 released on 7 nov 2005.
  4. 3.0 released on 6 nov 2006.
  5. 3.5 released on 19 nov 2007.
  6. 4.0 released on 12 apr 2010.
  7. 4.5 released on 15 aug 2012.

Platform support

  1. .Net framework runs on Window Xp, Window 2000, NT4, ME/98, SP6a, Vista, Window 7 & 8, Window Server 2003, 2008 & 2012
  2. Window 95 is not supported.
  3. Window 98/ME can't be used for development.

.Net Framework

.Net framework is a tool of .Net platform for building, deploying and running webservices, web applications and window applications. Mazor elements of .Net framework are CLR (common language runtime), FCL(framework class library), webservices, window & webforms/applications.

Features of .Net framework

  1. It is a layer between operating system(OS) and programming language.
  2. It supports many programming languages.
  3. .Net provides a common set of class library which can be accessed from any .Net based programming language.      

Friday 3 May 2013

Shortcut Key in SQL Server Management Studio



Shortcut Key in Sql Server Management Studio

Launching SSMS

START -> Run or press Windows + R, type ssms and click OK (or hit ENTER) which will launch SSMS.
You can also specify different parameters or switches
  • The -E switch will let you connect to the local instance using Windows authentication.
  • The -U switch is used to specify a user and -P to specify the password
  • If you want SSMS to connect to a specific database you can use the -d switch
  • If you want a script file to be opened in SSMS you can specify the location and name of the file. This will just open the file in SSMS and will not execute the code. If you need to execute a script file you can use the SQLCMD utility.
  • To close SSMS you can use ALT+F4.

You can simply open the SSMS or you can specify the -E switch to open SSMS and connect using Windows authentication. If the current user does not have sufficient permissions obviously it will fail.

When we open SSMS a splash screen appears while loading SSMS in the memory. You can specify -nosplash switch which opens SSMS without the splash screen.

You can use -? which gives you the different command options as shown below. 


Table Details

            If you select a table name in the query window of Sql Server Management Studio
and press ALT + F1 it will display the details of that table.

In the background shortcut key will execute sp_help on your behalf, so in this example it executes: sp_help users, which is much quicker than typing it.


Otherwise you can also use sp_columns test_tbl


Changing Databases

Once you are in a Query Window in SSMS you can use CTRL+U to change the database. When you press this combination, the database combo-box will be selected as shown below. You can then use the UP and DOWN arrow keys to change between databases (or type a character to jump to databases starting with that character) select your database and hit ENTER to return back to the Query Window.


Changing Code Case (Upper or Lower)

When you are writing code you may not bother with using upper or lower case to make your code easier to read. To fix this later, you can select the specific text and hit CTRL+SHIFT+U to make it upper case or use CTRL+SHIFT+L to make it lower case as shown below.


Commenting Out Code

When writing code sometimes you need to comment out lines of code. You can select specific lines and hit CTRL+K followed by CTRL+C to comment it out and CTRL+K followed by CTRL+U to uncomment it out as shown below.

 Indenting Code

As a coding best practice you should to indent your code for better readability. To increase the indent, select the lines of code (to be indented) and hit TAB as many times as you want to increase the indent likewise to decrease the indent again select those lines of code and hit SHIFT+TAB.


There are many shortcut keys that are listed below.

Action
SSMS-Shortcut Key
Display the Query Designer
CTRL+SHIFT+Q
Close a menu or dialog box, canceling the action
ESC
Cancel a query
ALT+BREAK
Connect
CTRL+O
Disconnect
CTRL+F4
Disconnect and close child window
ALT+F4
Database object information
ALT+F1
Go to a line number
CTRL+G
Remove comments
CTRL+SHIFT+R
Execute a query
F5 or Ctrl + E
New Query window
CTRL+N
Object Browser (show/hide)
F8
Parse the query and check syntax
CTRL+F5
Display results in grid format
CTRL+D
Display results in text format
CTRL+T
Use database
CTRL+U

Wednesday 1 May 2013

HTML Codes for Punctuation and Other Characters

HTML codes to put punctuation characters on your Web page

The following list includes the HTML codes for punctuation characters not in the standard character set. Not all browsers support all the codes, so be sure to test your HTML codes before you use them.
Some punctuation characters are part of the Unicode character set, so you need to declare that in the head of your documents:
<meta http-equiv="content-type" content="text/html;charset=utf-8" />

Display Friendly Code Numerical Code Hex Code Description
&#09; &#x09; Horizontal Tab
&#10; &#x10; Line Feed
&#32; &#x20; Space
! ! &#33; &#x21; Exclamation Point
" &quot; &#34; &#x22; Double Quote
# # &#35; &#x23; Number Sign
& &amp; &#38; &#x26; Ampersand
' ' &#39; &#x27; Single Quote
( ( &#40; &#x28; Left Parenthesis
) ) &#41; &#x29; Right Parenthesis
* * &#42; &#x2A; Asterisk (Star)
, , &#44; &#x2C; Comma
- - &#45; &#x2D; Hyphen
. . &#46; &#x2E; Period
/ / &#47; &#x2F; Forward Slash
: : &#58; &#x3A; Colon
; ; &#59; &#x3B; Semi-Colon
? ? &#63; &#x3F; Question Mark
@ @ &#64; &#x40; At Sign
[ [ &#91; &#x5B; Left Square Bracket
\ \ &#92; &#x5C; Back Slash
] ] &#93; &#x5D; Right Square Bracket
^ ^ &#94; &#x5E; Caret
_ _ &#95; &#x5F; Underscore
{ { &#123; &#x7B; Left Curly Brace
| | &#124; &#x7C; Vertical Bar
} } &#125; &#x7D; Right Curly Brace
~ &tilde; &#126; &#x7E; Vertical Bar
&sbquo; &#130; &#x82; Single Low Quote
&dbquo; &#132; &#x84; Double Low Quote
&#133; &#x85; Elipsis
&dagger; &#134; &#x86; Dagger
&Dagger; &#135; &#x87; Double Dagger
&lsaquo; &#139; &#x8B; Left Single Angle Quote
&lsquo; &#145; &#x91; Left Single Quote
&rsquo; &#146; &#x92; Right Single Quote
&ldquo; &#147; &#x93; Left Double Quote
&rdquo; &#148; &#x94; Right Double Quote
&#149; &#x95; Small Bullet
&ndash; &#150; &#x96; En Dash
&mdash; &#151; &#x97; Em Dash
&trade; &#153; &#x99; Trademark
&rsaquo; &#155; &#x9B; Right Single Angle Quote
&nbsp; &#160; &#xA0; Non-Breaking Space
¡ &iexcl; &#161; &#xA1; Inverted Exclamation Point
¦ &brvbar; &#166; &#xA6; Broken Vertical Bar
© &copy; &#169; &#xA9; Copyright
ª &ordf; &#170; &#xAA; Feminine Ordinal Indicator
« &laquo; &#171; &#xAB; Left Angle Quote
¬ &not; &#172; &#xAC; Not Sign
­ &shy; &#173; &#xAD; Soft Hyphen
® &reg; &#174; &#xAE; Registered Symbol
° &deg; &#176; &#xB0; Degree
² &sup2; &#178; &#xB2; Superscript 2
³ &sup3; &#179; &#xB3; Superscript 3
µ &micro; &#181; &#xB5; Micro Sign
&para; &#182; &#xB6; Pilcrow (Paragraph Sign)
· &middot; &#183; &#xB7; Middle Dot
¹ &sup1; &#185; &#xB9; Superscript 1
º &ordm; &#186; &#xBA; Masculine Ordinal Indicator
» &raquo; &#187; &#xBB; Right Angle Quote
¿ &iquest; &#191; &#xBF; Inverted Question Mark
&#8453; &#x2105; Care Of
&#8319; &#x207F; Superscript N
§ &sect; &#167; &#xA7; Section Mark
¨ &iquest; &#191; &#xBF; Inverted Question Mark
&#8213; &#x2015; Horizontal Bar
&#8227; &#x2023; Triangle Bullet
&oline; &#8254; &#x203E; Overline
&#8252; &#x203C; Double Exclamation Point
&#8470; &#x2116; Number Word

Other Character Codes

Note: not all of these characters will display on every browser, be sure to test before you rely on them for your Web site.

Display Friendly Code Numerical Code Hex Code Description
&spades; &#9824; &#x2660; Spade card suit
&clubs; &#9827; &#x2663; Clubs card suit
&diams; &#9830; &#x2666; Diamonds card suit
&hearts; &#9829; &#x2665; Hearts card suit
&larr; &#8592; &#x2190; Left arrow
&rarr; &#8594; &#x2192; Right arrow
&uarr; &#8593; &#x2191; Up arrow
&darr; &#8595; &#x2193; Down arrow
&#9792; &#x2640; Female Indicator
&#9794; &#x2642; Male Indicator
&#9833; &#x2669; Quarter Note
&#9834; &#x266A; Eighth Note
&#9836; &#x266C; Two Eighth Notes
&#9837; &#x266D; Flat
&#9839; &#x266F; Sharp