Google+ Peter Bromberg's .NET Blog | All Things Programming

Peter Bromberg's .NET Blog All Things Programming

How to block tracking cookies in Google Chrome

27. April 2018 15:08 by admin in CHROME, SECURITY

 

Web sites plant cookies for all kinds of reasons, some good, and many not so good. If you visit the New York Times, for example, there are nearly 80 cookies planted, many from services that do nothing but collect your browsing habits and track you all over the web.

1. Click the favicon at the left of the address bar. If it's https, click the green "Secure" icon. You'll see a popup with a list of options. 
2. Near the bottom will be "cookies" Click that and you will see the screen in the photo. From here you can block any cookies you don't like. You're welcome.

NOTE: If you like to stay signed in to your Google account, don't block any Google cookies.

 

Lexical Analysis (Word Count) of Trump's State of the Union Speech

31. January 2018 08:30 by admin in

Each  year I do an analysis of the word count of the current president's State of the Union addresss. The code to do this (once you have downloaded the speech as a text file) has gotten much simpler over the years, especially after the introduction of LINQ.

Here is an example of the key part of the code in C# as an extension method:

public static Dictionary<string, int> GetWordFrequency(this string input){
return input.Split(new char[] { ' ' })
.Where(i => i.Trim() != String.Empty && Regex.IsMatch(i,@"\w"))
.Select(i => Regex.Replace(i,@"[^A-Za-z0-9]+$","").ToLower())
.Where(x => !stopwords.Contains(x))
.GroupBy(w => w)
.OrderByDescending(group => group.Count())
.ToDictionary(group => group.Key, group => group.Count());
}

Here is the sorted list of words with their frequency (Down to a count of 5):

american,29
people,23
americans,20
tonight,20
america,14
congress,13
tax,13
country,13
home,11
am,10
administration,9
america's,9
family,9
world,8
immigration,8
united,7
building,7
safe,7
finally,7
workers,7
nation,7
veterans,7
citizens,7
heroes,6
love,6
strong,6
proud,6
jobs,6
protect,6
communities,6
nuclear,6
isis,6
north,6
passed,5
help,5
police,5
including,5
stands,5
bill,5
reform,5
drugs,5
drug,5
dangerous,5
terrorists,5

 

You can download the complete source code below. The speech.text file is in the /bin/debug folder.

SOTU.zip (215.24 kb)

How to improve the performance of Visual Studio 2017

3. November 2017 13:01 by admin in ASP.NET, C#, VIsual Studio 2017

 

1. Exclude VS and other tools from Windows Defender.

Here is a list of exclusions for a system with Visual Studio 2017 Professional, ReSharper and Node.js installed.

Processes to Exclude:

// visual studio & tools
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe
C:\Program Files\dotnet\dotnet.exe
// Node.js
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Web\External\node.exe
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\ServiceHub\Hosts\ServiceHub.Host.Node.x86\ServiceHub.Host.Node.x86.exe
// Node.js (if installed separately or upgraded)
C:\Program Files\nodejs\node.exe

Folders to Exclude:

// project folder (Whatever folder(s) you use for projects)
// visual studio & tools
C:\Program Files (x86)\Microsoft Visual Studio 10.0
C:\Program Files (x86)\Microsoft Visual Studio 14.0
C:\Program Files (x86)\Microsoft Visual Studio
C:\Windows\assembly
C:\Windows\Microsoft.NET
C:\Program Files (x86)\MSBuild
C:\Program Files\dotnet
C:\Program Files (x86)\Microsoft SDKs
C:\Program Files\Microsoft SDKs
C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv
C:\Program Files (x86)\Microsoft Office
// cache folders
C:\ProgramData\Microsoft\VisualStudio\Packages
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
C:\Users\{{USERNAME}}\AppData\Local\Microsoft\VisualStudio
C:\Users\{{USERNAME}}\AppData\Local\Microsoft\WebsiteCache
C:\Users\{{USERNAME}}\AppData\Local\Jetbrains
C:\Users\{{USERNAME}}\AppData\Roaming\Microsoft\VisualStudio
C:\Users\{{USERNAME}}\AppData\Roaming\JetBrains
C:\Users\{{USERNAME}}\AppData\Roaming\npm
C:\Users\{{USERNAME}}\AppData\Roaming\npm-cache


