Skip to content

Instantly share code, notes, and snippets.

@hoangitk
hoangitk / script-to-create-or-drop-all-primary-keys-MSSQL.sql
Created November 15, 2022 05:01
[Script to create and drop all Primary Keys in MSSQL] #sql #tools
/*
Credit: https://social.technet.microsoft.com/wiki/contents/articles/2321.script-to-create-or-drop-all-primary-keys.aspx
*/
DECLARE @object_id int;
DECLARE @parent_object_id int;
DECLARE @TSQL NVARCHAR(4000);
DECLARE @COLUMN_NAME SYSNAME;
DECLARE @is_descending_key bit;
DECLARE @col1 BIT;
@hoangitk
hoangitk / SurrealDb.md
Created September 22, 2022 09:20
[SurrealDB] #surrealdb

SurrealDb

Tutorials

  • Start:
     surreal start --log debug --user root --pass root memory 
     surreal sql --conn http://localhost:8000 --user root --pass root --ns test --db test --pretty
@hoangitk
hoangitk / rust.md
Created September 22, 2022 08:35
Rust #rust #install

Rust

Installation

  • WLS ref:
     sudo apt install build-essential # Install pre-reqs
     curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
@hoangitk
hoangitk / FormsAuthenticationTicketHelper.cs
Created July 19, 2022 09:29 — forked from dazinator/FormsAuthenticationTicketHelper.cs
Decrypt a Legacy ASP.NET Forms Authentication Cookie (that uses SHA1 validation, and AES encryption) - without horrendous dependencies on system.web.. This allows you to decrypt a forms authentication cookie that was created in ASP.NET 3.5, from an ASP.NET 5 application.
internal static class FormsAuthenticationTicketHelper
{
private const byte CURRENT_TICKET_SERIALIZED_VERSION = 0x01;
private const int MAX_TICKET_LENGTH = 4096;
// Resurrects a FormsAuthenticationTicket from its serialized blob representation.
// The input blob must be unsigned and unencrypted. This function returns null if
// the serialized ticket format is invalid. The caller must also verify that the
// ticket is still valid, as this method doesn't check expiration.
using System.IO.Pipelines;
using System.Net;
using System.Net.Security;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
var builder = WebApplication.CreateBuilder(args);
@hoangitk
hoangitk / Move docker-desktop-data distro out of System Drive.md
Created March 20, 2022 05:46
Move docker-desktop-data distro out of System Drive #docker
@hoangitk
hoangitk / Git_Practices.md
Last active March 11, 2022 06:18
[Git Practice] #git
@hoangitk
hoangitk / ExampleUsage.cs
Created November 27, 2021 04:24 — forked from NickCraver/ExampleUsage.cs
Code to mark a SQL string before it's passed to Dapper.
public static List<T> Query<T>(this DataContext db, string sql, object param = null, int? commandTimeout = null, IDbTransaction transaction = null, [CallerFilePath]string fromFile = null, [CallerLineNumber]int onLine = 0, string comment = null)
{
using (db.Connection.EnsureOpen())
{
try
{
return db.Connection.Query<T>(MarkSqlString(sql, fromFile, onLine, comment), param, transaction ?? db.Transaction, true, commandTimeout).AsDapperList();
}
catch (SqlException ex) when (ex.Is(SqlErrorCode.DatabaseReadOnly_3906))
{
@hoangitk
hoangitk / Shrink your WSL2 Virtual Disks and Docker Images and Reclaim Disk Space.md
Created November 3, 2021 07:04
[Shrink your WSL2 Virtual Disks and Docker Images and Reclaim Disk Space] #wsl #tips

Shrink your WSL2 Virtual Disks and Docker Images and Reclaim Disk Space

Credit: https://www.hanselman.com/blog/shrink-your-wsl2-virtual-disks-and-docker-images-and-reclaim-disk-space

Docker Desktop for Windows uses WSL to manage all your images and container files and keeps them in a private virtual hard drive (VHDX) called ext4.vhdx.

It's usually in C:\Users\YOURNAME\AppData\Local\Docker\wsl\data and you can often reclaim some of the space if you've cleaned up (pruned your images, etc) with Optimize-Vhd under an administrator PowerShell shell/prompt.

You'll need to stop Docker Desktop by right clicking on its tray icon and choosing Quit Docker Desktop. Once it's stopped, you'll want to stop all running WSL2 instances with wsl --shutdown

Mine was 47gigs as I use Docker A LOT so when I optimize it from admin PowerShell from the wsl\data folder

@hoangitk
hoangitk / curl in Powershell.md
Created October 27, 2021 10:08
[curl in Powershell] #powershell