Skip to content

Instantly share code, notes, and snippets.

View secretorange's full-sized avatar

Lee Gunn secretorange

View GitHub Profile
using System;
using System.Linq;
namespace MontyHall
{
public class Game
{
private static Random Random = new Random();
public static void Main(string[] args)
@secretorange
secretorange / ConditionalAnchorTagHelper.cs
Last active February 17, 2019 16:23
ASP.NET 5 Conditional Anchor Tag Helper. This tag helper will omit the anchor tag if the href is null or empty.
namespace SecretOrange
{
[HtmlTargetElement("a", Attributes = "asp-conditional")]
public class ConditionalAnchorTagHelper : TagHelper
{
public override async void Process(TagHelperContext context, TagHelperOutput output)
{
var href = context.AllAttributes["href"]?.Value.ToString();
if (String.IsNullOrWhiteSpace(href))
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace SecretOrange.Data
{
public class EasySort<T> where T : class
{

My SQL Snippets

Process List

SHOW PROCESSLIST

DROP all tables

SELECT concat('DROP TABLE IF EXISTS `', table_schema, '`.`', table_name, '`;')
@secretorange
secretorange / Constants.cs
Created April 12, 2018 07:36
Commonly used RegEx for DotNet. Email, Password etc.
public static class Constants
{
public static class RegEx
{
public const string Email = @"^[a-zA-Z0-9#'$%+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9#'$%+/=?^_`{|}~-]+)*[a-zA-Z0-9#'$%+/=?^_`{|}~-]*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9]{2,}$";
// Passwords must be at least 8 characters and contain at 3 of 4 of the following: upper case (A-Z), lower case (a-z), number (0-9) and special character (e.g. !@#$%^&*)
public const string Password = "^((?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])|(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[^a-zA-Z0-9])|(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])|(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])).{8,}$";
}
}
@secretorange
secretorange / Folders.md
Last active April 14, 2018 12:49
Freelance setup

WORK IN PROGRESS

  • 📁 DEV (Development folder - anything dev related that can be thrown away)
  • 📁 DB (All databases for all projects)
  • 📁 PRJ (Projects)
  • 📁 ACC (Accounts - Invoices & receipts etc)

Details

@secretorange
secretorange / UnitTests.cs
Last active October 21, 2018 16:05
Version attribute for MSTest, useful for testing versioned API endpoints.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Diagnostics;
namespace UnitTestProject
{
[TestClass]
public class UnitTests
{
[TestMethod]
@secretorange
secretorange / LambdaEntryPoint.cs
Last active August 29, 2023 18:52
Get access to the Lambda alias at Startup which you can then use to load environment specific config
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using System.IO;
using AWSBoot.Boot;
using Microsoft.Extensions.Configuration;
using Amazon.Lambda.AspNetCoreServer.Internal;
@secretorange
secretorange / CacheInvalidationRequestBuilder.cs
Last active December 19, 2018 09:53
Builds a signed GET request to invalidate an AWS API Gatewat endpoint https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace Aws
{
public static class CacheInvalidationRequestBuilder
-- GET RID OF OLD VERSIONS
IF OBJECT_ID('tempdb..#tmp') IS NOT NULL
DROP TABLE #tmp
Select TOP 10000 VersionID into #tmp FROM cmsDocument
WHERE versionID NOT IN (SELECT D.versionId FROM cmsDocument D
WHERE D.versionId IN (SELECT versionId FROM (SELECT CV.versionId, published, newest, RANK() OVER(ORDER BY CV.versionDate DESC) RowNum
FROM cmsContentVersion CV JOIN cmsDocument DD ON CV.versionId = DD.versionId
WHERE DD.nodeId = D.nodeId) AS tmp