Bing Code Search Add-in for Visual Studio

Bing Code Search for Visual Studio 2013 helps developers find and reuse code samples on the web more easily by bringing the code search experience directly into Visual Studio. With this extension, a developer can search sites such as MSDN, StackOverflow, CSharp411 and Dotnetperls and find, copy and use C# code samples directly inside the IDE.

Download the Code Search Add-in from the Visual Studio gallery site for free.

Make software installation painless with Chocolatey

Problem

Everybody knows the pain of installing a complete new PC system. After installing windows and drivers the issue arrises to install all those useful tools like 7zip, VLC media player, Notepad++ and others. You have to download the installers from websites, wait for completion, unzip, run, install and next, next, next.

Solution

Linux never had this problem, because of apt-get feature. For Windows there now is a solution: Chocolatey! It offers you a seamless and quiet installation quickly from the command line via a central catalog of installation packages. All you need is the main Chocolatey program installed and the package names you want to install. From the command line, you can install Google Chrome, like this:

image

That’s it! It tells Chocolatey to download and install Google Chrome.

The real work behind Chocolatey is done by the NuGet program. The developers have created a set of PowerShell scripts around it. Most important: the installers are downloaded from the official sites. Chocolatey is not changing installers, making installers or hosting the installers. It's automating the boring parts of getting software, but it's still getting that software from the same location as always.

First step: install Chocolatey

To install, open a dos prompt and run:

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin

After completion the Chocolatey is downloaded and installed in c:\Chocolatey.

Basic list of commands

All Chocolatey commands are run by the command prompt.

Full name Short name & examples Description
choco list clist Display a list of all available packages.
  clist pdf Displays only packages with ‘pdf’ in the title/description.
  clist GoogleChrome –all Displays all the versions of Google Chrome
choco install cinst Install a package silently. Example: ‘cinst GoogleChrome’.
  cinst –notSilent Install a package with the standard wizard. Then more control of where the package is installed & extra options.
choco update all cup all Update all package installed with Chocolatey
choco uninstall cuninst Uninstall a package. Example: ‘cuninst GoogleChrome’
     

Installation feedback

Example of how an installation looks like:

image

Advanced stuff – your own repository

It’s also possible to create/use your own private repository. It can be a local directory, a USB drive, network share with installers in it. Every installer should have a package install script with the extension .nupkg. You can find them in c:\Chocolatey\lib or you can download them from the Chocolatey website:

image 

You can install local packages by using the –source parameter. For a new computer you can use:

image

After installation of all the packages, run this to update all:

image

For the bonus points: Boxstarter offers extra Powershell commands for writing complex installationscripts. Not only for simple Chocolatey packages, but also for installers that require system reboots.

Advanced stuff – Install Windows features

You can also automate installations of Windows features which normally require you to navigate to ‘Add/Remove programs then click Install Windows Features’. To discover the features you can install: ‘clist –source windowsfeatures’.

image

To install the classic ‘Feature’ Telnet Client, just run: cinst –source windowsfeatures TelnetClient

It’s also possible to install WEBpi features (The Web Platform Installer) like this. Again for a full list: ‘clist -source webpi’. To install Umbraco: ‘cinst –source webpi umbraco’

Tip of the day: Random sort a List of objects with Linq

Let’s say you have a list of objects and you want a random presentation to your website visitor. Below is a simple, but effective random algorithm in C# with Linq-to-object by using the GUID type (see line 10 below).

   1:  List<MemorySearchResult> list = Session["MemoryList"] as List<MemorySearchResult>;
   2:              
   3:  // see if list is already in user session
   4:  if (list == null)
   5:  {
   6:      // list not in session, so create a new one
   7:      var newList = myRepository.GetListOfObjects();
   8:   
   9:      // randommize
  10:      list = newList.OrderBy(tempGuid => Guid.NewGuid()).ToList();
  11:   
  12:      // store in session
  13:      Session["MemoryList"] = list;
  14:  }
  15:   
  16:  // now list is randomized and stored in session and ready to use

 

Easy does it!

Disable auto-update for Chrome extensions

Sometimes a Chrome extension gets very popular and then the authors choose a commercial path. Or some feature is discontinued, but you want to keep it as is. Below I describe a way to keep the extension from auto updating itself with the help of the Chrome extension source viewer. This extension is very useful for learning how to develop chrome extensions (how did they did this/that?).

First install the Chrome extension source viewer from the Chrome webstore. Or if you are planning to use it once, you can use the online version.

image 

Steps to modify a Chrome extension (to disable auto-update)

  1. Download a specific version of a Chrome extension. My example I used it for is Media Hint. Version 0.1.12 can be found here

  2. Go to your extensions folder in Chrome, turn on Developer Mode, and click on the options link below Chrome extension source viewer

  3. Open the viewer

  4. Open the recently downloaded Media Hint file

  5. Click "Download" in the upper left corner. Finder will open showing you a null folder that contains the Media Hint logo, a javascript file, and the manifest.

  6. Open the Manifest JSON file (Any text editor will do)

  7. Change the update url (found in quotations) to http://127.0.0.1 (you own local machine IP) and save the file

  8. Optional: Go to the Chrome Developer tools and choose to pack a chrome extension to create a .crx file again.

  9. Drag the entire null folder or the .crx file (with the newly edited manifest file) into your Chrome Extensions page with developer mode turned on.

  10. . Enjoy your customized extension

Hope this helps,

Guus