Skip to content

Instantly share code, notes, and snippets.

Avatar

Randy Burden randyburden

View GitHub Profile
@randyburden
randyburden / CodeMirror_CurlyBraceWrappedText_Demo
Created Oct 21, 2014
CodeMirror Custom Syntax Highlighter for highlighting double curly brace wrapped text aka Mustache / Handlebars
View CodeMirror_CurlyBraceWrappedText_Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CurlyBraceWrappedText Demo</title>
<style type="text/css">
.CodeMirror {border: 1px solid black;}
.cm-CurlyBraceWrappedText {color: #CC0000; font-weight: bold;}
</style>
<link rel="stylesheet" href="css/codemirror.css">
@randyburden
randyburden / BooleanJsonConverter.cs
Created Jul 4, 2013
A Json.NET JsonConverter that can handle converting the following values into boolean values: true, false, yes, no, y, n, 1, 0.
View BooleanJsonConverter.cs
using System;
using Newtonsoft.Json;
namespace JsonConverters
{
/// <summary>
/// Handles converting JSON string values into a C# boolean data type.
/// </summary>
public class BooleanJsonConverter : JsonConverter
{
@randyburden
randyburden / Add_Yourself_As_A_Sql_Server_Express_SysAdmin.txt
Created Nov 28, 2012
Add Yourself as a SQL Server Express SysAdmin
View Add_Yourself_As_A_Sql_Server_Express_SysAdmin.txt
Adding Yourself as SQL Server Express SysAdmin
----------------------------------------------
Problem:
The help desk installs SQL Server on our developer machines under their own user accounts meaning you aren't a
sysadmin on your own SQL Server Express instance which in turn means you can't create a new database.
Solution:
@randyburden
randyburden / ValidateOrderByClause.cs
Created Oct 19, 2017
C# method to validate a string-based OrderBy clause to be used in a dynamic LINQ statement
View ValidateOrderByClause.cs
internal void ValidateOrderByClause(string orderBy, string[] supportedOrderByFields)
{
if (!string.IsNullOrWhiteSpace(orderBy))
{
var orderBys = orderBy.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (var orderByClause in orderBys)
{
var orderByClauseParts = orderByClause.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
var orderByClauseField = orderByClauseParts[0];
@randyburden
randyburden / TimeSpanHelper.cs
Last active Mar 4, 2019
TimeSpan helper and extension method for creating a formatted string of a given TimeSpan. Supports up to microsecond resolution. Also includes some unit tests.
View TimeSpanHelper.cs
using System;
using NUnit.Framework;
namespace Helpers
{
/// <summary>
/// TimeSpan Helper.
/// </summary>
public static class TimeSpanHelper
{
@randyburden
randyburden / OwinRequestExtensions.cs
Created Oct 22, 2014
OwinRequest extensions for getting query string, form body, and header parameters as Dictionary<string,string>
View OwinRequestExtensions.cs
/// <summary>
/// Owin Request extensions.
/// </summary>
public static class OwinRequestExtensions
{
/// <summary>
/// Gets the combined request parameters from the form body, query string, and request headers.
/// </summary>
/// <param name="request">Owin request.</param>
/// <returns>Dictionary of combined form body, query string, and request headers.</returns>
@randyburden
randyburden / ConnectionStringHelper.cs
Created Mar 21, 2018
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
View ConnectionStringHelper.cs
using System;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Utilities
{
/// <summary>
@randyburden
randyburden / RegisterWindowsScheduledTasks.ps1
Created Nov 8, 2017
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.
View RegisterWindowsScheduledTasks.ps1
##########################################
### 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 / OracleOptionalDateRangeQuery.sql
Created Nov 6, 2017
Oracle PL/SQL example of a query with an optional date range
View OracleOptionalDateRangeQuery.sql
/* 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 / ConfigurationManagerOptionsProvider.cs
Last active Sep 29, 2017
C# strongly named application settings/options implementation. Can be used with Dependency Injection or with static helper method AppSettingsOptionsProvider<T>.Bind();.
View ConfigurationManagerOptionsProvider.cs
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>
You can’t perform that action at this time.