P/Invoke Tutorial: Pinning (Part 4)

Sometimes a C/C++ function needs to store data you pass to it for later reference. If such data is a managed object (like a string or class) you need to make sure that the garbage collector doesn’t delete it while it’s still used/stored in the native code.

That’s what pinning is for. It prevents the garbage collector from deleting and moving the object.

Read more →

Quick Tip: Start Docker Toolbox Shell via Batch

Are you still stuck with Windows 8.1 or earlier? Then, if you want to use Docker, you have to use the Docker Toolbox.

Docker Toolbox comes with its own “shell” called Docker Quickstart Terminal. It uses Windows’ own command window – which is pretty limited.

docker-shell.png

As I explored in Command Line Replacement For Windows, there are alternatives.

To be able to interact with Docker Toolbox in these alternative command line tools, you can create a simple batch file that drops you into the same Docker shell as the “Docker Quickstart Terminal”:

@echo off
setlocal
cd /D %DOCKER_TOOLBOX_INSTALL_PATH%
"%GIT_INSTALL_ROOT%\bin\bash.exe" --login -i "%DOCKER_TOOLBOX_INSTALL_PATH%\start.sh"

Vagrant Tutorial – From Nothing To Multi-Machine

As developers, we sometimes want to quickly test some software. Instead of installing it directly on our developer machine, it’s better to install it in a virtual machine (VM). But if you don’t have a VM ready, setting one up usally takes a lot of time – and there goes your productivity.

Fortunately, there is a solution: Vagrant

Vagrant is a free tool that lets you quickly spin-up fresh VMs out of thin air. It can even spin-up multiple VMs at the same time.

This article is step by step tutorial for getting from nothing to a multi-VM setup where the VMs can talk to each other.

Read more →

Breaking .NET’s Random class

Security is hard. In a current project I saw some code that created some access tokens based on a random number generator – .NET’s Random class. The code used an instance of Random stored in static field and I got curious:

If you have such a long living Random instance, could you predict the random values after generating a few of them?

It turns out, it is possible. And you only need to read 56 55 “random” values to predict all future values.

Read more →