Skip to content

Instantly share code, notes, and snippets.

View caseywatson's full-sized avatar
🌳
Using my OC(d) to turn big mental trees into perfect toothpicks.

Casey Watson ☁️ caseywatson

🌳
Using my OC(d) to turn big mental trees into perfect toothpicks.
View GitHub Profile
@caseywatson
caseywatson / MerryChristmasFriends.cs
Created December 25, 2012 15:23
Merry Christmas Friends!
public void string SingChristmasCarol()
{
var carolBuilder = new StringBuilder();
carolBuilder.AppendLine("Tis the season to be jolly!");
carolBuilder.AppendLine(SingChorus());
carolBuilder.AppendLine("Deck the halls with boughs of holly!");
carolBuilder.AppendLine(SingChorus());
carolBuilder.AppendLine("Don we now our gay apparel!");
carolBuilder.AppendLine(SingChorus());
@caseywatson
caseywatson / DistinctExtensions.cs
Created April 10, 2013 21:00
LINQ operators that require an IEqualityComparer<T> suck. Do this instead.
using System;
using System.Collections.Generic;
namespace SpaceX.CDL.Core
{
public class FunctionalEqualityComparer<T> : IEqualityComparer<T>
{
private readonly Func<T, T, bool> comparisonFunction;
public FunctionalEqualityComparer(Func<T, T, bool> comparisonFunction)
public static bool IsValidXmlDocument(this string source)
{
try
{
var document = XDocument.Parse(source);
return true;
}
catch
{
return false;
@caseywatson
caseywatson / PluralizationExtensions.cs
Created May 27, 2013 21:08
PluralizationService + Extension Methods = AWESOME
using System;
using System.Data.Entity.Design.PluralizationServices;
using System.Globalization;
using System.Text;
namespace Modelio.Core
{
public static class StringExtensions
{
public static string Pluralize(this string source)
@caseywatson
caseywatson / RandomGeo.sql
Created June 25, 2013 22:25
This code will generate random points given a min and max ID, min and max X coordinate and min and max Y coordinate using SQL geospatial data types.
DECLARE @min BIGINT = 9989
DECLARE @max BIGINT = 21899
DECLARE @minX FLOAT = -118.3876873
DECLARE @maxX FLOAT = -87.55091344
DECLARE @minY FLOAT = 30.195573
DECLARE @maxY FLOAT = 42.010291
WHILE (@min < @max) BEGIN
@caseywatson
caseywatson / DownloadUdf.cs
Created August 8, 2013 21:54
This SQL CLR UDF will download data given a URL and return a VarBinary. Helpful in cases where you are moving binary objects from the database to some other location (in my case, Azure) with minimal impact.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Net;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
@caseywatson
caseywatson / Resharper Type Members Layout
Created July 9, 2014 17:50
Resharper Type Members Layout Patterns
<Patterns xmlns="urn:shemas-jetbrains-com:member-reordering-patterns">
<!-- Do not reorder COM interfaces -->
<Pattern>
<Match>
<And Weight="100">
<Kind Is="interface" />
<HasAttribute CLRName="System.Runtime.InteropServices.InterfaceTypeAttribute" />
</And>
</Match>
@caseywatson
caseywatson / OnlyOne
Last active August 29, 2015 14:17
OnlyOne Extension Method
public static bool OnlyOne<T>(this IEnumerable<T> source, Func<T, bool> condition = null)
{
return (source.Count(condition ?? (t => true)) == 1);
}
@caseywatson
caseywatson / None
Created March 14, 2015 21:55
None Extension Method
public static bool None<T>(this IEnumerable<T> source, Func<T, bool> condition = null)
{
return (source.Any(condition ?? (t => true)) == false);
}
@caseywatson
caseywatson / FunctionalStringSplitExtension.cs
Created August 26, 2016 14:36
Similar to C# string.Split but splits on a condition, not a character array. Great for quick and easy string tokenization.
using System;
using System.Collections.Generic;
using System.Text;
namespace Extensions
{
public static class FunctionalStringSplitExtension
{
public static string[] Split(this string source, Func<char, bool> splitOn)
{