Skip to content

Instantly share code, notes, and snippets.

View ukcoderj's full-sized avatar

Justin ukcoderj

View GitHub Profile
@ukcoderj
ukcoderj / BaseResourceProvider.cs
Last active September 19, 2018 10:45
.NET Core Port Of afana.me's excellent i18n internationalisation (no magic strings in code - http://afana.me/archive/2013/11/01/aspnet-mvc-internationalization-store-strings-in-database-or-xml.aspx/)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace YourWebsite.i18n
{
/// <summary>
/// This is a .net core port of
/// http://afana.me/archive/2013/11/01/aspnet-mvc-internationalization-store-strings-in-database-or-xml.aspx/
@ukcoderj
ukcoderj / SSLSettingsIIS8.ps1
Created March 5, 2019 15:31 — forked from justinacton/SSLSettingsIIS8.ps1
Powershell script to configure your IIS server with Perfect Forward Secrecy and TLS 1.2.
# Copyright 2014, Alexander Hass
# http://www.hass.de/content/setup-your-iis-ssl-perfect-forward-secrecy-and-tls-12
#
# Version 1.4
# - RC4 has been disabled.
# Version 1.3
# - MD5 has been disabled.
# Version 1.2
# - Re-factored code style and output
# Version 1.1
@ukcoderj
ukcoderj / StringProtectionHelper.cs
Created June 11, 2019 15:49
DPAPI - ProtectedData.Protect - Example for hiding sensitive information in Windows
using System;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text;
namespace TestConsole
{
/// <summary>
/// Uses DPAPI for hiding sensitive information
/// Adapted from MSDN: https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.protecteddata?redirectedfrom=MSDN&view=netframework-4.8
@ukcoderj
ukcoderj / CopyConstructorExample.cs
Created June 14, 2019 10:31
Copy Constructor Example
using System;
using System.Collections.Generic;
namespace DeleteMeConsole
{
public class StateChecking
{
public void DoTest()
@ukcoderj
ukcoderj / service-fabric-fix-local-cluster.ps1
Created December 19, 2019 14:58
Fix a Broken Local Service Fabric Cluster
#
# WARNING: YOU MUST STOP 'SERVICE FABRIC HOST SERVICE' IN SERVICES FIRST
# IF THE APPLICATION IS STUCK IN 'STARTING', RESTART YOUR MACHINE
#
# This script will completely reset the local cluster
#
Remove-Item 'C:\SfDevCluster' -Recurse -Force -ErrorAction Stop
New-Item -ItemType directory -Path 'C:\SfDevCluster'
@ukcoderj
ukcoderj / consolewithusersecrets.cs
Created May 5, 2020 13:09
.NET Core Console Accessing User Secrets
using Microsoft.Extensions.Configuration;
using System;
namespace TestSecrets
{
// NuGet
//
// Microsoft.Extensions.Configuration
// Microsoft.Extensions.Configuration.UserSecrets
@ukcoderj
ukcoderj / angular-enum-select
Created October 26, 2020 09:04
Angular Select In Child Component Bound to Enumeration
// CHILD COMPONENT HTML
<select id="upload_type_select" #uploadTypeSelect
class="form-control"
(change)="onUploadTypeChange(uploadTypeSelect.value)">
<option *ngFor="let upType of uploadTypesMapping"
[value]="upType.value"
[selected]="upType.value === uploadDataType">
{{ upType.type }}
</option>
@ukcoderj
ukcoderj / Download.service.ts
Last active November 5, 2020 14:55
Download a blob held in azure to an angular client
import { Injectable, EventEmitter } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, throwError, of } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import { saveFile, saveAs } from 'file-saver'; // npm install file-saver
import { Base64 } from 'js-base64'; // npm install js-base64
import { DownloadFile } from '../models/dowload/download-file';
@Injectable({
providedIn: 'root'
@ukcoderj
ukcoderj / IsDirectoryTraversing.cs
Last active March 25, 2021 05:07
C# Helper To See If There Is A Directory Traversal Attempt on a File
/// <summary>
/// This is to guage whether someone is trying a directory traversal attack.
/// I.e. they should be requesting 'somefilename.pdf'
/// but they request '../anotherlocation/someotherfilename.pdf
/// </summary>
/// <param name="fileName">The file name to check</param>
/// <returns></returns>
public bool IsDirectoryTraversing(string fileName)
{
bool isTraversing = false;
@ukcoderj
ukcoderj / state-machine-page.component.html
Created April 26, 2021 10:01
Angular XState State Machine - Queries State - Doesn't use the event
<h3>State Machine</h3>
<button (click)="moveBack()">Back</button>
<button (click)="moveNext()">Next</button>
<p>State: {{currentState}}</p>