Instantly share code, notes, and snippets.

View postal-code-to-state-map-condensed.csv
StateName StateCode CondensedPostalCodeRanges
Alabama AL 35000-35299;35400-36999
Alaska AK 99500-99999
Arizona AZ 85000-85399;85500-85799;85900-86099;86300-86599
Arkansas AR 71600-72999
California CA 90000-90899;91000-92899;93000-96199
Colorado CO 80000-81699
Connecticut CT 06000-06389;06391-06999
Delaware DE 19700-19999
District of Columbia DC 20000-20099;20200-20587;56900-56999;20589-20597;20599
View TrivialJsonConverter.cs
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public class TrivialJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return true;
}
View find-next-value-change-in-column.vba
Sub FindNextValueChangeInColumn()
'
' FindNextValueChangeInColumn Macro
'
On Error GoTo ErrHandler
Dim currentValue As String
Dim compareValue As String
currentValue = ActiveCell.Value
View aspnet-core-2-1-identity.sql
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);
View copy-older-files.ps1
# 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)"
}
View rename-check-constraint-convention.sql
-- 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)
View generate-vsts-shortcuts.sql
-- Google Chrome stores dates in microseconds since 1601-01-01 in the `keywords` sqlite table
-- the following line generates that value
-- select (strftime('%s', datetime('now')) + 11644473600) * 1000000
-- algo used to generate a uuid per row
-- select lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6)))
/*
Variables are not supported in sqlite.
View git-fetch-all-recurse.ps1
param (
[string]$path = "c:\dev\"
)
Write-Output "Recurse in $path for hidden .git folders..."
$gitdirs = Get-ChildItem -Recurse -Path $path -Force -Filter ".git"
Write-Output "Found: $($gitdirs.Length) repos"
View GoogleContactService.cs
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();
View convert-hashbytes-varbinary-hex-char.sql
convert(char(48), HASHBYTES('sha1', @HashInput), 2)
convert(char(64), HASHBYTES('sha2_256', @HashInput), 2)