Skip to content

Instantly share code, notes, and snippets.

@badcommandorfilename
badcommandorfilename / ManagedAuthenticatedEncryptor
Created June 12, 2019 07:09
Standalone (mostly) SP800_108_CTR_HMACSHA512 Key Derivation Function for ASPNetCore cookie sharing
///This is a Frankenstein class that can extract the AES key from a KDK as described in:
/// https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/subkeyderivation?view=aspnetcore-2.2
///With a bit of luck, this should let an ASP.NET app decrypt cookies generated by an ASPNETCore app
///Still consult https://docs.microsoft.com/en-us/aspnet/core/security/cookie-sharing?view=aspnetcore-2.2 to share cookies
///Credit for most of the code is from various parts of https://github.com/aspnet/AspNetCore/tree/master/src/DataProtection/DataProtection/src
public unsafe class CookieDataProtector : IDataProtector
{
readonly string _base64MasterKey;
@badcommandorfilename
badcommandorfilename / hide-sidebar.html
Created February 25, 2019 01:50
CSS only hide sidebar or navbar toggle
<style>
#sidebar {
width: 250px;
}
#hide-sidebar:checked ~ #sidebar {
width: 0;
display: none;
}
@badcommandorfilename
badcommandorfilename / RuntimeCast.cs
Created June 29, 2018 00:57
C# Runtime type Cast and CastEnumerable
static IEnumerable CastEnumerable(IEnumerable<object> input, Type t)
{
foreach(var o in input)
{
yield return Cast(o, t);
}
}
static object Cast(object obj, Type t)
@badcommandorfilename
badcommandorfilename / Base64ImgString.cs
Created May 28, 2018 00:36
Convert an ASP.NET Core image to a b64 data URL string
protected string Base64ImgString(string filepath) {
var serverpath = Path.Combine(HostingEnvironment.WebRootPath, filepath);
var contents = System.IO.File.ReadAllBytes(serverpath);
return $"data:image/png;base64,{Convert.ToBase64String(contents)}";
}
@badcommandorfilename
badcommandorfilename / s3redirectlinks.xml
Created May 24, 2018 02:20
Redirect broken links from a static s3 website
@badcommandorfilename
badcommandorfilename / readmore.html
Last active February 23, 2023 12:19
html html5 css read more break divider section
<!-- Pure HTML5 CSS simple "Read More" break to hide all elements after a clickable section-->
<style>
label.more {
display: inline-block;
width: 100%;
border-bottom: 1px solid black;
text-align: center;
}
@badcommandorfilename
badcommandorfilename / datepicker.cshtml
Created July 20, 2017 01:24
C# HTML5 input date datepicker MVC Razor
<!-- How to insert a date editor in a Razor view -->
<div class="form-group">
@Html.LabelFor(model => model.Start, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.Start, new { @type="date", @class = "form-control datepicker", @Value = Model.Start.ToString("yyyy-MM-dd") } )
@Html.ValidationMessageFor(model => model.Start, "", new { @class = "text-danger" })
</div>
</div>

Scope and Purpose

What are the objectives of the system? Who are the users? What goals do the users want?

Design Inputs

What technologies will be used? What software patterns (MVVM/MVC/Pub-Sub/Producer-Consumer) are being used? What other options were considered?

System Components

Component 1

What is Component 1? What is the responsibility of Component 1?

@badcommandorfilename
badcommandorfilename / FakeDbSetMock.cs
Created January 13, 2017 01:47
Test utility to generate a an empty DbContext
internal class FakeContext
{
public static dynamic Cast(object obj, Type t)
{
if (obj is IConvertible)
{
return Convert.ChangeType(obj, t) as dynamic;
}
else
{
@badcommandorfilename
badcommandorfilename / init.d_kestrel
Created August 25, 2016 23:17
init.d kestrel service script
#!/bin/sh
### BEGIN INIT INFO
# Provides: kestrel
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Script to run asp.net 5 application in the background
### END INIT INFO