Category: Code

Setting Manual Exposure in OpenCV

11 June, 2017 (14:01) | Snippets, Programming, Code, Python, OpenCV

In OpenCV, you can set the exposure for your camera manually by using the VideoCapture::set method. What isn’t obvious is what value to pass in for it. I have experimented with various webcams and the below settings seem to be accurate enough. Not all cameras allow setting the exposure programatically, so if […]

Android: Simple Example of Page Transition Using ViewPager

17 May, 2015 (18:54) | Java, Snippets, Programming, Code, Android

The ViewPager class built in to the Android SDK is a simple method of showing an animated transition between two views. For example, turning a page, or a calendar scrolling through months. This functionality can be added with only a few lines of code. Below I present an example containing pretty much […]

A Quick Snippet for Drawing Images in Java

2 October, 2014 (02:22) | Java, Snippets, Programming, Code, Android

Java does not have the best built-in tools in the world for drawing images, but it’s still useful for many purposes. Below is just a snippet on getting started drawing in Java. For more information on what’s available see the Java Graphics class reference.

BufferedImage i = new BufferedImage(500, 500,BufferedImage.TYPE_INT_RGB);
Graphics g=i.createGraphics();
g.drawLine(0, 0, 500, 500);
g.drawString(”This […]

A basic 3d to 2d projection

2 October, 2014 (02:09) | .Net, Programming, C#, Code, Computer Science

Developing an actual 3D engine is an incredible amount of work, and including a 3D library in your project can add a considerable amount of bloat to your project. Fortunately you can implement some very simple 3D projections in just a couple of lines of code, and they are not computationally intensive. There […]

Why you should return “this” from your setter methods.

26 September, 2014 (21:35) | .Net, Java, Snippets, Programming, C#, Code

Fortunately most API designers know to use this technique, but it’s still pretty common to find some that do not. It’s generally good practice, that when writing a setter method for a class, that you return the object’s “this” rather than “void”. The reason is that it allows a user of your class […]

Simple encryption and decryption of a string in c#

20 August, 2010 (12:32) | Cryptography, Security, Snippets, Programming, C#, Code

Here are some routines which are designed for simple use of Rijndael in C#. I’ve combined a test function in the class for simplicity of showing it’s use.

private static byte[] salt = Encoding.ASCII.GetBytes(”somerandomstuff”);

public static string Encrypt(string plainText, string […]

Implementation of DES in C

16 March, 2008 (23:31) | Cryptography, Security, Code, Computer Science