Skip to content

Instantly share code, notes, and snippets.

View randyburden's full-sized avatar

Randy Burden randyburden

View GitHub Profile
@randyburden
randyburden / NameGenerator.cs
Created September 5, 2016 06:38
A C# helper class for generating random first names and random last names.
using System;
namespace Helpers
{
/// <summary>
/// Name Generator.
/// </summary>
public static class NameGenerator
{
// List of the top 40 boy and girl baby names of 2016
@randyburden
randyburden / SocialSecurityNumberGenerator.cs
Created September 5, 2016 06:41
A C# helper class for generating random USA Social Security numbers. This was used in automated unit tests.
using System;
namespace Helpers
{
/// <summary>
/// Social Security Number Generator.
/// </summary>
public static class SocialSecurityNumberGenerator
{
/// <summary>
@randyburden
randyburden / InsertWithOracleArrayBinding.cs
Last active August 15, 2017 00:45
Insert list into a database table using Oracle array binding (a type of bulk insert)
/// <summary>
/// Insert list into a database table using Oracle array binding (a type of bulk insert).
/// </summary>
/// <typeparam name="T">Type of data in list.</typeparam>
/// <param name="listOfData">List to insert.</param>
/// <param name="tableName">Table name.</param>
/// <returns>Rows affected.</returns>
public int Insert<T>(List<T> listOfData, string tableName) where T : class, new()
{
try
@randyburden
randyburden / SqlServerAuditColumns.sql
Created August 17, 2017 17:27
Standard set of SQL Server audit columns with default constraints
CREATE TABLE TableName
(
TableNameId INT NOT NULL IDENTITY(1,1),
/* Other columns */
CreatedDate DATETIME2 NOT NULL CONSTRAINT [DF_TableName_CreatedDate] DEFAULT (GETDATE()),
CreatedBy VARCHAR(100) NOT NULL CONSTRAINT [DF_TableName_CreatedBy] DEFAULT (SUSER_SNAME()),
CreatedByHostName VARCHAR(100) NOT NULL CONSTRAINT [DF_TableName_CreatedByHostName] DEFAULT (HOST_NAME()),
ModifiedDate DATETIME2 NOT NULL CONSTRAINT [DF_TableName_ModifiedDate] DEFAULT (GETDATE()),
ModifiedBy VARCHAR(100) NOT NULL CONSTRAINT [DF_TableName_ModifiedBy] DEFAULT (SUSER_SNAME()),
ModifiedByHostName VARCHAR(100) NOT NULL CONSTRAINT [DF_TableName_ModifiedByHostName] DEFAULT (HOST_NAME())
@randyburden
randyburden / TFS_Compare_Filter_Criteria.txt
Created September 6, 2017 22:07
Filter criteria for the Compare feature in Visual Studio's Source Control Explorer for TFS TF Version Control
!*.csproj.user;!UpgradeLog.htm;!*.vspscc;!packages\;!bin\;!bld\;!ClientBin\;!Debug\;!obj\;!AppPackages\;!Release\;!TestResults\;!*.*~!*.appx!*.appxrecipe;!*.cache!*.cer!*.dbmdl!*.dll!*.docstates!*.docstates.suo;!*.err!*.exe!*.ilk!*.ipch!*.lastbuildstate!*.lce!*.ldf!*.lib!*.log!*.mdf!*.msscci!*.ncb!*.obj!*.opensdf!*.pch!*.pdb!*.pri!*.res!*.resources!*.sdf!*.suo!*.swp!*.temp!*.tfOrig*!*.tlog!*.tmp!*.trx!*.user!*.unsuccessfulbuild!*.v11.suo!*.vcxproj.user!*.vsix!*.vsmdi!*.vspscc!*.vssettings!*.vssscc!*.wrn!*.xap;!.metadata\
@randyburden
randyburden / EntityFrameworkMigrationTests.cs
Created September 11, 2017 19:33
C# test class with 2 Entity Framework-related tests intended to verify that there are no pending migrations and no migrations that need to be created.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data.Entity.Migrations;
using System.Data.Entity.Migrations.Design;
using System.Diagnostics;
using System.Linq;
namespace YabbaDabbaDoo
{
[TestClass]
public class EntityFrameworkMigrationTests
@randyburden
randyburden / ConfigurationManagerOptionsProvider.cs
Last active September 29, 2017 17:05
C# strongly named application settings/options implementation. Can be used with Dependency Injection or with static helper method AppSettingsOptionsProvider<T>.Bind();.
using System;
using System.Configuration;
using System.Reflection;
namespace Utilities.Options
{
/// <summary>
/// Uses <see cref="ConfigurationManager"/> to populate options.
/// Finds setting names/keys by <see cref="OptionNameAttribute"/>, {PropertyName}, or {ClassName}.{PropertyName}.
/// </summary>
@randyburden
randyburden / OracleOptionalDateRangeQuery.sql
Created November 6, 2017 22:46
Oracle PL/SQL example of a query with an optional date range
/* Oracle PL/SQL example of a query with an optional date range */
SET SERVEROUTPUT ON;
DECLARE
StartDate DATE := NULL;
EndDate DATE := NULL;
--StartDate DATE := TO_DATE ('01/01/2017', 'mm/dd/yyyy');
--EndDate DATE := TO_DATE ('02/01/2017', 'mm/dd/yyyy');
RecordCount NUMBER;
BEGIN
SELECT COUNT(*)
@randyburden
randyburden / RegisterWindowsScheduledTasks.ps1
Created November 8, 2017 15:02
Registers Windows Scheduled Tasks. Taken from a working example I created that ran as a post-deployment step. It also cleans up old deployment directories.
##########################################
### Registers Windows Scheduled Tasks ###
##########################################
<###############################################################################################################
Notes:
- This example was from a working solution I created where this script was run as a post-deploy step for a
console application that served as the entry point for multiple scheduled tasks that could be executed
by supplying the task name.
@randyburden
randyburden / ConnectionStringHelper.cs
Created March 21, 2018 19:40
C# Connection String helper that can inject a custom application name pattern into a connection string. Custom application format is: <AssemblyName>, Version=X.X.X.X, BuildDate=MM/DD/YYYY 12:00 PM
using System;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Utilities
{
/// <summary>