Skip to content

Instantly share code, notes, and snippets.

View aaronhoffman's full-sized avatar

Aaron Hoffman aaronhoffman

View GitHub Profile
@aaronhoffman
aaronhoffman / RSACryptoServiceProviderHelper.cs
Created February 11, 2020 12:52
Convert RSACryptoServiceProvider ToXmlString RsaXML W3C XKMS format to Public Private key PEM base64 string
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
public class RSACryptoServiceProviderHelper
{
// code from here:
// - https://stackoverflow.com/questions/23734792/c-sharp-export-private-public-rsa-key-from-rsacryptoserviceprovider-to-pem-strin
// - https://stackoverflow.com/questions/28406888/c-sharp-rsa-public-key-output-not-correct/28407693#28407693
@aaronhoffman
aaronhoffman / AesKeyGenerator.cs
Last active October 15, 2019 21:19
Generate Random AES Encryption Key
public static class AesKeyGenerator
{
public static string GenerateKey(int bitStrength)
{
// note: valid bit strength for aes: 128, 192, or 256 bits (16, 24, or 32 bytes)
var random = new System.Security.Cryptography.RNGCryptoServiceProvider();
var keyArray = new byte[bitStrength / 8];
random.GetBytes(keyArray);
var base64key = Convert.ToBase64String(keyArray);
@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 / rename-check-constraint-convention.sql
Last active November 14, 2018 17:05
rename sql constraints to match convension
-- script to generate sp_rename commands for all check constraints
select
ck.name as current_name
,po.name as ParentObject
,po.type_desc as ParentType
,ISNULL(pc.name, N'') as ColumnName
,'exec sp_rename @objname = N''[' + ps.name + '].[' + ck.name + ']'', @newname = ''CK_' + po.name + '_' + pc.name + '''' as rename_cmd
from
sys.check_constraints ck
left join sys.objects po on (ck.parent_object_id = po.object_id)
@aaronhoffman
aaronhoffman / delete-bin-obj-node-nuget-directories.ps1
Last active November 4, 2018 18:58
Clean up source code directory. Delete all bin, obj, node_modules, bower_components, and packages directories.
# delete all bin,obj,node_modules,bower_components,packages,.vs, and *proj.user files and directories
Get-ChildItem . -include bin -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include node_modules -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include bower_components -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include packages -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include .vs -Hidden -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
Get-ChildItem . -include *proj.user -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
@aaronhoffman
aaronhoffman / TrivialJsonConverter.cs
Created September 13, 2018 21:47
Newtonsoft.Json BaseJsonConverter example
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public class TrivialJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return true;
}
@aaronhoffman
aaronhoffman / GoogleContactService.cs
Last active August 1, 2018 20:01
Google Contacts API Create New Contact in My Contacts System Group. more: https://www.mycontactsync.com/
public class GoogleContactService
{
public void CreateContact()
{
var cr = this.CreateContactsRequest();
var groups = cr.GetGroups().Entries.ToList();
var myContactsSystemGroup = groups.FirstOrDefault(x => x.SystemGroup == "Contacts");
var newContact = new Contact();
Sub FindNextValueChangeInColumn()
'
' FindNextValueChangeInColumn Macro
'
On Error GoTo ErrHandler
Dim currentValue As String
Dim compareValue As String
currentValue = ActiveCell.Value
create table [dbo].[AspNetRoleClaims] (
[Id] int IDENTITY(1, 1) not null,
[RoleId] nvarchar(450) not null,
[ClaimType] nvarchar(MAX) null,
[ClaimValue] nvarchar(MAX) null,
constraint [PK_AspNetRoleClaims] primary key clustered ([Id] asc)
);
go
create nonclustered index [IX_AspNetRoleClaims_RoleId] on [dbo].[AspNetRoleClaims] ([RoleId] asc);
@aaronhoffman
aaronhoffman / copy-older-files.ps1
Created June 5, 2018 13:25
PowerShell script to copy files older than a given date
# copy files older than a given date
$items = Get-ChildItem -Path ".\" | Where-Object { $_.CreationTime -le "12/31/2017" }
Write-Output "count $($items.Length)"
foreach ($item in $items)
{
Move-Item -Path $item.FullName -Destination "c:\destination\$($item.Name)"
}