Skip to content

Instantly share code, notes, and snippets.

View davetransom's full-sized avatar

Dave Transom davetransom

View GitHub Profile
@davetransom
davetransom / MvcConfiguration.cs
Last active September 10, 2020 03:55
ShortGuid Model Binding (MVC or WebApi) example
// Configure binding provider for MVC during the general setup, e.g.
// ... AreaRegistration.RegisterAllAreas();
ModelBinderProviders.BinderProviders.Add(new MyProject.ModelBinders.Mvc.ShortGuidModelBinderProvider());
// ... FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
@davetransom
davetransom / ExtractTarGz.cs
Last active February 18, 2022 11:24 — forked from ForeverZer0/ExtractTarGz.cs
Use pure C# to extract .tar and .tar.gz files
using System;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace TarExample
{
public class Tar
{
/// <summary>
@davetransom
davetransom / nest-git-pull.ps1
Last active June 11, 2018 22:38
Searches folders for `.git` subfolder, reports current branch/commit, performs a `git pull`
param($work)
# restart PowerShell with -noexit, the same script, and 1
if (!$work) {
powershell -noexit -file $MyInvocation.MyCommand.Path 1
return
}
# source:
# https://michael-mckenna.com/update-multiple-git-repositories-on-windows-at-once-using-powershell/
@davetransom
davetransom / override-getMockSignature.js
Created July 14, 2015 10:34
Display model descriptions in swagger-ui.
// This needs to be injected into swagger-ui's index.html file after 'swagger-ui.js' (where getMockSignature is defined)
// but _before_ it is used to render parts of the page. A horrible dirty hack.
var _originalGetMockSignature = window.Model.prototype.getMockSignature;
window.Model.prototype.getMockSignature = function newModelGetMockSignature(modelsToIgnore) {
var model = this;
var signature = _originalGetMockSignature.apply(this, arguments);
@davetransom
davetransom / DistinguishedName.cs
Created April 10, 2015 23:51
Implementation of LDAP Distinguished Name parser, based on http://stackoverflow.com/a/25335936/137854. Also trims leading whitespace from attribute names and handles quoted values e.g. the `O="VeriSign, Inc."` in `CN=VeriSign Class 3 Secure Server CA - G3, OU=Terms of use at https://www.verisign.com/rpa (c)10, OU=VeriSign Trust Network, O="VeriS…
public class DistinguishedName
{
/// <summary>
/// Represents a name/value pair within a distinguished name, including the index of the part.
/// </summary>
public struct Part
{
public Part(string name, string value, int index = -1)
: this()
{
@davetransom
davetransom / swagger-overrides.js
Last active June 2, 2016 13:27
A javascript override of swagger-ui markdown rendering to play nicely with XML comments generated from .NET
(function () {
var re_leading_whitespace = /^\s+(?=[^\s])/g,
re_is_whitespace = /^\s*$/,
re_br = /<br ?\/?>/gi,
re_blockquotes_for_html_fix = /^(\s*&gt;)+/gm;
function transform_markdown(html, text) {
var
// leading padding string, if found
@davetransom
davetransom / 1. Usage.cs
Last active December 27, 2015 00:59
A simple, lightweight and maintainable way to output arbitrary CSV/TSV - keeps header names close to the column/value definition.
// vars to be used inside column value funcs
DateTime utcnow = DateTime.UtcNow;
const decimal VIP_SPEND = 1000000M;
var fields = new CsvDefinition<MyRecord>
{
{ "Username", row => string.Concat(row.Prefix, ":", row.Username) },
{ "Email", row => row.Email },
{ "Status", row => row.TotalSpend >= VIP_SPEND ? "VIP" : "Pffft..., Peon" },
{ "Spend ($)", row => row.TotalSpend == null ? "None" : row.TotalSpend.ToString("n2") },