Skip to content

Instantly share code, notes, and snippets.


Chris F Carroll chrisfcarroll

View GitHub Profile
chrisfcarroll /
Created Dec 31, 2018 for MacBook 17" 2010–2011 With Broken Radeon graphics chip
#! /bin/sh
echo "---------------------------------------------------------------
Run this script twice.
First, from a Recovery Mode commandline to run csrutil disable.
Second, after rebooting to a Single user mode commandline, with / partition mounted writeable, to do all the things that must be done with csrutil status= disabled
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>
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 / WebClientBaseAndWrapper.cs
Last active Nov 15, 2018
.Net WebClientBase, WebClientWrapper and WebClientFake for a testable System.Net.WebClient
View WebClientBaseAndWrapper.cs
public abstract class WebClientBase : IDisposable
WebHeaderCollection headers = new WebHeaderCollection();
public abstract void UploadValuesAsync(Uri address, string method, NameValueCollection data);
public abstract void UploadValuesAsync(Uri address, string method, NameValueCollection data, object userToken);
public abstract byte[] UploadData(Uri address, string method, byte[] data);
public abstract byte[] UploadFile(Uri address, string method, string fileName);
public abstract byte[] UploadValues(Uri address, string method, NameValueCollection data);
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 / Uninstall-Programs-Or-Features.ps1
Last active Oct 23, 2020
PowerShell commandline Uninstall-Programs-Or-Features.ps1
View Uninstall-Programs-Or-Features.ps1
Uninstall one or more Windows Program or Feature, by name or regular expression.
Lists Programs And Features installed on the current machine which match
the -matchingName parameter and then, after force or confirmation, uninstalls them.
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:
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 / 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 / LogAssert.cs
Last active Nov 29, 2018
Runtime Assertion, Log.Assert, TryLog, TryElse methods
View LogAssert.cs
public static class LogAssert
public static void Assert(this ILogger logger, Func<bool> assertion, string failureMessage = "Try failed", LogEventLevel level = LogEventLevel.Debug, string successMessage=null, IEnumerable args = null)
var ok = assertion();
if (ok && successMessage!=null) { logger.Write(level, successMessage, args ?? new object[0]); }
if (!ok) { logger.Write(level, failureMessage, args ?? new object[0]); }
You can’t perform that action at this time.