Tuesday, August 4, 2015

Enable Execution of Powershell Scripts inside Visual Studio
























PS P:\>Set-ExecutionPolicy unrestricted
PS P:\>Set-ExecutionPolicy remotesigned

Tuesday, July 21, 2015

Compressed AJAX Data

String Extension Method Zip:
public static byte[] Zip(this string str)
{
var bytes = Encoding.ASCII.GetBytes(str);
using (var memorystreaminput = new MemoryStream(bytes))
using (var memorystreamoutput = new MemoryStream())
{
using (var gs = new GZipStream(memorystreamoutput, CompressionMode.Compress))
{
memorystreaminput.CopyTo(gs);
}
return memorystreamoutput.ToArray();
}
}

Repository Save:
var showsIQueryable = GetShowsIQueryable();
var serializer = new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue };
var data = serializer.Serialize(showsIQueryable);

var compressedDataBlob = data.Zip();

//stores compressedDataBlob

Controller ActionResult Get:
var showsJsonText = _showService.CommandRepo.GetShowsCache();
Response.Headers.Remove("Content-Encoding");
Response.AppendHeader("Content-Encoding", "gzip");

return new FileContentResult(showsJsonText, "application/javascript");

JavaScript:
$.ajax({
type: "POST",
url: serverUrl,
dataType: 'json',
cache: false,
async: true,
data: JSON.stringify(model),
contentType: "application/json; charset=utf-8"
}).done(function (data) {
....
});

HTML:
<script type="text/javascript">
var shows = @Html.Raw(new JavaScriptSerializer().Serialize(Model.Shows)
</script>

Thursday, July 16, 2015

Friday, July 10, 2015

Watching: Website Performance

























Website Performance
Introduction
Make Performance a Priority
Why web performance?
Performance and user experience
How we get web performance
Focus on the critical path
The total cost of ownership
The Middle-End: YSlow
YSlow rules
Beyond the big 14
The Middle-End: Resources
Images
Minification
The Middle-End: Architecture & Communication
Understanding the middle-end
Introduction to architecture
Data validation
JSON, ajax, & Web sockets
The Front-End: Resource Loading
Preloading images
Lazy loading
Parallel loading
The Front-End: Abstractions & Animation
OO is slower
JavaScript animations
CSS transition vs. css animation
The Front-End: UI Thread, Garbage Collection & jsPerf
The single threaded browser
Threaded JavaScript
Dynamic memory allocation
Introduction jsPerf
JavaScript performance mythbusters

Wednesday, May 13, 2015

Friday, April 17, 2015

3 Ways to Load Html with HtmlAgilityPack

Method 1:
var web = new HtmlWeb();
var doc = web.Load(sourceUrl);

Method 2:
var uri = new Uri(sourceUrl);
var request = (HttpWebRequest)WebRequest.Create(uri);
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
var response = (HttpWebResponse)request.GetResponse();

var doc = new HtmlDocument();
var stream = response.GetResponseStream();
doc.Load(stream, Encoding.UTF8);

Method 3:
using (var wc = new WebClient()){
html = wc.DownloadString(sourceUrl);
}
var doc = new HtmlDocument();
doc.LoadHtml(html);