Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Hoffman aaronhoffman

View GitHub Profile
@aaronhoffman
aaronhoffman / datemath.cs
Created Oct 22, 2015
SQL Server vs .NET DateTime Leap Year Arithmetic
View datemath.cs
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 Nov 17, 2017
PowerShell - List File Line Count For Files in a Directory that Match a Given Pattern
View count-file-lines.ps1
# 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 Feb 23, 2016
Convert SQL Server Management Studio SSMS Varbinary Column Output to Byte Array C#
View ConvertVarbinaryToByteArray.cs
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
Get Public IP Address using Powershell
View get-public-ip-address.ps1
$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 Jan 15, 2019
Lambda function to process a Amazon SES Delivery Notification message from a SNS Topic into a DynamoDB Table
View aws-sns-event-template-with-actual-ses-deliverynotification-sns-message
{
"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 Mar 15, 2016
Generate SQL Statements to Group By Each Column of Table Separately
View group-by-each-column.sql
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 Mar 22, 2016
UTC Time to Central
View CDT
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 Apr 20, 2016
WGS84 Longitude and Latitude Bounding Boxes for UTM Zones
View UtmZoneBoundingBox.cs
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
Convert WGS84, latitude, longitude, to Web Mercator, Google Maps, Bing Maps, Pixel Coordinates
View TileSystem.cs
// 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 Apr 26, 2018
Custom Azure WebJob TraceWriter For SQL Server
View Program.cs
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}}"));
You can’t perform that action at this time.