Posts

C#: What is the difference between IQueryable vs IEnumerable?

The main difference between the two is the location of the query execution. The following example demonstrates the difference: IQueryable<Model> models = ... models.Where(x => x.ID ...) IQueryable is used from LINQ-to-Anything (such as SQL). In this case, the query filter will be executed on the SQL server. This is great for reducing the amount of data returned from the data store. However, if the code looks as follows: IEnumerable<Model> models = ... models.Where(x=> x.ID ...) The results might be the same but using IEnumerable will cause the query results to be loaded in the memory and the predicate will be executed on the entire result set.

C#: How can I get my Selemium test to log into Azure?

I have been writing some entry level Selenium tests for my Azure website that authenticates using Azure AD. The biggest issue is trying to get the WebDriver to authenticate into the solution. After a lot of learning (read: failed attempts) I have the following solution (read: hack) that seems to work. 1. In my [TestInitialize] method, I load JQuery to the created page public static class Common     {         public static string GetEval(IWebDriver driver, string script)         {             IJavaScriptExecutor js = driver as IJavaScriptExecutor;             return (string)js.ExecuteScript(script);         }         public static string GetFile(string path)         {             using (var reader = new StreamReader(path))             {   ...

CSS: How do I create a single 'back to top' button?

A little CSS and JQuery can produce a lot of magic in an application. Here is the code. 1. Start with a simple html page. The important item here is to have an 'ID' to navigate to. In my case, I called it 'top'. <html> <head>     <base href="/" />     <title>Test Page</title>     <meta charset="UTF-8" />     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <script src=”//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js”></script>     <link href="css/myStuff.css" rel="stylesheet" /> </head> <body>     <div>         <!-- Start Body Content -->         <div ng-view role="main" id="top"></div>         <!-- End Body Content --> ...

SharePoint: Cannot file "Style%2520Library/Js/myfile.js"

I recent SharePoint deployment raised the interesting error about a missing file. When I checked the expected folder, the file was there so the error seemed a little strange. The solution is in the message: The missing file is Style %2520 Library. The cause was an incorrect link reference in the masterpage. The link was set to <SharePoint:ScriptLink Name="~SiteCollection/ Style%20Library /JS/myfile.js" runat="server" ID="ScriptLink2" /> SharePoint is url encoding the value. The encoded value of '%' is '%25', which results in the strange url. I removed the %20 from the link address and the issue was resolved.

HTML5: How do I store values in the session (and why is $cookie complaining about space).

It appears that there is a size limitation for angular-cookies - 4KB. Bummer. An alternative is to use the HTML 5 objects window.localStorage or window.sessionStorage. See  here  for details I used sessionStorage to hold a single object and an object array from a REST endpoint. The code to get and set the values is as follows: First, set the values: sessionStorage.Object1 = JSON.stringify(singleObject); sessionStorage.Object2 = JSON.stringify(multipleObjects) Now populate objects with the cached values: var single = JSON.parse($.parseJSON(sessionStorage.Object1)) var array = $.parseJSON(sessionStorage.Object2)

C#: Pass multiple values to a REST endpoint without having multiple parameters

Instead of passing the parameters to /REST.svc?param1=a&param2=b var items = new NameValueCollection(); items.Add("param1", "a"); items.Add("param2", "b"); var content = HttpPost("http://MyRestEndpoint", items); public static string HttpPost(string uri, NameValueCollection pairs)         {             byte[] response = null;             using (WebClient client = new WebClient())             {                 response = client.UploadValues(uri, pairs);             }             return System.Text.Encoding.UTF8.GetString(response);         } NOTE: You can quite easily inject a proxy using the following code: client.Proxy = new System.Net.WebProxy("myProxy", 1001);

AngularJS: Creating headers in an ng-repeat

I came across this great directive  here  to create headers based on sections in an ng-repeat. The cides works like a charm. Here is a copy. // html <div ng-repeat="item in data.items | orderBy:... | filter:... as filteredItems" header-list objects="filteredItems" header="getHeader">     <div ng-show="item.$header">{{item.$header}}</div>     <div>Your normal content</div>  </div> // controller function $scope.getHeader = function(item) {   return item.name.slice(0, 1); } // directive app.module("...").directive('headerList', function () {   return {     restrict: 'A',     scope: {       objects: '=',       header: '=' // This must be a function or instance method     },     link: function(scope) {       scope.$watch('objects', function() {         var lastHeader, currentHeader; ...