Monday, December 16, 2013

How to play guitar: Day 10

Follow for complete tutorial

How to read the tab: 
Read from left to right and numbers indicate fret number.

Guitar tab for DDLJ:
e ----------7-5-7-3-5-8-7
B 5-5—5
Tujhe dekha toh yeh jana sanam

e —------7-5-7-3-5
B 5-5—5------------8-7
Pyar hota hai dewana sanam

Ab yaha se kahan jaye hum

B 5-7-3-5-7-3--------5
Tere baho mein mar jaye hum


Sunday, December 8, 2013

How to learn guitar: Day 9

Follow for complete tutorial

Notes on fifth and sixth string:

Fifth string: A, B, C

Sixth string: E, F, G

Play all the strings:


How to learn guitar: Day 7 - 8

Complete rest of basic theory:

Rest duration:
Dots and ties:
Steps and accidents:

Notes on fourth string: D, E, F

Play Kal ho na ho:

How to learn guitar: Day 6

Notes on third string: G, A

Play happy birth day:

How to learn guitar: Day 4 - 5

Follow for complete tutorial

Play your first song using following notes:

Jingle Bells:

How to learn guitar: Day 2 - 3

Start with the theory:

The staff, Cleff and Ledger lines:
Note duration:
Measures and time signatures:

Learn basic notes on strings:


Start with basic caterpillar:
1. Press first four frets in E string and play guitar
2. Continue the same with other strings

Make a practice to start with caterpillar everyday. Once you are master in this caterpillar choose different one.

By this time you should be aware of notes, staff, clefs, note duration and playing basic caterpillar.

Following figure can help you remember notes on staff:

Notes on first string (E string): E, F, G

Notes on second string (B string): B, C, D

Play notes on first and second string by looking following notes:

How to learn guitar: Day 1

Follow for complete tutorial

Day 1 - learn parts of guitar and how to hold the guitar: 

We need to first learn how to hold guitar as it's very important.

We want to see the frets all the time so guitar should be slightly angled.
After holding guitar just go through parts of guitar.

You want to also learn how to hold pick.

Try pressing any fret and play guitar.
I know your guitar is not sounding great but, it will.

Saturday, December 7, 2013

AngularJS: Basics

Single Page Application (SPA): SPA application is like Silverlight application, where all the pages are loaded at the beginning and later allow the users to navigate between the pages without calling the server.
SPA application loads all the pages on the client's browser at the beginning and use JavaScript in order to switch between the pages making parts of HTML visible and invisible depending on which page is chosen. It reduces the server round trip and makes application faster.
e.g. - It's a single page application created using AngularJS - It is also a single page application created using AngularJS

Challenges with SPAs:
  • DOM Manipulation
  • History
  • Module loading
  • Routing
  • Caching
  • Object modelling
  • Data Binding
  • Ajax/ Promises
  • View loading
Angular is full-featured SPA framework. It provides following features:
  • Data binding
  • MVC
  • Routing
  • Testing
  • jqLite - similar to JQuery
  • Templates
  • History
  • Factories

Core features:
Dependency Injection

Directives: Directives in AngularJS are used to make custom HTML elements and simplify DOM manipulation. let you structure your views. They can modify the behaviour of new and existing DOM elements, by adding custom functionality, like a datepicker or an autocomplete widget.
In short, Directives provides HTML tricks. All built in directives start with ng-. However, we can start with data-ng- as it's easier for validation.

ng-app: Use this directive to auto-bootstrap an AngularJS application (add this in html or body).
ng-model: The ngModel directive binds an input,select, textarea (or custom form control) to a property on the scope.
ng-init: Initialize the data.
ng-repeat: iterate for each element as per collection collection.
There are different filter, which apply different filtering operation.

Example:  filter, orderBy, lowercase and uppercase, json - converts javascript object to JSON, date, currency

MVC in AngularJS:
View does not contain logic. Logic are contained in Controllers and manages the data. The glue between View and Controllers is scope ($scope).
We can create SimpleController function and glue with view with help of scope. the we can access object and properties of Controller in view.
Modules, Route and factories:
Module -> Config -> Routes -> View  <--> Controllers
Controllers -> Factory
View -> Directives
Modules are containers, where we can create Config -> Routes, Filter, Directive, Factory -> Service -> Provider -> value, Controller.
It is defined using ng-app = "moduleName". angular object gives access to module function where you can refer other module.
var  demoApp = angular.module('demoApp', ['helperModule']);
We can create controllers in module using demoApp.
demoApp.controllers('ControllersName', function($scope) {} );

Routes: We need to load different views in SPAs. View could be embedded as script in actual shell page and we can load view using template id.
Second way is to backup on the server you might actually have all these views and I like to call them partials because they are part of page. We can create config and give a route ($routeProvider). We can define which Controller to load for which view. We need not to add code for Controllers in each page.
We can also add place holders using ng-view in page. Angular automatically manages history.

