Skip to content

Instantly share code, notes, and snippets.

@hoangitk
hoangitk / IIS_Verbs.config
Last active April 16, 2020 15:19 — forked from jalalhejazi/IIS_Verbs.config
CORS: Web.config to enable CORS
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS"/>
<add name="Access-Control-Allow-Headers" value="Content-Type"/>
</customHeaders>
</httpProtocol>
@hoangitk
hoangitk / SqlKataExample.cs
Created June 23, 2020 06:49 — forked from benmccallum/SqlKataExample.cs
Optimized, cursor-based paging for connections with MS SQL CTEs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using AutoGuru.Client.Shared;
using AutoGuru.Client.Shared.Dtos;
using AutoGuru.Client.Shared.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
@hoangitk
hoangitk / git_submodules.md
Created June 29, 2020 07:22 — forked from gitaarik/git_submodules.md
Git Submodules basic explanation

Git Submodules basic explanation

Why submodules?

In Git you can add a submodule to a repository. This is basically a repository embedded in your main repository. This can be very useful. A couple of advantages of using submodules:

  • You can separate the code into different repositories.
@hoangitk
hoangitk / ConsolePortScanner.cs
Created September 11, 2020 06:39 — forked from jonlabelle/ConsolePortScanner.cs
Simple async C# Open Port Network Scanner
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Net.Sockets;
namespace ConsolePortScanner
{
class MainClass
@hoangitk
hoangitk / Pattern.cs
Created November 4, 2020 03:12 — forked from michael-wolfenden/Pattern.cs
Pattern
public class Pattern<TReturn>
: List<(Type Type, Func<object, TReturn> Map)>
{
public void Add<T>(Func<T, TReturn> map)
=> Add((typeof(T), o => map((T)o)));
public Pattern<TReturn> Default(TReturn val)
{
Add((object _) => val);
return this;
@hoangitk
hoangitk / svelte-summit-2020-summary.md
Created November 26, 2020 09:06 — forked from vedam/svelte-summit-2020-summary.md
links and ressources from the svelte-summit-2020 talks

You'll find the talks here


Morgan Williams @mrgnw

The Zen of Svelte

Approaching frontend as a backend developer, Svelte feels surprisingly pythonic. Let's take a quick look at what's familiar, what's foreign, and how to explore the gap.

@hoangitk
hoangitk / MachineKeys.cs
Created April 8, 2021 05:40 — forked from cmcnab/MachineKeys.cs
Extracting current ASP.NET machine keys and setting them without committing them to the Web.config
namespace MyApp.Web.Security
{
using System;
using System.Configuration;
using System.Reflection;
using System.Web;
using System.Web.Configuration;
public class MachineKeys
{
@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))
{
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 / 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.