How to check a checkbox with jQuery

To check a checkbox with jQuery you can use the snippet below.

Sample jQuery 1.6+

$('.Checkbox').prop('checked', true); //change true to false to set checked state to false

Sample jQuery 1.5 and below

$('.Checkbox').attr('checked', true);  //change true to false to set checked state to false

Please rate this snippet

How to Shuffle a List in C# and VB.NET

To Shuffle a List in C# and VB.NET you can use the snippet below.

Sample C#

public static IList<T> ShuffleIList<T>(IList<T> inputList)
{
	var cryptoServiceProvider = new RNGCryptoServiceProvider();
	var count = inputList.Count;
	while (count > 1)
	{
		var bytes = new byte[1];
		do cryptoServiceProvider.GetBytes(bytes);
		while (!(bytes[0] < count * (Byte.MaxValue / count)));
		var index = (bytes[0] % count);
		count--;
		var input = inputList[index];
		inputList[index] = inputList[count];
		inputList[count] = input;
	}
	return inputList;
}

Sample VB.NET

Public Shared Function ShuffleIList(Of T)(inputList As IList(Of T)) As IList(Of T)
	Dim cryptoServiceProvider = New RNGCryptoServiceProvider()
	Dim count = inputList.Count
	While count > 1
		Dim bytes = New Byte(0) {}
		Do
			cryptoServiceProvider.GetBytes(bytes)
		Loop While Not (bytes(0) < count * ([Byte].MaxValue / count))
		Dim index = (bytes(0) Mod count)
		count -= 1
		Dim input = inputList(index)
		inputList(index) = inputList(count)
		inputList(count) = input
	End While
	Return inputList
End Function

Please rate this snippet

How to flip a image in C# and VB.NET

To flip a image in C# and VB.NET you can use the following snippet.

Sample C#

public enum FlipMode
{
	Horizontal = 0,
	Vertical = 1,
	Both = 2
}

public Image FlipImage(Image myImage, FlipMode myFlipmode)
{
	var ret = myImage;
	switch (myFlipmode)
	{
		case FlipMode.Horizontal:
			ret.RotateFlip(RotateFlipType.RotateNoneFlipX);
			break;
		case FlipMode.Vertical:
			ret.RotateFlip(RotateFlipType.RotateNoneFlipY);
			break;
		case FlipMode.Both:
			ret.RotateFlip(RotateFlipType.RotateNoneFlipXY);
			break;
	}
	return ret;
}

Sample Vb.NET

Public Enum FlipMode
	Horizontal = 0
	Vertical = 1
	Both = 2
End Enum

Public Function FlipImage(myImage As Image, myFlipmode As FlipMode) As Image
	Dim ret = myImage
	Select Case myFlipmode
		Case FlipMode.Horizontal
			ret.RotateFlip(RotateFlipType.RotateNoneFlipX)
			Exit Select
		Case FlipMode.Vertical
			ret.RotateFlip(RotateFlipType.RotateNoneFlipY)
			Exit Select
		Case FlipMode.Both
			ret.RotateFlip(RotateFlipType.RotateNoneFlipXY)
			Exit Select
	End Select
	Return ret
End Function

Please rate this snippet

How to flip a coin in C# or VB.NET

To flip a coin in C# or VB.NET you just need to use this extension method on a instance of random.

Extension Method C#

public static bool FlipCoin(this Random rand)
{
    return rand.Next(2) == 0;
}

Extension Method VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Function FlipCoin(rand As Random) As Boolean
	Return rand.Next(2) = 0
End Function

Please rate this snippet