2. Turn off indexing
Indexing Service is another bottleneck, pulling the disk I/O to 100% during builds and installing packages as well as shortening the lifetime of SSD drives.

Open the command prompt, type services.msc, and press enter. At the list of services, scroll down until you find Windows Search service. You’ll notice it has probably a Started status and Automatic startup type. Stop the service and set the startup type to Disabled. Do a system restart.
Search will still work, it just won't use the index.

3. Visual Studio Settings:

The following are recommended settings based on best practices for Visual Studio 2017
You can decide which features to leave enabled based on your own needs.

Environment -> General
Uncheck “Automatically adjust visual experience based on client performance”
Uncheck “Enable rich client visual experience”
Check “Use hardware graphics acceleration if available”
Environment -> AutoRecover
Uncheck “Save AutoRecover information every”
Environment -> Documents
Check “Save documents as Unicode when data cannot be saved in codepage”
Environment -> Keyboard
Set “ForceGC” to ctrl+num1
Set “ReSharper_Toggle” to ctrl+num0 (if ReSharper is used)
Set “ReSharper_EnableDaemon” to ctrl+num8 (if ReSharper is used)
Environment -> Startup
Set “At startup” to “Show empty environment at startup”
Uncheck “Download content every”
Environment -> Synchronized settings
Uncheck “Synchronize settings across devices when signed into Visual Studio”
Projects and Solutions
Uncheck “Track active item in solution explorer”
Check “Lightweight solution load for all solutions”
Projects and Solutions -> Build and Run
Check “Only build startup projects and dependencies on run”
Projects and Solutions -> Web Package Management
Set “Restore on Project Open” to false (for Bower)
Set “Restore on Save” to false (for Bower)
Set “Restore on Project Open” to false (for NPM)
Set “Restore on Save” to false (for NPM)
Text Editor -> General
Uncheck “Track changes”
Text Editor -> All Languages -> General
Uncheck “Enable virtual space”
check “Line numbers”
Uncheck “Navigation bar”
Text Editor -> All Languages -> Scroll Bars
Uncheck “Show annotations over vertical scroll bar”
Text Editor -> All Languages -> CodeLens
Uncheck “Enable CodeLens”
Text Editor -> Basic -> Advanced
Uncheck “Enable full solution analysis”
Text Editor -> C# -> Advanced
Uncheck “Enable full solution analysis”
Text Editor -> Basic, C# -> IntelliSense
Uncheck “Show completion list after a character is deleted”
Set “Snippets behavior” to “Never include snippets”
Text Editor -> CoffeeScript -> CoffeeLint
Set “Enable CoffeeLint” to false
Text Editor -> CSS -> CssLint
Set “Enable CSS Lint” to false
Text Editor -> CSS, HTML, JSON, LESS, SCSS -> Advanced
Set “Show errors as warnings” false
Text Editor -> JavaScript/TypeScript -> EsLint
Set “Enable ESLint” to false
Text Editor -> SQL Server Tools, U-SQL -> Intellisense
Uncheck “Enable Intellisense”
Text Editor -> [Language] -> Formatting -> General
Uncheck everything (if ReSharper is used for formatting assistance)
Debugging
Uncheck “Suppress JIT optimization on module load (Managed only)”
Uncheck “Enable Edit and Continue”
Debugging -> Just-In-Time
Uncheck “Script”
IntelliTrace
Uncheck “Enable IntelliTrace”
Node.js Tools
Set “Check for surveys/news” to “Never”
Web Forms Designer
Uncheck “Enable Web Forms Designer”
Windows Forms Designer
Set “Automatically Populate Toolbox” to false
XAML Designer
Uncheck “Enable XAML Designer”

Kudos to developer Burak Tasci ( https://www.linkedin.com/in/buraktasci/) for many of the above settings.

How to get an assembly's location on the fly

9. August 2017 13:30 by admin in

 

private string[] GetAssemblyLocation(string[] assemblyNames){string[] locations = new string[assemblyNames.Length];for (int loop = 0; loop <= assemblyNames.Length - 1; loop++){locations[loop] = AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && a.ManifestModule.Name == assemblyNames[loop]).Select(a => a.Location).FirstOrDefault();}return locations;}


USAGE:

string reportPath = GetAssemblyLocation(new string[] { "Reports.dll" })[0];
  System.Reflection.Assembly assembly = Assembly.LoadFrom( reportPath);