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 / 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 / karabiner.json
Last active Sep 21, 2017
Windows on Mac : Just the main Windows Ctrl-keystroke -> Cmd-keystroke mappings. Using Karabiner.
View karabiner.json
{
"profiles": [
{
"complex_modifications": {
"parameters": { /* ... etc ... */ },
"README": "********************************************************************************************************",
"README": "*" COPY JUST THE ELEMENTS OF THIS "rules" array into your profiles.complex_modifications.rules array. "*",
"README": "********************************************************************************************************",
"rules": [
@chrisfcarroll
chrisfcarroll / Curl.ps1
Last active Sep 12, 2017
PowerShell wrapper for Invoke-WebRequest with Proxy
View Curl.ps1
#
$env:Proxy="http://YOUR-CORPORATE-PROXY-HERE" ;
Add-Type -AssemblyName 'Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
function curl
{
param(
[Parameter(Mandatory=$true)][string]$Uri,
[Object]$Body,
[String]$ContentType,
[PSCredential]$Credential,
@chrisfcarroll
chrisfcarroll / youtube-dl-prompt.ps1
Created Jul 8, 2017
Youtube Downloader Prompting Wrapper : wraps youtube-dl.exe for a start-menu icon that prompts for the url to download.
View youtube-dl-prompt.ps1
param( [Parameter(Mandatory=$true)][string]$UrlToDownload )
$downloadDirectory="C:\Users\Services\Downloads"
cd $downloadDirectory
write-host ""
write-host ""
write-host "Downloading $urlToDownload to $downloadDirectory ..."
write-host ""
write-host ""
$Error.Clear()
youtube-dl.exe $urlToDownload
@chrisfcarroll
chrisfcarroll / SerilogStringListSink.cs
Last active Sep 21, 2017
A StringList Sink for Serilog. Typical usage:
View SerilogStringListSink.cs
using System;
using System.Collections.Generic;
using System.IO;
using Serilog;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting;
using Serilog.Formatting.Display;
@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 ------------------------------------------------------------
View WrappingAsyncInAsyncAwaitIsRedundant.cs
//
// Example 1) async await is redundant when calling a method that doesn't block anyway
//
void Main()
{
var filename = Path.Combine(Path.GetTempPath(), "ExampleAsyncAwaitIsRedundant.txt");
using (var fstream= new FileStream(filename,FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 4096,FileOptions.Asynchronous))
{
fstream.Seek(0, SeekOrigin.Begin);
View Minimal html5 doc
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>title</title></head><body>Here</body></html>
@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 / AutoHotKey for a Mac User with an Apple keyboard on Windows.ahk
Last active Jul 13, 2019
AutoHotKey script for they who, being Mac Users with an Apple keyboard, yet still insist on using Windows. Also some arrange-windows-on-a-big-screen keys . Takes a similar approach as Parallels to keyboard mapping: rather than a wholesale swap of Cmd <-> Ctrl, instead duplicate favourite ctrl-key shortcuts to the Cmd key. For the big screen: som…
View AutoHotKey for a Mac User with an Apple keyboard on Windows.ahk
; Language: English
; https://gist.github.com/chrisfcarroll/dddf32fea1f29e75f564
;
; Uses unicode. Save this file as utf-8 with BOM.
; Else it shall not work.
;
#NoEnv ; Recommended
;SendMode Input ; Recommended
SendMode Event
SetWorkingDir %userprofile% ; Ensures a consistent starting directory.
You can’t perform that action at this time.