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
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 #\
) <#\
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `
#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# Bash Start ------------------------------------------------------------
@chrisfcarroll
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
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"
albumname=""
acodec="mpga"
mux="mpeg1"
ext=".mp3"
directoryAsAlbumName=""
foldDirectoryNames=""
function showhelp {
@chrisfcarroll
chrisfcarroll / HtmlToPdfWriter.cs
Last active May 9, 2018
.Net wrapper for the very excellent https://wkhtmltopdf.org/
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
chrisfcarroll / Asp.Net MVC DebuggableModelBinder and CheckboxToBoolModelBinder.md
Last active Sep 13, 2018
To make stepping through the modelbinding process easier
View Asp.Net MVC DebuggableModelBinder and CheckboxToBoolModelBinder.md

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
chrisfcarroll / Asp.Net SignedUrls.md
Last active Oct 12, 2018
Signed Url Generator for .Net with Timestamp and HMACSHA512
View Asp.Net SignedUrls.md

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
</a>
  • 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 http://tampermonkey.net/
// @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 https://trello.com/*
// @grant none
// ==/UserScript==
// jshint -W097
@chrisfcarroll
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
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
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.