Skip to content

Instantly share code, notes, and snippets.

View jeremykdev's full-sized avatar

Jeremy Knue jeremykdev

View GitHub Profile
@jeremykdev
jeremykdev / MsSqlDataTypeExtension.cs
Last active June 15, 2021 00:18
Collection of C# extension methods to check for compability between .NET value and Microsoft SQL 2005+ data type
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace net.datacowboy
{
//collection of extension methods to check for compability between .NET value and Microsoft SQL 2005+ data type
public static class MsSqlDataTypeExtension
@jeremykdev
jeremykdev / StringExtensionMethods.cs
Created July 11, 2013 20:28
Collection of extension methods for working with strings in .NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace net.datacowboy
{
public static class StringExtensionMethods
{
/// <summary>
@jeremykdev
jeremykdev / DateTimeExtensionMethods.cs
Last active December 21, 2015 10:48
Collection of extension methods for working DateTime value in .NET.
public static class DateTimeExtensionMethods
{
//get first day of month for a given date
public static DateTime FirstDayOfMonth(this DateTime input)
{
return new DateTime(input.Year, input.Month, 1);
}
//get last day of month for a given date
public static DateTime LastDayOfMonth(this DateTime input)
@jeremykdev
jeremykdev / UsStateInformation.cs
Created September 12, 2013 15:09
Collection of U.S. state information
//average lat/lon based on http://dev.maxmind.com/geoip/legacy/codes/state_latlon/
public class UsStateInformation
{
public string Name { get; set; }
public string Abbreviation { get; set; }
public decimal Latitude { get; set; }
@jeremykdev
jeremykdev / Log4NetConfigRollingFileAppenderDaily
Last active December 24, 2015 00:29
Log4Net configuration for a rolling file appender with a new file each day.
<log4net>
<appender name="rollFile" type="log4net.Appender.RollingFileAppender">
<file value="C:\path\log" />
<rollingStyle value="Date" />
<datePattern value="yyyy-MM-dd'.txt'" /> <!-- added .txt to end of date pattern so that the file extension txt will be used, note that .txt is escaped by single quotes -->
<appendToFile value="true" />
<staticLogFileName value="false" />
@jeremykdev
jeremykdev / UsStateTwoCharacterAbbreviationAttribute.cs
Created December 5, 2013 19:44
Custom data annotation validation attribute to validate that data is a two character U.S. state abbreviation.
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
sealed public class UsStateTwoCharacterAbbreviationAttribute : ValidationAttribute
{
private readonly string[] validStateAbbr = new string[] { "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY" };
@jeremykdev
jeremykdev / Query for Table Meta Data.sql
Last active August 29, 2015 13:55
Query for table meta data for SQL server database. Will show description for columns created in SQL managment studio visual designer. These comments are stored as 'MS_Description'. To show other extended properties change the EP.name value in the LEFT JOIN clause.
SELECT
S.name AS SchemaName
, T.name AS TableName
, C.name AS ColumnName
, EP.value AS ColumnDescription
, Y.name AS DataType
, C.max_length AS MaximumLength
, C.is_nullable AS AllowsNulls
, C.precision AS Precision
, C.scale AS Scale
@jeremykdev
jeremykdev / SqlServerDataTypeParameterMappingExtension.cs
Created January 30, 2014 19:41
Collection of extension methods to convert .NET objects/values to equivalent parameters for MS SQL Server. For use with ORMs such as NPoco or PetaPoco to provide explicit conversion to parameter rather than defaults such as all strings being treated as nvarchar(8000) fields.
using System;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Collection of extension methods to convert .NET objects/values to equivalent parameters for MS SQL Server
/// For use with ORMs such as NPoco or PetaPoco to provide explicit conversion to parameter rather than defaults such as all strings being treated as nvarchar(8000) fields
/// </summary>
@jeremykdev
jeremykdev / generate-statements-drop-all-foreign-keys.sql
Created March 31, 2014 16:33
Generate SQL statements to drop all foreign keys in a Microsoft SQL Server database
SELECT 'ALTER TABLE ' + QUOTENAME(S.name) + '.' + QUOTENAME(T.name) + ' DROP CONSTRAINT ' + QUOTENAME(FK.name) + ';'
FROM sys.foreign_keys AS FK
INNER JOIN sys.tables AS T
ON ( Fk.parent_object_id = T.object_id )
INNER JOIN sys.schemas AS S
ON ( T.schema_id = S.schema_id )
ORDER BY S.name, T.name, FK.name;
@jeremykdev
jeremykdev / ReportSubscriptionByEmailAddress.sql
Created April 22, 2014 21:28
Query to find reports which are scheduled to be send to a given email address using a subscription in Microsoft SQL Server Reporting Services..
USE ReportServer;
SELECT C.Path
FROM dbo.Subscriptions AS S
INNER JOIN dbo.Catalog AS C
ON ( S.Report_OID = C.ItemID )
WHERE ExtensionSettings LIKE '%[email protected]%'
ORDER BY C.Path;