Array to CSV with javascript

More of a quick note to myself than anything but a nice quick way of making a Comma separated string was found here.

I went with the simple answer as I know the strings will never have comma’s in them.

var arr = new Array(3);
arr[0] = "Zero";
arr[1] = "One";
arr[2] = "Two";
[/ javascript]


The stack overflow answer and comments does provide alternative methods where this could be overcome.

var arr = new Array(3);
arr[0] = “Zero”;
arr[1] = “One”;
arr[2] = “Two”;

document.write(arr); // same as document.write(arr.toString()) in this context


Users exists MSSQL

Nice little snippet to see if a specific login has user access to a database.

More info here

Select as LoginName, sp.type_desc as LoginType, as DBUser, dp.type_desc as UserType
from sys.server_principals sp
join sys.database_principals dp on dp.sid = sp.sid
where = 'test' -- your login


Linq LambdaComparisons

Whilst trying out some integration testing I came across a really handy class with some great extension methods.  I wanted to be able to pick out all the roles that weren’t all ready assigned to a user.  I started playing with some loops and comparisons and got my knickers in a twist with something that should be pretty simple.  I then stumbled across the Except expression for linq, which didn’t work on my objects as the where entity framework entities.  SO a little more googeling and I found these articles.   Which show to to Lambda Distinct and Except and it magically fixed all my problems.


Gist of the classes

This shows my simple example that looks at all the roles in a database and compares them to all the roles a user has and highlights the difference. The lambda used is the Id filed which is a unique primary key for the role.