Skip to content

Instantly share code, notes, and snippets.

View aaronhoffman's full-sized avatar

Aaron Hoffman aaronhoffman

View GitHub Profile
@aaronhoffman
aaronhoffman / datemath.cs
Created October 22, 2015 20:49
SQL Server vs .NET DateTime Leap Year Arithmetic
var leapPrevMinus = new DateTime(2011, 2, 27);
var leapPrev = new DateTime(2011, 2, 28);
var leapPrevPlus = new DateTime(2011, 3, 1);
var leapDayMinusMinus = new DateTime(2012, 2, 27);
var leapDayMinus = new DateTime(2012, 2, 28);
var leapDay = new DateTime(2012, 2, 29);
var leapDayPlus = new DateTime(2012, 3, 1);
var leapNextMinus = new DateTime(2013, 2, 27);
@aaronhoffman
aaronhoffman / group-by-each-column.sql
Created March 15, 2016 21:02
Generate SQL Statements to Group By Each Column of Table Separately
declare @table_name varchar(200) = 'dbo.mytablename'
select
'select ' + c.name + ', count(1) cnt from ' + @table_name + ' group by ' + c.name + ' order by 2 '
from sys.columns c
where c.object_id = object_id(@table_name)
@aaronhoffman
aaronhoffman / CDT
Created March 22, 2016 21:38
UTC Time to Central
UTC 24 12
--- -- --
00 19 07PM
01 20 08
02 21 09
03 22 10
04 23 11
05 00 12AM
06 01 01
07 02 02
@aaronhoffman
aaronhoffman / UtmZoneBoundingBox.cs
Last active April 20, 2016 16:21
WGS84 Longitude and Latitude Bounding Boxes for UTM Zones
public class UtmZoneInfo
{
public string UtmZoneNumber { get; set; }
public string UtmZoneLetter { get; set; }
public string UtmZone { get; set; }
public double LongitudeCenter { get; set; }
public double LongitudeMinimum { get; set; }
public double LongitudeMaximum { get; set; }
@aaronhoffman
aaronhoffman / PrettyPrintArrayOfArrays.cs
Last active July 26, 2016 14:52
Pretty Print Array of Arrays
public string PrettyPrintArrayOfArrays(int[][] arrayOfArrays)
{
if (arrayOfArrays == null)
return "";
var prettyArrays = new string[arrayOfArrays.Length];
for (int i = 0; i < arrayOfArrays.Length; i++)
{
prettyArrays[i] = "[" + String.Join(",", arrayOfArrays[i]) + "]";
@aaronhoffman
aaronhoffman / sp-space-used-each-table.sql
Created August 5, 2016 17:16
Get size of each table in SQL Server Database
-- sp spaced used each table http://stackoverflow.com/a/7892361/47226
-- must be temp table, table var not referenceable by SP
create table #TableSize (
Name varchar(255),
[rows] int,
reserved varchar(255),
data varchar(255),
index_size varchar(255),
unused varchar(255))
@aaronhoffman
aaronhoffman / web.config
Created August 8, 2016 18:19
asp.net web.config redirect to https
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect_to_https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="localhost" negate="true" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
@aaronhoffman
aaronhoffman / Global.asax.cs
Last active August 9, 2016 19:49
ASP.NET MVC 4 Membership, Users, Passwords, Roles, Profile, Authentication, Authorization http://aaron-hoffman.blogspot.com/2013/02/aspnet-mvc-4-membership-users-passwords.html
// The using below is needed for "UsersContext" - it will be relative to your project namespace
using MvcApplication1.Models;
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Threading;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
@aaronhoffman
aaronhoffman / OpmFedScope.sql
Last active September 8, 2016 19:32
SQL Script to Create OpmFedScope Database
CREATE DATABASE [OpmFedScope]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'OpmFedScope', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\OpmFedScope.mdf' , SIZE = 134144KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'OpmFedScope_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\OpmFedScope_log.ldf' , SIZE = 15040KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [OpmFedScope] SET COMPATIBILITY_LEVEL = 120
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
@aaronhoffman
aaronhoffman / StateCodes.cs
Created October 17, 2016 21:18
State Codes United States
var stateCodes = new Dictionary<string, string>()
{
{"AL", "ALABAMA"},
{"AK", "ALASKA"},
{"AZ", "ARIZONA"},
{"AR", "ARKANSAS"},
{"CA", "CALIFORNIA"},
{"CO", "COLORADO"},
{"CT", "CONNECTICUT"},
{"DE", "DELAWARE"},