Skip to content

Instantly share code, notes, and snippets.


Chris F Carroll chrisfcarroll

Block or report user

Report or block chrisfcarroll

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
chrisfcarroll / Bash-or-PowerShell-with-Param.ps1
Last active Oct 21, 2017
Hold both bash and PowerShell code in a single script file and/or make a PowerShell.ps1 script executable on all platforms. For Windows, *nix, linux and macOs. See Comments below
View Bash-or-PowerShell-with-Param.ps1
` # \
# PowerShell Param statement : every line must end in #\ except the last line must with <#\
# And, you can't use backticks in this section #\
param( [ValidateSet('A','B')]$tabCompletionWorksHere, #\
[switch]$andHere #\
) <#\
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `
# Bash Start ------------------------------------------------------------
chrisfcarroll / LoggingConfig.cs
Created Nov 9, 2017
Serilog Typical setup for Log to RollingFile from Config. with fallback
View LoggingConfig.cs
static class LoggingConfig
/// <summary>
/// After calling this method, use the logger with
/// <code>Log.Logger....</code>
/// e.g.
/// <see cref="Log.Logger"/>.<see cref="ILogger.Debug(string,object[])"/>
/// </summary>
public static ILogger RegisterLogger(ILogger overrideLogger=null)
chrisfcarroll / vlc
Last active Apr 18, 2018
MacOs command line script : use VLC to transcode to mp3
View vlc
#! /usr/bin/env bash
outputdirectory="`dirname ~/Music`/Music/VLCout"
function showhelp {
chrisfcarroll / HtmlToPdfWriter.cs
Last active May 9, 2018
.Net wrapper for the very excellent
View HtmlToPdfWriter.cs
//Uncomment and paste into LinqPad: void Main()
// var pathToWkHtmlToPdfExe=@"C:\yourpathto\wkhtmltopdf.exe";
// var outputPath=new FileInfo(Path.Combine(System.IO.Path.GetTempPath(), "htmlto.pdf"));
// var html="<html><head></head><body><style>body{font-family:\"Helvetica\"}</style><h1>Hello World</h1></body></html>";
// using(var outputstream= new MemoryStream(10000))
// {
// HtmlToPdfWriter.GeneratePdf(new StringReader(html), outputstream, new Size{Width=210,Height=297}, pathToWkHtmlToPdfExe );
// Encoding.UTF8.GetString(outputstream.GetBuffer()).Dump();
// using (var fs=outputPath.OpenWrite()){ outputstream.CopyTo(fs); }
chrisfcarroll / Asp.Net MVC DebuggableModelBinder and
Last active Sep 13, 2018
To make stepping through the modelbinding process easier
View Asp.Net MVC DebuggableModelBinder and

Use the DebuggableModelBinder with a breakpoint to investigate what's happening when your complex model isn't binding as you expect.

Use the CheckBoxToBoolModelBinder to bind <input type="checkbox" > Note the Html standard describes "on" as the only valid postable value for a checkbox.. If you're posting something else, change the code. And don't that forget that unchecked means that nothing gets posted.

In either case, wire them up with e.g.:

public class MvcApplication : HttpApplication
    protected void Application_Start()
chrisfcarroll / Asp.Net
Last active Oct 12, 2018
Signed Url Generator for .Net with Timestamp and HMACSHA512
View Asp.Net

Jealous of AWS style signed-URL links? Wish you could do that too?

Generate your own signed links with two simple classes.

<a href='/SignatureRequired/GetSecretThings?@Html.QuerystringFragmentTimestampAndSignature())>
    Get Secret Things Here
  • My use-case was to restrict the link to the original IP Address:
View trello-wrap-n-stack-to-fit.user.js
// ==UserScript==
// @name Trello Wrap-n-Stack-To-Fit
// @namespace
// @version 0.73
// @description Trello: Auto-wrap, stack and resize your Trello lists so they don't go offscreen. And kill that horizontal scroll-bar.
// @author chrisfcarroll
// @match*
// @grant none
// ==/UserScript==
// jshint -W097
chrisfcarroll / StringMaskedExtension.cs
Last active Nov 5, 2018
String.Masked() extension method
View StringMaskedExtension.cs
public static class StringExtensions
/// <summary>
/// Overwrite the right-most fraction 1/<paramref name="maskFractionOneOver"/> of <paramref name="str"/> with <paramref name="maskCharacter"/>
/// </summary>
/// <param name="str"></param>
/// <param name="maskFractionOneOver"></param>
/// <param name="maskCharacter"></param>
/// <example>"1234".Masked() => "123*"</example>
/// <returns>the masked string</returns>
chrisfcarroll / DeSerializeExcludingFieldsContractResolver.cs
Last active Nov 5, 2018
ContractResolvers for Newtonsoft.Json which can ignore fields either by predicate or by name
View DeSerializeExcludingFieldsContractResolver.cs
using System;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
public class DeSerializeExcludingFieldsContractResolver : DefaultContractResolver
readonly Type type;
readonly Predicate<JsonProperty> ignoreProperty;
chrisfcarroll / HtmlPartialSection.cs
Last active Nov 6, 2018
Razor sections for Partials. Html.PartialSection() and Html.RenderPartialSection() offer sections accessible to partial pages, with optional de-duplication.
View HtmlPartialSection.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
namespace Helpers
/// <summary>Create or Render a <see cref="Helpers.PartialSection"/>s via the current <see cref="HtmlHelper"/></summary>
You can’t perform that action at this time.