Factory: Once we define factory, we can inject as a parameter in Controller function and use the object returned in Factory. We can have different factory in application. It can return something using AJAX call and we can use it in controllers.
We can inject $http object in Factory to access REST API's.
Factory, Service and Provider have different way to return the data.


Sunday, May 26, 2013

SQL and MDX Performance Tips

Improving performance is key skill for a database developer. So, every database developer should have check few key points to improve the query.

I mentioning some of them below. Please add in comments if there are any you know.

SQL Performance Tips:

1. Include SET NOCOUNT ON statement

2. Use schema name with object name - reduces searching time of objects

3. Use IF EXISTS (SELECT 1) instead of IF EXISTS (SELECT *):

4. Use the sp_executesql stored procedure instead of the EXECUTE statement: The sp_executesql stored procedure supports parameters. So, using the sp_executesql stored procedure instead of the EXECUTE statement improve the re-usability of your code

5. Use TRY-Catch for error handling

6.  Avoid using <> as a comparison operator

7. Avoid using dynamic SQL statements if you can write T-SQL code without using them

8. Minimize the use of Nulls because they incur more complexity in queries and updates. ISNULL and COALESCE functions are helpful in dealing with NULL values

9. Following priority order should be followed when any index is created a) WHERE clause, b) JOIN clause, c) ORDER BY clause, d) SELECT clause

10. Try to use UNION to implement an "OR" operation. Better use UNION ALL if a distinguished result is not required

11. Using JOIN is better for performance then using sub queries or nested queries.

MDX Performance Tips:

1.       Use Sub cube instead of WHERE clause

2.       Use NON EMPTY where ever possible

3.       While calculating a measure, use “NULL” instead of “0”. This allows NON EMPTY to work and makes calculation faster

IIF([Measures].[B] = 0, null, [Measures].[A] / [Measures].[B] )

4.       Create a calculated SET to reuse in query

5.       Sparse sets first in cross joins before dense sets

6.       Filter a set before using it in a cross join to reduce the cube space before performing the cross join

7.       Use IS operator while comparing levels/ members

8.       Use Exists functions for filtering to enable the query execution engine to use bulk evaluation mode

9.       Avoid unnecessary calculations like checking for null in IIF condition

10.    Rewrite MDX queries containing arbitrary shapes to reduce excessive sub queries where possible

Sunday, April 21, 2013

MDX Tricks: Part 1

Non Empty v/s NonEmpty:

Non Empty:

This will return all the columns which are not null for all the tuples of rows axis:

, { 
  } ON ROWS 
FROM [Cube];

This will return all the rows which are not null for all the tuples of column axis:

  } ON ROWS 
FROM [Cube];

Non Empty:

returns the set of tuples that are not empty from a specified set,

  } ON ROWS 
FROM [Cube];

As you can see, the NonEmpty operator takes all the rows having a not NULL value for Subscribers in the rows 

and then displays all the measures defined in the column axis. Basically what happens internally is that 

NonEmpty is evaluated when the sets defining the axis are evaluated. So at this point of time, there is no 

context of the other axes.

  {[Date].[Month].[March]} ON COLUMNS 
  } ON ROWS 
FROM [Blog Statistics] 

NonEmpty is evaluated when the set defining the axis is evaluated (here, Country) and at that point of time, 

NonEmpty is evaluated for each member of the country against the default member of the Date dimension 

(which would be ALL generally). 

Use NonEMPTY before filtering the rows to improve the performance as shown below:

  {[Measures].[Hits]} ON COLUMNS 
      [Measures].[Hits] > 30 
  } ON ROWS 
FROM [Blog Statistics];

Wednesday, March 13, 2013

Operators in SQL Server

Scope Resolution Operator: 
The scope resolution operator :: provides access to static members of a compound data type.
A compound data type is one that contains multiple simple data types and methods.

DECLARE @hid hierarchyid;
SELECT @hid = hierarchyid::GetRoot();
PRINT @hid.ToString();

Result: /

Bitwise Operators:

DECLARE @a int;
SET @a = 10 & 20
print @a

SET @a = 10 ^ 20
print @a

SET @a = 10 | 20

print @a


Binary Representation of 10, 20:

10 = 01010
20 = 10100

01010 & 10100 = 00000 = 0
01010 ^ 10100 = 11110 = 30
01010 | 10100 = 11110 = 30


Concatenating two strings:

SELECT 'FirstName' + ' ' + 'LastName' AS FullName


SELECT FirstName + ' ' + LastName
FROM Person.Person

% - Matches any string of zero or more characters. This wildcard character can be used as either a prefix or a suffix

SELECT FirstName, LastName
FROM Person.Person
WHERE FirstName LIKE 'Dan%';
[] - Matches any single character within the specified range or set that is specified between the brackets.

FROM HumanResources.Employee AS e
      INNER JOIN Person.Person AS p ON e.BusinessEntityID = p.BusinessEntityID
      INNER JOIN Person.BusinessEntityAddress AS ea ON e.BusinessEntityID = ea.BusinessEntityID
      INNER JOIN Person.Address AS a ON a.AddressID = ea.AddressID
