Thursday, November 17, 2016

DETECT SHAKE USING JAVASCRIPT

DETECT SHAKE USING JAVASCRIPT

 <!doctype html>  
 <html>  
      <head>  
           <style type="text/css">  
                #box  
                {  
                     width: 300px;  
                     height: 300px;  
                }  
                               #carbonads {   
                  max-width: 300px;   
                  background: #f8f8f8;  
                }  
                .carbon-text {   
                  display: block;   
                  width: 130px;   
                }  
                .carbon-poweredby {   
                  float: right;   
                }  
                .carbon-text {  
                  padding: 8px 0;   
                }  
                #carbonads {   
                  padding: 15px;  
                  border: 1px solid #ccc;   
                }  
                .carbon-text {  
                  font-size: 12px;  
                  color: #333333;  
                  text-decoration: none;  
                }  
                .carbon-poweredby {  
                  font-size: 75%;  
                  text-decoration: none;  
                }  
                #carbonads {   
                  position: fixed;   
                  top: 5px;  
                  right: 5px;  
                }  
           </style>  
           <script type="text/javascript" src="https://cdn.rawgit.com/alexgibson/shake.js/master/shake.js"></script>  
           <script type="text/javascript">  
                function getRandomInt(min, max) {  
                 return Math.floor(Math.random() * (max - min + 1)) + min;  
                }  
                var shakeEvent = new Shake({threshold: 15});  
                shakeEvent.start();  
                window.addEventListener('shake', function(){  
                     var element = document.getElementById("box");  
                  var r = getRandomInt(0, 255);  
                  var g = getRandomInt(0, 255);  
                  var b = getRandomInt(0, 255);  
                  element.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";  
                }, false);  
                //stop listening  
                function stopShake(){  
                     shakeEvent.stop();  
                }  
                if(!("ondevicemotion" in window)){alert("Not Supported");}  
           </script>  
      </head>  
      <body>  
           Shake to change color of the box  
           <div id="box"></div>  
           <script type="text/javascript">  
                var element = document.getElementById("box");  
                var r = getRandomInt(0, 255);  
                var g = getRandomInt(0, 255);  
                var b = getRandomInt(0, 255);  
             element.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";  
           </script>  
           <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=qnimate" id="_carbonads_js"></script>  
      </body>  
 </html>  

Monday, November 14, 2016

PIVOT and UNPIVOT Table Examples - Sql Server

 PIVOT and UNPIVOT Table Examples - Sql Server


 USE AdventureWorks  
 GO  
 -- Creating Test Table  
 CREATE TABLE Product(Cust VARCHAR(25), Product VARCHAR(20), QTY INT)  
 GO  
 -- Inserting Data into Table  
 INSERT INTO Product(Cust, Product, QTY)  
 VALUES('KATE','VEG',2)  
 INSERT INTO Product(Cust, Product, QTY)  
 VALUES('KATE','SODA',6)  
 INSERT INTO Product(Cust, Product, QTY)  
 VALUES('KATE','MILK',1)  
 INSERT INTO Product(Cust, Product, QTY)  
 VALUES('KATE','BEER',12)  
 INSERT INTO Product(Cust, Product, QTY)  
 VALUES('FRED','MILK',3)  
 INSERT INTO Product(Cust, Product, QTY)  
 VALUES('FRED','BEER',24)  
 INSERT INTO Product(Cust, Product, QTY)  
 VALUES('KATE','VEG',3)  
 GO  

-- Selecting and checking entires in table

SELECT * FROM Product GO -- Pivot Table ordered by PRODUCT SELECT PRODUCT, FRED, KATE FROM ( SELECT CUST, PRODUCT, QTY FROM Product) up PIVOT (SUM(QTY) FOR CUST IN (FRED, KATE)) AS pvt ORDER BY PRODUCT GO -- Pivot Table ordered by CUST SELECT CUST, VEG, SODA, MILK, BEER, CHIPS FROM ( SELECT CUST, PRODUCT, QTY FROM Product) up PIVOT (SUM(QTY) FOR PRODUCT IN (VEG, SODA, MILK, BEER, CHIPS)) AS pvt ORDER BY CUST GO

-- Unpivot Table ordered by CUST

SELECT CUST, PRODUCT, QTY FROM ( SELECT CUST, VEG, SODA, MILK, BEER, CHIPS FROM ( SELECT CUST, PRODUCT, QTY FROM Product) up PIVOT ( SUM(QTY) FOR PRODUCT IN (VEG, SODA, MILK, BEER, CHIPS)) AS pvt) p UNPIVOT (QTY FOR PRODUCT IN (VEG, SODA, MILK, BEER, CHIPS) ) AS Unpvt GO -- Clean up database DROP TABLE Product GO

