Skip to content

Instantly share code, notes, and snippets.

View chrisfcarroll's full-sized avatar
🤹‍♂️
🌍...☕...🖥️...⏳...⛪...🛌🏼

Chris F Carroll chrisfcarroll

🤹‍♂️
🌍...☕...🖥️...⏳...⛪...🛌🏼
View GitHub Profile
@chrisfcarroll
chrisfcarroll / vlc
Last active April 18, 2018 15:23
MacOs command line script : use VLC to transcode to mp3
#! /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 18:07
.Net wrapper for the very excellent https://wkhtmltopdf.org/
//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 September 13, 2018 16:53
To make stepping through the modelbinding process easier

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 October 12, 2018 10:23
Signed Url Generator for .Net with Timestamp and HMACSHA512

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:
@chrisfcarroll
chrisfcarroll / StringMaskedExtension.cs
Last active November 5, 2018 12:36
String.Masked() extension method
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 November 5, 2018 13:25
ContractResolvers for Newtonsoft.Json which can ignore fields either by predicate or by name
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 November 6, 2018 19:46
Razor sections for Partials. Html.PartialSection() and Html.RenderPartialSection() offer sections accessible to partial pages, with optional de-duplication.
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
chrisfcarroll / WebClientBaseAndWrapper.cs
Last active November 15, 2018 17:31
.Net WebClientBase, WebClientWrapper and WebClientFake for a testable System.Net.WebClient
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
chrisfcarroll / LogAssert.cs
Last active November 29, 2018 12:59
Runtime Assertion, Log.Assert, TryLog, TryElse methods
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)
{
try
{
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]); }
@chrisfcarroll
chrisfcarroll / force-integrated-graphics.sh
Created December 31, 2018 18:45
force-integrated-graphics.sh for MacBook 17" 2010–2011 With Broken Radeon graphics chip
#! /bin/sh
kextoffdir="/kextoff"
loginhookscript="/Library/LoginHook/LoadDelayedAMDRadeonX3000kext.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