Labels

CSOM (1) JavaScript (1) SharePoint (1)

Thursday, October 8, 2020

VS Code Theme


 VS Code Theme







{
    "files.watcherExclude": {
        "**/target"true
    },
    "editor.tokenColorCustomizations": {
        "[Dark+ Tweaked]": {
            "types""#14a1e2d2",
            "keywords""#e06a1af3",
            "functions""#07a042",
            "variables""#FF0000",
            "comments""#606060",
            "textMateRules": [
                {
                    "name""key",
                    "scope""keyword",
                    "settings": {
                        "foreground""#5fb2c7",
                        "fontStyle""italic"
                    },
                },
                {
                    "name""comment1",
                    "scope""variable.other",
                    "settings": {
                        "foreground""#d82067",
                        "fontStyle""italic"
                    },
                },
                {
                    "name""comment2",
                    "scope""keyword.operator",
                    "settings": {
                        "foreground""#f5de0cf8",
                        "fontStyle""italic"
                    },
                },
                {
                    "name""comment3",
                    "scope""string.regexp",
                    "settings": {
                        "foreground""#0cf53ffb",
                        "fontStyle""italic"
                    },
                },
                {
                    "name""comment3",
                    "scope""entity.name.method",
                    "settings": {
                        "foreground""#b30cf5fb",
                        "fontStyle""italic"
                    },
                },
            ]
        },
    },
}


{
    "files.watcherExclude": {
        "**/target": true
    },
    "editor.tokenColorCustomizations": {
        "[Dark+ Tweaked]": {
            "types": "#14a1e2d2",
            "keywords": "#e06a1af3",
            "functions": "#07a042",
            "variables": "#FF0000",
            "comments": "#606060",
            "textMateRules": [
                {
                    "name": "key",
                    "scope": "keyword",
                    "settings": {
                        "foreground": "#5fb2c7",
                        "fontStyle": "italic"
                    },
                },
                {
                    "name": "comment1",
                    "scope": "variable.other",
                    "settings": {
                        "foreground": "#d82067",
                        "fontStyle": "italic"
                    },
                },
                {
                    "name": "comment2",
                    "scope": "keyword.operator",
                    "settings": {
                        "foreground": "#f5de0cf8",
                        "fontStyle": "italic"
                    },
                },
                {
                    "name": "comment3",
                    "scope": "string.regexp",
                    "settings": {
                        "foreground": "#0cf53ffb",
                        "fontStyle": "italic"
                    },
                },
                {
                    "name": "comment3",
                    "scope": "entity.name.method",
                    "settings": {
                        "foreground": "#b30cf5fb",
                        "fontStyle": "italic"
                    },
                },
            ]
        },
    },
}

Thursday, February 1, 2018

C# Class to Dataset


Extension method to Convert IEnumerable to DataSet


public static DataTable AsDataTable<T>(this IEnumerable<T> data)
{
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
var table = new DataTable();
foreach (PropertyDescriptor prop in properties)
{
table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
}
foreach (T item in data)
{
DataRow row = table.NewRow();
foreach (PropertyDescriptor prop in properties)
row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
table.Rows.Add(row);
}
return table;
}


Call the method

IEnumerable<T>data = ReadFile(...);
DataTable dataTable = data.AsDataTable();

Sunday, December 24, 2017

SQL Server Query Plan Analysis: The 5 Culprits That Cause 95% of Your Performance Headaches

SQL Server Query Plan Analysis: The 5 Culprits That Cause 95% of Your Performance Headaches









Wednesday, December 13, 2017

Simple DAX on Power BI

DAX

Sum with applying a filter

Total for Non Duplicate = 
CALCULATE(
SUM('InvoiceDetails'[Total]),
'InvoiceDetails'[DuplicateInvoice] IN { FALSE }
)

Total for Non Duplicate 2 =
 SUMX( 
FILTER(InvoiceDetails,InvoiceDetails[DuplicateInvoice] = FALSE ),

InvoiceDetails[Total])


Handle null value in SUM/ COUNT


Exception Value = 
VAR total=SUM(InvoiceStatusView[EXCEPTION]) 

RETURN IF(ISBLANK(total),0,total)


Exception Count = 

VAR total=COUNT(InvoiceStatusView[EXCEPTION]) 

RETURN IF(ISBLANK(total),0,total)

Tuesday, December 5, 2017

All Tables Row Count

All Tables Row Count


SELECT T.name AS [TABLE NAME], 
       I.rows AS [ROWCOUNT] 
FROM   sys.tables AS T 
       INNER JOIN sys.sysindexes AS I 
               ON T.object_id = I.id 
                  AND I.indid < 2 
ORDER  BY I.rows DESC 

Wednesday, October 4, 2017

Time Dimension T-SQL


Generating Time Dimention

with cte1 as(

select 1 as a from( values(1),(2)) as A(a)
cross join ( values(1),(2)) as B(b)
),
cte2 as( select 1 as x from cte1 as a cross join cte1
),cte3 as( select 1 as x from cte2 as a cross join cte2
),cte4 as( select 1 as x from cte3 as a cross join cte3
),CTE as( select ROW_NUMBER() over(order by (select 1)) as x from cte4)
select x,CONVERT (date, getdate()-x ) from CTE


Thursday, August 24, 2017

Hashing password with Salt

Hashing password with Salt

Generate hash in Sql
SELECT HASHBYTES('SHA2_512', 'password-plaintext');

Generate hash in .Net
SHA512 hash = SHA512Managed.Create();
saltedPassword=password+Guid.NewGuid().ToString().ToUpper();
byte[] passwordHash = hash.ComputeHash(Encoding.UTF8.GetBytes(saltedPassword));

salt used is Guid

Points to Note to match HASH generated in SQL  and .Net 
  1. Guid is SQL is in UPPER Case while .Net Guid is in lower case
  2. string equivalent in .Net is varchar and NOT nvarchar, so use CAST(N'xxxxxx' as varchar(50)) in case its variable is of type nvarchar





can use below script to generate salt and hash
 
  1. update dbo.Tenant set TenantPasscodeSalt=NEWID();
  2. update dbo.Tenant set TenantPasscodeHash= HASHBYTES( 'SHA2_512',CAST(TenantPasscode as VARCHAR(50))+CAST(TenantPasscodeSalt as VARCHAR(50)))

byte[] passwordHash;
salt =Guid.NewGuid();
            using (SHA512 hash = SHA512Managed.Create())
            {
                string saltedPassword = password + salt.ToString().ToUpper();
                passwordHash = hash.ComputeHash(Encoding.UTF8.GetBytes(saltedPassword));
            }

SqlParameter paramTenantPasscodeHash = cmd.Parameters.Add("@TenantPasscodeHash", SqlDbType.VarBinary, 128);
                        paramTenantPasscodeHash.Value = passwordHash;