Let’s say you have an existing Unity game and you would like to test a prefab exclusively by itself. No problem, you’ve come to the right place. You can do this using what is called a Play Mode unit test. Here is some sample code to help get you started:

[UnityTest]
[Timeout(180000)] // Sets the timeout of the test in milliseconds (if the test hangs, this will ensure it closes after 3 minutes).
public IEnumerator TestAnimationAnimUtilityPrefab()
{
// Remove the default skybox.
RenderSettings.skybox = null;
// Create a new root game object.
var root = new GameObject();
// Attach a camera to our root game object.
root.AddComponent(typeof(Camera));
// Get a reference to the camera.
var camera = root.GetComponent<Camera>();
// Set the camera's background color to white.
camera.backgroundColor = Colors.white;
// Add our game object (with the camera included) to the scene by instantiating it.
root = GameObject.Instantiate(root);
// Load a prefab (by giving it the path to an existing prefab).
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Example.prefab");
// Instantiate the prefab (by adding it to the scene). Use the Quaternion to set the rotation in degrees and the Vector3 to set the position in 3D space.
prefab = GameObject.Instantiate(prefab, new Vector3(0, 0, 10), new Quaternion(0, 180, 0, 0));
// Wait for three seconds (this gives us time to see the prefab in the scene if its an animation or something else).
yield return new WaitForSeconds(3f);
// In this example, let's assume that our Example.prefab has a script on it called ExampleScript.
var script = prefab.gameObject.GetComponentInChildren<ExampleScript>();
// Assert that the script exists on our prefab so we don't stumble upon this problem in the future.
Assert.IsTrue(script != null, "ExampleScript must be set on Example.prefab.");
// Finally, we should clean up our scene by destroying our objects.
GameObject.Destroy(prefab);
GameObject.Destroy(root);
}

Here is a script I wrote which you can apply to your existing 3D camera in order to perform various functions such as zooming, dragging, or panning the main camera. It worked best for me in a chess game I was writing while learning Unity, in which I had to display a chess board to the user and allow him to move around the board inside of the game.

The inner mean is your hash rate. I’m sitting at about 13043122 H/s, which according to some online mining profitability calculator, could earn me about $30.45 / month if I don’t have to pay for electricity.

I just came across a weird API method in a C library for Windows that returned a list of strings as char **. Obviously, to read this back you need to know when to stop enumerating, so it told me this list is NULL terminated (terminated by a NULL pointer). Pretty cool, but I had no clue how to even allocate or to free this data type properly so I set up to create a proper example in a Visual C++ console application, since I couldn’t find any good articles on this online. So, effectively this list lives as a pointer to a pointer to a string. Here is how you can create one, read one back, and free one:

Hopefully you won’t have to spend a few hours on this like I just did. In addition, you would only use such a structure in production if you knew that none of your strings are ever to be NULL, or else they’d be mistaken for the NULL terminator and your deallocation method will fail miserably.

I feel its time to take a short break from blogging about code, so here are some photos. I took them recently on my Sony a7R II (man, what a camera). I shot them quite exclusively with either the Tamron SP 150-600MM F/5-6.3 Di VC USD lens using the LA-EA3 35mm Full-Frame A-Mount Adapter or via the Sony Vario-Tessar T* FE 16–35 mm F4 ZA OSS lens. Note that some of these Jay’s baseball game shots were literally up in the nosebleeds. I don’t think we could have gotten seats any further from the action.

Asynchronous programming is a bit nightmarish, but hopefully this sheds some light upon how you can leverage certain delegate types. Take this example, where you want an abstraction layer for calling a block of code up to a set number of attempts until it succeeds, otherwise having it delegate back the exception you’ve obtained on the very last attempt:

So, you want to add the latest reCAPTCHA Version 2.0 to your existing MVC website, you want to make it secure with server-side validation, and you want to make it asynchronous and have a rich user experience with AJAX? No problem. Start by adding div’s into the forms you need. Their ID’s will indicate where we want to place CAPTCHA elements. Note for all intents and purposes I am using two different CAPTCHA elements on the same page, just to illustrate it can be done, and done nicely:

Then wire these up. Take note of how the reCAPTCHA API allows us to tell it what loading method to use and what type of rendering we want (explicit, in this case). This is very important, as it allows us to control the CAPTCHA in JavaScript. Also, make sure to include your site key in the rendering calls:

Sometimes, you just need an extension method to generate and download files from the client-side of most modern browsers. The only real takeaway from the code below is that Internet Explorer browser agents like to behave differently and require a different function call to provide this type of functionality. Other than that its pretty clear-cut, with most other modern browsers supporting the download attribute.

To generate a self-signed X509 certificate out of the box with vanilla .NET and C#, you will need to Platform Invoke the Cryptography library in Windows. You don’t need to use any third party libraries for this, Windows is perfectly capable of tackling this task for you. Wired up for using the SHA512 hashing algorithm, here is the code to make the magic happen:

This should resolve any Secure Connection Failed errors if you are seeing these on your development machines, but also, its not something you should do for any website out there, because it can easily compromise security.