defineProperty method in Javascript

defineProperty is a method on Object which allow you to configure the properties to meet some criterias.
Here is a simple example with an employee object with two properties firstName & lastName and append the two properties by overriding the toString method on the object.
You will get Output as : Jameel Moideen

I am going to change the same code by using defineProperty on the object

The first parameter is the name of the object and then second parameter is name of the property we are adding , in our case it’s toString and then the last parameter is json object which have a value going to be a function and three parameters writable,enumerable and configurable.Right now I just declared everything as true.

If u run the example you will get Output as : Jameel Moideen

Let’s understand why we need the three properties such as writable,enumerable and configurable.
One of the very annoying part of the javascript is , if you change the toString property to something else for example

if run this again , everything gets breaks
Let’s change writable to false. If run the same again you will get the correct output as ‘Jameel Moideen’ . This property will prevent overwrite this property later.
if you print all the keys inside the object , you can see all the properties including toString.
if you set enumerable to false , you can hide toString property from everybody else. If run this again you will get firstName,lastName

if someone later redefined the object on later for example enumerable to true and run it. You can see toString property came again.

we no need this behavior , so you can restrict this by set configurable to false.

Set HTTP Cache Expiration in Angular JS and Typescript

Create an Interceptor for every service calls

angular.module('app').factory("cacheInterceptor", ["$cacheFactory", function ($cacheFactory) {
 var httpTtlCache = {};
 return {
 request: function (config) {
 var expirationTime;
 if (config.expiration) {
 expirationTime = config.expiration;
 delete config.expiration;
 if (new Date().getTime() - (httpTtlCache[config.url] || 0) > expirationTime) {
 httpTtlCache[config.url] = new Date().getTime();
 return config;

Push the interceptor through config

angular.module('app', []).config(['$httpProvider', function ($httpProvider) {

Pass the expiration when you call your httpservice

  var expirationTime = 60 * 60 * 1000;
            $http.get(url, { expiration: expirationTime,cache:true }).then(function (response) {

Row Level Security In SQL Server 2016

By using Row Level Security(RLS) you can filter and block access to individual rows within a table based on some custom logic that you write inside a predicate function.
A predicate function is an ordinary inline table-valued function(TVF) which SQL Server executes against every DML operation on the table.Your predicate function typically compare the current user context with some column value in each and return yes or no if that row is accessible.You can apply the predicate function to the table by creating a security policy and SQL Server immediately filters in the case of
select or blocks in the case of insert,update,delete.You can easily turn on and off at any time for any table.There are two types of predicates

  1. Filter Predicates
  2. Block Predicate

Filter Predicate
You can apply filter predicates on any select, update ot delete statement so that rows deemed inaccessible to the user are not processed by the select , update or delete operation.

Block Predicate
This predicate is more like triggers, preventing the user from inserting , updating or deleting rows that violate the rules of the predicate function. there are variations for predicate function

Can’t insert or update rows to values that would violate the predicate
Can’t update or delete rows that violates the predicate

Security Predicate Functions
Security Predicate Functions are table valued function (TVF) which you write in T-SQL. This TVF must be a schema bound which means that all object references, tables or other functions must be fully qualified by schema name even if it’s default dbo schema.


For showing the demo I have created a sample Sales table where with orders where we want each salesperson to access only the orders in the table they are assigned.Means each person should have private access to their owns orders and none of the sales person can access to other salesperson orders.So we will grant read only access to their orders and only one admin user has read and write access to all the rows in a table.

Create a user, this could be any database user whether that user is a SQL server login or windows authentication login.Here I am created the users without any login

Create an sec schema

You can see username parameter which map to the username column when we create the security policy below. In the above function you can see Table return WITH SCHEMABINDING which is mandatory for predicate functions.

Let’s apply security policy on sales table for testing the predicate function created. for that I am running predicate function as User1

When I select the above predicate function you can see a permission error . The SELECT permission was denied on the object ‘fn_securitypredicate’, database ‘SampleDB’, schema ‘sec’. which is expected because  we will not allow the normal users to execute the table valued function selecting from directly. For testing i am giving a temporary grant select permission to the User1.

Execute the select statement again.Now you can see predicate function return 1

I am again executing the function by passing as User2 and you can see that no result is returned meaning that rows with User2 in the sales Username column are inaccessible to queries executed by User1

Let’s test the Table Valued Function for the Admin User. For that I am going to REVERT to default dbo user and removing the select permission from the TVF that we added temporarily before

which will return 1

Let’s create a new Security policy with Filter Predicate we have created before

Let’s select the records from sales table and you can see no records return because Now it’s run under default dbo user.

Let’s execute as User1 and you can see that three records are showing corresponding to the user1
Select * from Sales

You can download the source from here

Minify CSS using Gulp

For minifying, you can use csso plugin. 
npm install gulp-csso –save-dev
Create a new task for minifying the css using this plugin

var gulp = require('gulp');
//gulp-load-plugins helps for a cleaner syntax
var $ = require('gulp-load-plugins')({ lazy: true });

function () {
return gulp.src([“./Theme/default.css”])

Dynamic Data Masking(DDM) in SQL Server 2016

Dynamic Data Masking(DDM)

You can use DDM in many scenarios involving sensitive data.For example in a production database there are some strict regulations from sharing the sensitive data to the developers when they are working on live data.DDM helps solve this problem because admininstrators can now give developers access to production data with all sensitive data masked from view.There is no additional development effort or coding required for this. You just define your masks.

Here I am going to create a new table with few masked columns


partial function – queries only show the first two characters and the last two characters and replaces everything in between with three dots

default function – completely hide the value

email function – only show the first character of the email address followed by a hardcoded mask  formatted to look like a email address

You can use the below query to select the masked columns

I have already added two records in the UserAccount table. I am going to select and check the mask is applied to the records

When you look at the records, can see that masking is not applied to the records.It’s because masking is applied only to the users that don’t have the UNMASK permission.the current connect have that permission that’s why nothing is masked.

I am going to create a new user for demo purpose and giving the user to select permission only

I am going to select the records as DemoUser

Now You can see all the records have mask applied.If you want to give UNMASK permission you can grant permission


You can download the source code from here