ResultSet: -- Selecting and checking entires in table

Cust Product QTY ------------------------- -------------------- ----------- KATE VEG 2 KATE SODA 6 KATE MILK 1 KATE BEER 12 FRED MILK 3 FRED BEER 24 KATE VEG 3

-- Pivot Table ordered by PRODUCT


 PRODUCT FRED KATE  
 -------------------- ----------- -----------  
 BEER 24 12  
 MILK 3 1  
 SODA NULL 6  
 VEG NULL 5  

-- Pivot Table ordered by CUST

CUST VEG SODA MILK BEER CHIPS ------------------------- ----------- ----------- ----------- ----------- ----------- FRED NULL NULL 3 24 NULL KATE 5 6 1 12 NULL

-- Unpivot Table ordered by CUST

CUST PRODUCT QTY ------------------------- -------- ----------- FRED MILK 3 FRED BEER 24 KATE VEG 5 KATE SODA 6 KATE MILK 1 KATE BEER 12 12

Friday, November 11, 2016

CSS Layout - The position Property

The position property specifies the type of positioning method used for an element (static, relative, fixed or absolute).

The position Property

The position property specifies the type of positioning method used for an element.
There are four different position values:
  • static
  • relative
  • fixed
  • absolute
Elements are then positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the position value.

position: static;

HTML elements are positioned static by default.
Static positioned elements are not affected by the top, bottom, left, and right properties.
An element with position: static; is not positioned in any special way; it is always positioned according to the normal flow of the page:
This
element has position: static;
Here is the CSS that is used:

Example

div.static {
    position: static;
    border: 3px solid #73AD21;
}

position: relative;

An element with position: relative; is positioned relative to its normal position.
Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element.
This
element has position: relative;
Here is the CSS that is used:

Example

div.relative {
    position: relative;
    left: 30px;
    border: 3px solid #73AD21;
}

position: fixed;

An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element.
A fixed element does not leave a gap in the page where it would normally have been located.
Notice the fixed element in the lower-right corner of the page. Here is the CSS that is used:

Example

div.fixed {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 300px;
    border: 3px solid #73AD21;
}
This
element has position: fixed;

position: absolute;

An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed).
However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.
Note: A "positioned" element is one whose position is anything except static.
Here is a simple example:
This
element has position: relative;
This
element has position: absolute;
Here is the CSS that is used:

Example

div.relative {
    position: relative;
    width: 400px;
    height: 200px;
    border: 3px solid #73AD21;
} 

div.absolute {
    position: absolute;
    top: 80px;
    right: 0;
    width: 200px;
    height: 100px;
    border: 3px solid #73AD21;
}

Thursday, November 10, 2016

SQL ORDER BY

The ORDER BY keyword is used to sort the result-set.

The SQL ORDER BY Keyword

The ORDER BY keyword is used to sort the result-set by one or more columns.
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in a descending order, you can use the DESC keyword.

SQL ORDER BY Syntax

SELECT column_name, column_name
FROM table_name
ORDER BY column_name ASC|DESC, column_name ASC|DESC;

Wednesday, November 9, 2016

The GROUP BY Statement in Sql

The GROUP BY Statement

The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.

SQL GROUP BY Syntax

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;

Create Store Procedure in Sql Server

Other benefits include
1. Create once and call it N number of times
2. Reduce traffic since instead of whole query only stored procedure name is sent from front end
3. You can give selected users right to execute a particular stored procedure.

Create Procedure

Example

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE GetEmployeeDetails
      @EmployeeID int = 0
AS
BEGIN
      SET NOCOUNT ON;
      SELECT FirstName, LastName, BirthDate, City, Country
      FROM Employees WHERE EmployeeID=@EmployeeID
END
GO


Execute the Procedure

exec Procedure name



Alter or Modify a Stored Procedure

To modify a stored procedure ALTER keyword is used rest all remains the same.

Example
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE GetEmployeeDetails
      @EmployeeID int = 0
AS
BEGIN
      SET NOCOUNT ON;
      SELECT FirstName, LastName, BirthDate, City, Country
      FROM Employees WHERE EmployeeID=@EmployeeID
END
GO

Drop or Delete a Stored Procedure
 DROP keyword is used proceeded by the name of the stored procedure.

Example
DROP PROCEDURE GetEmployeeDetails

Tuesday, November 8, 2016

How Many Foreign Key Can You Have on A Single Table?

Answer: SQL Server 2014 and earlier versions, supports 253 as a maximum foreign key table references per table. However, this limitation, changes in SQL Server 2016.