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 / 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 / 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 / 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 / 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 / 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 / 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)
{
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 / 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 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:
You can’t perform that action at this time.