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 / count-file-lines.ps1
Last active November 17, 2017 16:08
PowerShell - List File Line Count For Files in a Directory that Match a Given Pattern
# List File Line Count For Files In A Directory That Match A Given Pattern
$path = "C:\path\"
$filter = "*match*.csv"
Write-Output $path
Write-Output $filter
$files = Get-ChildItem -Path $path -Filter $filter
$files | ForEach-Object {
# Write-Output $_.FullName
Get-Content -Path ($path + $_) | Measure-Object -Line | Select-Object -ExpandProperty Lines | Write-Output
}
@aaronhoffman
aaronhoffman / ConvertVarbinaryToByteArray.cs
Created February 23, 2016 00:58
Convert SQL Server Management Studio SSMS Varbinary Column Output to Byte Array C#
static void Main(string[] args)
{
// read input from local file (could also pass in via args)
var hexInput = File.ReadAllText("hexInput.txt");
// convert to binary, strip off first two chars 'Ox'
var byteArray = StringToByteArray(hexInput.Substring(2));
// write bytes to file
File.WriteAllBytes("output.file", byteArray);
@aaronhoffman
aaronhoffman / get-public-ip-address.ps1
Last active May 22, 2018 15:53
Get Public IP Address using Powershell
$url = "https://www.icanhazip.com/"
$webclient = New-Object System.Net.WebClient
$ipResp = $webclient.DownloadString($url)
$ip = $ipResp.ToString().Trim()
Write-Output $ip
@aaronhoffman
aaronhoffman / aws-sns-event-template-with-actual-ses-deliverynotification-sns-message
Last active January 15, 2019 19:04
Lambda function to process a Amazon SES Delivery Notification message from a SNS Topic into a DynamoDB Table
{
"Records": [
{
"EventSource":"aws:sns",
"EventVersion":"1.0",
"EventSubscriptionArn":"arn:aws:sns:us-west-2:xxxx:xxxx",
"Sns": {
"Type":"Notification",
"MessageId":"88B1B251-2E92-4FC3-BFAA-E3BBD0BAB10A",
"TopicArn":"arn:aws:sns:us-west-2:881222951025:survey-tool-ses-delivery",
@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 / TileSystem.cs
Created May 26, 2016 00:53
Convert WGS84, latitude, longitude, to Web Mercator, Google Maps, Bing Maps, Pixel Coordinates
// source: https://msdn.microsoft.com/en-us/library/bb259689.aspx
//------------------------------------------------------------------------------
// <copyright company="Microsoft">
// Copyright (c) 2006-2009 Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Text;
@aaronhoffman
aaronhoffman / Program.cs
Last active April 26, 2018 12:23
Custom Azure WebJob TraceWriter For SQL Server
static void Main()
{
var config = new JobHostConfiguration();
// Log Console.Out to SQL using custom TraceWriter
// Note: Need to update default Microsoft.Azure.WebJobs package for config.Tracing.Tracers to be exposed/available
config.Tracing.Tracers.Add(new SqlTraceWriter(
TraceLevel.Info,
"{{SqlConnectionString}}",
"{{LogTableName}}"));