Skip to content

Instantly share code, notes, and snippets.

View Protiguous's full-sized avatar

Protiguous Protiguous

View GitHub Profile
@Protiguous
Protiguous / FormatBytes.sql
Last active January 12, 2023 09:12
SQL Server Function to format bytes into larger units like MB, GB, TB, etc..
-- select [dbo].[FormatBytes]( 13241322.567567, 'bytes' );
-- select [dbo].[FormatBytes]( 132413225.567567, 'bytes' );
-- select [dbo].[FormatBytes]( 1324132255.567567, 'bytes' );
-- select [dbo].[FormatBytes]( 13241322551.567567, 'bytes' );
-- select [dbo].[FormatBytes]( 13241322.567567, 'mb' );
-- select [dbo].[FormatBytes]( 132413225.567567, 'gb' );
-- select [dbo].[FormatBytes]( 1324132255.567567, 'tb' );
-- select [dbo].[FormatBytes]( 13241322551.567567, 'zb' );
-- select [dbo].[FormatBytes]( 13241322551.567567, 'yb' );
-- select [dbo].[FormatBytes]( 132413225512.567567, 'yb' );
@Protiguous
Protiguous / BaseNotifyModel.cs
Created September 4, 2022 02:45 — forked from RupertAvery/BaseNotifyModel.cs
WPF ListView Binding
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace WPFSample
{
public class BaseNotifyModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
@Protiguous
Protiguous / Sanitize.cs
Last active January 19, 2022 00:51
Truncate (sanitize) decimal numbers to the Nth decimal place.
// Copyright © Protiguous. All Rights Reserved.
//
// This entire copyright notice and license must be retained and must be kept visible in any binaries, libraries, repositories, or source code (directly or derived) from our binaries, libraries, projects, solutions, or applications.
//
// All source code belongs to Protiguous@Protiguous.com unless otherwise specified or the original license has been overwritten by formatting. (We try to avoid it from happening, but it does accidentally happen.)
//
// Any unmodified portions of source code gleaned from other sources still retain their original license and our thanks goes to those Authors.
// If you find your code unattributed in this source code, please let us know so we can properly attribute you and include the proper license and/or copyright(s).
// If you want to use any of our code in a commercial project, you must contact Protiguous@Protiguous.com for permission, license, and a quote.
//
@Protiguous
Protiguous / ABetterClassDispose.cs
Last active September 11, 2021 09:33
A different [easier] way of disposing objects.
// Copyright © Protiguous. All Rights Reserved.
//
// This entire copyright notice and license must be retained and must be kept visible in any binaries, libraries, repositories, or source code (directly or derived) from our binaries, libraries, projects, solutions, or applications.
//
// All source code belongs to Protiguous@Protiguous.com unless otherwise specified or the original license has been overwritten by formatting. (We try to avoid it from happening, but it does accidentally happen.)
//
// Any unmodified portions of source code gleaned from other sources still retain their original license and our thanks goes to those Authors.
// If you find your code unattributed in this source code, please let us know so we can properly attribute you and include the proper license and/or copyright(s).
// If you want to use any of our code in a commercial project, you must contact Protiguous@Protiguous.com for permission, license, and a quote.
//
fsutil.exe file createnew "Emergency Disk Space (safe to delete).$$$" 8589934592
@Protiguous
Protiguous / ExpectedOutput.1-100.txt
Created March 31, 2021 21:51
FizzBuzz Expected Output, Lines 1 to 100
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
@Protiguous
Protiguous / Drop and Create Service Broker objects.sql
Last active August 16, 2020 02:42
Easy Create Objects for Service Broker (works in SQL Server 2019 Developer Edition)
-- Based from https://sqlperformance.com/2014/03/sql-performance/configuring-service-broker
USE [master]
GO
ALTER DATABASE [Test] SET ENABLE_BROKER WITH NO_WAIT
GO
USE [Test]
GO
@Protiguous
Protiguous / ListExample.cs
Last active August 14, 2020 08:45
Example to show adding items to a list and removing certain items.
//Verified to run under .NET 5.0 Console Application.
namespace ConsoleApp1 {
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
@Protiguous
Protiguous / Draw BrentOzar.sql
Last active November 17, 2019 18:33 — forked from SQLAdrian/drawbrent.sql
Let's draw Brent
/*Adrian Sullivan - 2019/11/15 Fun with polygons.*/
/*Thanks to Michael J Swart for all the awesome work on color
https://michaeljswart.com/
*/
DECLARE @tt table(id int identity(0,1), label VARCHAR(50), gg GEOMETRY)
SET NOCOUNT ON
DECLARE @g geometry = 'POLYGON((-121.97087 37.372518,-121.97087 37.372518,-121.970863 37.372517,-121.970845 37.372515,-121.97087 37.372518))'
@Protiguous
Protiguous / FullDBBackup.ps1
Created November 9, 2019 01:17 — forked from AdamLJohnson/FullDBBackup.ps1
Powershell script to backup all SQL Databases on a server. Useful for SQL Express.
$serverName = ".\SQLExpress"
$backupDirectory = "D:\backupSQL"
$daysToStoreDailyBackups = 7
$daysToStoreWeeklyBackups = 28
$monthsToStoreMonthlyBackups = 3
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-Null