Skip to content

Instantly share code, notes, and snippets.

@FaronBracy
FaronBracy / RandomString.cs
Last active August 29, 2015 14:06
Create a Crypto Random String
string RandomString(int length, string allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") {
if (length < 0) throw new ArgumentOutOfRangeException("length", "length cannot be less than zero.");
if (string.IsNullOrEmpty(allowedChars)) throw new ArgumentException("allowedChars may not be empty.");
const int byteSize = 0x100;
var allowedCharSet = new HashSet<char>(allowedChars).ToArray();
if (byteSize < allowedCharSet.Length) throw new ArgumentException(String.Format("allowedChars may contain no more than {0} characters.", byteSize));
// Guid.NewGuid and System.Random are not particularly random. By using a
// cryptographically-secure random number generator, the caller is always
@FaronBracy
FaronBracy / gist:f295950ce4416cdf0ef1
Created August 26, 2014 12:29
Jon Skeet's Clever Enum
public class MyCleverEnum
{
public static readonly MyCleverEnum First = new FirstCleverEnum();
public static readonly MyCleverEnum Second = new SecondCleverEnum();
// Can only be called by this type *and nested types*
private MyCleverEnum()
{
}
@FaronBracy
FaronBracy / gist:25c77fc572794f7bcfe4
Created June 3, 2014 21:05
Camera class for XNA or MonoGame
using Microsoft.Xna.Framework;
namespace DreamersDesign
{
public class Camera
{
public Camera( int viewportWidth, int viewportHeight, Vector2 cameraPosition, ClockManager clockManager )
{
ViewportWidth = viewportWidth;
ViewportHeight = viewportHeight;
DECLARE @startId bigint;
DECLARE @endId bigint;
SET @startId = 0
SET @endId = 42327636
WHILE (@startId > @endId)
BEGIN
UPDATE storage.StorageInformation
SET LocationTypeId = 0, BackupLocationTypeId = 0
WHERE @startId <= StorageId and StorageId < @startId + 100000 and LocationTypeId IS NULL;