WHERE a.PostalCode LIKE '[0-9][0-9][0-9][0-9]';

[^] - Matches any single character that is not within the range or set specified between the square brackets.

SELECT FirstName, LastName
FROM Person.Person
WHERE FirstName LIKE 'Al[^a]%'

ORDER BY FirstName;


_ - Matches any single character in a string comparison operation that involves pattern matching, such as LIKE and PATINDEX.

SELECT FirstName, LastName
FROM Person.Person
WHERE FirstName LIKE '_an'

ORDER BY FirstName;


Tuesday, March 12, 2013

SQL Queries to check configurations in SQL Server

SQL Queries to check different server Properties:

1.    Max Server Memory:


SELECT * FROM sys.Configurations WHERE
NAME = 'max server memory (MB)'

SELECT * FROM sys.dm_os_sys_memory

Update Query for Max Server Memory:

Exec sp_configure 'max server memory (MB)', 12228

2.    Backup Compression Default:
Default Value: 0
Updated Value as per standards: 1

SELECT * FROM sys.Configurations WHERE
NAME = 'backup compression default'

How to update Backup Compression:
Exec sp_configure 'backup compression default', 1

3.    Instant Data File Initialization:
Default Value: Off
Standards: On

4.    MAXDOP
Default Value: 0
Standards: n (If there are n processors)


exec master..xp_msver processorCount
Exec sp_configure 'max degree of parallelism', 4

5.    How to check Authentication mode:
            CASE SERVERPROPERTY('IsIntegratedSecurityOnly')  
                        WHEN 1 THEN 'Windows Authentication'  
                        WHEN 0 THEN 'Windows and SQL Server Authentication'  
            END as [Authentication Mode] 

6.    How to check TempDB Properties:

    name AS FileName,
    size*1.0/128 AS FileSizeinMB,
    CASE max_size
        WHEN 0 THEN 'Autogrowth is off.'
        WHEN -1 THEN 'Autogrowth is on.'
        ELSE 'Log file will grow to a maximum size of 2 TB.'
    growth AS 'GrowthValue',
    'GrowthIncrement' =
            WHEN growth = 0 THEN 'Size is fixed and will not grow.'
            WHEN growth > 0 AND is_percent_growth = 0
                THEN 'Growth value is in 8-KB pages.'
            ELSE 'Growth value is a percentage.'
FROM tempdb.sys.database_files;

Thursday, January 24, 2013

Data Warehouse design

Line of business:
LOB is a general term which often refers to a set of one or more highly related products which service a particular customer transaction or business need.

Data Warehouse:
Analyzing data from databases that support line-of-business (LOB) applications is usually not an easy task. The normalized
relational schema used for an LOB application can consist of thousands of tables. Naming conventions are frequently not
enforced. Therefore, it is hard to discover where the data you need for a report is stored.

Common solution to these problems is to create a data warehouse (DW). A DW is a centralized data silo for an enterprise that contains merged, cleansed, and historical data. 
Queries often involve reading huge amounts of data and require large scans. To support such queries, it is imperative to use an appropriate physical design for a DW.

Common problem designing DWH:

  1. Normalization is a process in which you define entities in such a way that a single table represents exactly one entity. The goal is to have a complete and non-redundant schema. In a database that supports an LOB application for an enterprise, you might finish with thousands of tables!  
  2. Finding the appropriate tables and columns you need for a report can be painful in a normalized database simply because of the number of tables involved.
  3. In addition, a query that joins 10 tables, as would be required in reporting sales by    countries and years, would not be very fast.
The Star and Snowflake schemas are both simplified and narrative. A data warehouse should use Star and/or Snowflake designs
Start Schema:
It resembles a star. There is a single central table, called a fact table, surrounded by multiple tables called dimensions.
The fact table is connected to all the dimensions with foreign keys. Usually, all foreign keys taken together uniquely identify each row in the fact table, and thus collectively form a unique
key, so you can use all the foreign keys as a composite primary key of the fact table. You can also add a simpler key. The fact table is on the “many” side of its relationships with the dimensions.
If you were to form a proposition from a row in a fact table, you might express it with a sentence such as, “Customer A purchased product B on date C in quantity D for amount E.”
This proposition is a fact; this is how the fact table got its name.
Dimensions with connections to multiple fact tables are called shared or conformed dimensions.

Snowflake Schema:
Star schema with normalized dimensions is called a Snowflake schema. Queries on a Star schema are simpler and faster than queries on a Snowflake schema, because they involve fewer joins.
You should use a Snowflake schema only for quick POC projects.

Auditing and Lineage:
For every update, you should audit who made the update, when it was made, and how many rows were transferred to each dimension and fact table in your DW. you might want to know where
each row in a dimension and/or fact table came from and when it was added. In such cases, you must add appropriate columns to the dimension and fact tables. Such detailed auditing information
is also called lineage in DW terminology.

Download SQL Queries from link to build DWH.