Skip to content

Instantly share code, notes, and snippets.

View josephwambura's full-sized avatar
👨‍💻
I may be slow to respond.

Joseph Wambura josephwambura

👨‍💻
I may be slow to respond.
View GitHub Profile
@josephwambura
josephwambura / SubtractTwoDates.sql
Created March 22, 2022 12:02
Subtract two dates in Microsoft SQL Server
select CreatedDate , * from dbo_Customers
where
(DATEDIFF(day, CAST(CreatedDate as date), GETDATE())) > 180
-- day is for the intervals, could be minute, hour.
-- using 180 days (6 months) for testing.
-- The CreatedDate is of type DateTime (datetime2).
-- using Table dbo_Customers

IdentityServer4

Duende.IdentityServer

Adding / Removing Migrations

dotnet ef migrations add LengthsMigration --context AdminAuditLogDbContext --project ..\Kelsey.IdentityServer.Admin.EntityFramework.SqlServer\Kelsey.IdentityServer.Admin.EntityFramework.SqlServer.csproj

Updating / Dropping Database

SELECT TOP 1 SubjectAdditionalData, * FROM AuditLog
WHERE
len(SubjectAdditionalData) =
(SELECT max(len(SubjectAdditionalData)) FROM AuditLog);

If you have a local clone, you can update it by running the following commands.

git branch -m master main

git fetch origin

git branch -u origin/main main

git remote set-head origin -a

Add-Migration CreateIdentitySchema -Context ApplicationDbContext -OutputDir ".\Data\Migrations\"

Remove-Migration -Context ApplicationDbContext

@josephwambura
josephwambura / EasilyCleanBinObjFolders.md
Last active December 16, 2023 21:43
Easily Clean Bin/Obj Folders from Visual Studio solution using Powershell

Boot up powershell in admin mode and **_navigate to the root of your repos.

THIS IS VERY IMPORTANT: DO NOT RUN THIS COMMAND IN A SYSTEM FOLDER OR TERRIBLE THINGS WILL HAPPEN.

I am serious about this, make sure you do this in a sub folder. Mine is F:\source\repos

Then run this command:

Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
@josephwambura
josephwambura / HelpfulSqlScripts.md
Last active November 2, 2022 19:10
Helpful Sql Scripts
select count(*) as [Count], Avg(Amount) as [Average], Sum(Amount)/2 as [Sum divided by 2] from dbo_OrderLineItems where OrderId in 
(
	select Id from dbo_Orders where CustomerId in 
	(
	'GUIDGUID-GUID-GUID-GUID-GUIDGUID',
	'GUIDGUID-GUID-GUID-GUID-GUIDGUID',
	'GUIDGUID-GUID-GUID-GUID-GUIDGUID'
	) and (Cast(CreatedDate as date) between '01 June 2022' and '31 July 2022')
)