Skip to content

Instantly share code, notes, and snippets.

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;
@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;
@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 / 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 / EnumExtensions.cs
Created March 8, 2015 02:25
Some extension methods for enums that are useful for older versions of .NET
public static class EnumExtensions
{
private static void CheckIsEnum<T>(bool withFlags)
{
if (!typeof(T).IsEnum)
throw new ArgumentException(string.Format("Type '{0}' is not an enum", typeof(T).FullName));
if (withFlags && !Attribute.IsDefined(typeof(T), typeof(FlagsAttribute)))
throw new ArgumentException(string.Format("Type '{0}' doesn't have the 'Flags' attribute", typeof(T).FullName));
}
@FaronBracy
FaronBracy / ProductVersion.sql
Created March 18, 2015 20:25
Create a project version table
-- Create new table for keeping track of all the versions of project files
CREATE TABLE wa.ProjectVersion(
ProjectVersionId int IDENTITY(1,1) NOT NULL,
ProjectId int NOT NULL,
DateCreated datetime2(7) NOT NULL,
ProjectFileId varchar(50) NOT NULL
PRIMARY KEY CLUSTERED
(
ProjectVersionId ASC
)
@FaronBracy
FaronBracy / InterfaceDrawingSample.cs
Created March 12, 2016 21:12
Example of drawing interface elements with MonoGame that do not transform
// Draw everything that will be transformed with the camera like the player, cells, etc.
_spriteBatch.Begin( SpriteSortMode.BackToFront, null, SamplerState.PointClamp, null, null, null, Camera.TranslationMatrix );
for ( int x = minX; x < maxX; x++ )
{
for ( int y = minY; y < maxY; y++ )
{
bool isVisible = Global.GameModel.Map.Properties[x + y * Global.GameModel.Map.Width] == CellProperties.Visible;
Tiles[x, y].Draw( _spriteBatch, SpriteSheet, new Vector2( x * Global.CellWidth, y * Global.CellHeight ), isVisible );
}
@FaronBracy
FaronBracy / xd2md.cs
Created January 10, 2017 17:55 — forked from formix/xd2md.cs
Generates Markdown From VisualSturio XML documentation files
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
namespace Formix.Utils
{
class Program
@FaronBracy
FaronBracy / Program.cs
Created March 2, 2019 13:59
Example - Cells further away in FOV are dimmer
public class Program
{
private static double DistanceBetween( int x1, int y1, int x2, int y2 )
{
return Math.Sqrt( Math.Pow( x2 - x1, 2 ) + Math.Pow( y2 - y1, 2 ) );
}
private static int WalkingDistanceBetween( int x1, int y1, int x2, int y2 )
{
return Math.Abs( x2 - x1 ) + Math.Abs( y2 - y1 );
@FaronBracy
FaronBracy / warrior.js
Created March 26, 2019 00:30
Warrior JS code
let exploreState = {
execute: function(player,warrior) {
if (player.sense(warrior) === 'empty') {
warrior.walk(player.direction);
}
else if (player.sense(warrior) === 'wall') {
warrior.pivot();
}
else if (player.sense(warrior) === 'enemy') {
warrior.think("It's time to kick ass and chew bubble gum...");