Instantly share code, notes, and snippets.

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
,o.name as ParentObject
,o.type_desc as ParentType
,ISNULL(C.name, N'') as ColumnName
,'exec sp_rename @objname = N''' + ck.name + ''', @newname = ''CK_' + o.name + '_' + c.name + '''' as rename_cmd
from
sys.check_constraints ck
join sys.objects o on (ck.parent_object_id = o.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)
View INotifyPropertyChangedExtensions.cs
public static void OnPropertyChanged<T>(
this INotifyPropertyChanged @this,
PropertyChangedEventHandler propertyChanged,
Expression<Func<T>> propertyExpr)
{
if (propertyChanged == null) return;
var memberExpr = (MemberExpression)propertyExpr.Body;
var ea = new PropertyChangedEventArgs(memberExpr.Member.Name);