Skip to content

Instantly share code, notes, and snippets.

View surgicalcoder's full-sized avatar

surgicalcoder

  • United Kingdom
View GitHub Profile
@surgicalcoder
surgicalcoder / gist:975d6221bf7d7414a844
Created September 4, 2015 13:34
Automagically run windows updates.
I'm using nlog for my logger, and you need to add a reference to WUApiLib. You need a way to handle multiple reboots to do updates (which is what our custom StepResult bits do)
private static Logger logger = LogManager.GetCurrentClassLogger();
public StepResult PerformAction()
{
UpdateSession session = new UpdateSession();
ISearchResult uResult;
@surgicalcoder
surgicalcoder / gist:644403f4a1b7eb1c09dd
Created October 15, 2015 10:06
Azure Data Movement API
Import Microsoft.Azure.Storage.DataMovement and all dependencies from Nuget, then have this:
private static void Download()
{
ServicePointManager.DefaultConnectionLimit = Environment.ProcessorCount * 8;
ServicePointManager.Expect100Continue = false;
string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=elatuse2mtrsprodsql;AccountKey=5LJ7KqzdaQlatfXcMMdJe0xw9jadzYR7VLo37GgMclaFZn5mwV58qszm9Azta5dfwJ5SJXPHKfuKsiIRAm/UyA==;";
@surgicalcoder
surgicalcoder / Program.cs
Created December 25, 2015 21:03 — forked from DanielSWolf/Program.cs
Console progress bar. Code is under the MIT License: http://opensource.org/licenses/MIT
using System;
using System.Threading;
static class Program {
static void Main() {
Console.Write("Performing some task... ");
using (var progress = new ProgressBar()) {
for (int i = 0; i <= 100; i++) {
progress.Report((double) i / 100);
@surgicalcoder
surgicalcoder / IPProtocolType.cs
Created July 25, 2016 11:23
C# IP Protocol Type Enum
public enum IPProtocolType
{
[Description("IPv6 Hop-by-Hop Option")]
HOPOPT = 0,
[Description("Internet Control Message")]
ICMP = 1,
[Description("Internet Group Management")]
IGMP = 2,
[Description("Gateway-to-Gateway")]
GGP = 3,
@surgicalcoder
surgicalcoder / file.cs
Created January 2, 2017 14:25
URL Friendly Base64'ness
public static class Base64Extension
{
static readonly char[] padding = { '=' };
public static string EncodeURLBase64(this string Input)
{
var base64 = Convert.ToBase64String(Encoding.Default.GetBytes(Input)).TrimEnd(padding).Replace('+', '-').Replace('/', '_');
return base64;
}
public static string DecodeURLBase64(this string Input)
@surgicalcoder
surgicalcoder / blarg.cs
Created March 20, 2017 14:49
Hack for adding MVC Core modules dynamically
public class Blarg : ApplicationPart, IApplicationPartTypeProvider, ICompilationReferencesProvider
{
public Assembly Assembly { get; }
public Blarg(Assembly assembly)
{
if (assembly == (Assembly)null)
throw new ArgumentNullException("assembly");
this.Assembly = assembly;
}
public override string Name
@surgicalcoder
surgicalcoder / file.cs
Last active August 16, 2017 12:39
JsonToParametersAttribute
public class JsonToParametersAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
var stream = filterContext.HttpContext.Request.Body;
using (var sr = new StreamReader(stream))
using (var jsonTextReader = new JsonTextReader(sr))
{
@surgicalcoder
surgicalcoder / CreateDapperPOCO.groovy
Last active February 1, 2024 08:28
Generate Dapper Contrib from database with DataGrip
import com.intellij.database.model.DasTable
import com.intellij.database.model.ObjectKind
import com.intellij.database.util.Case
import com.intellij.database.util.DasUtil
import com.intellij.database.model.DasIndex
import com.intellij.util.ObjectUtils
import groovy.json.*
typeMapping = [
(~/(?i)^bit$/) : "bool",
@surgicalcoder
surgicalcoder / docker-for-windows.md
Created May 26, 2020 10:06 — forked from BretFisher/docker-for-windows.md
Getting a Shell in the Docker for Windows Moby VM

2018 Update: Easiest option is Justin's repo and image

Just run this from your CLI and it'll drop you in a container with full permissions on the Moby VM. Only works for Moby Linux VM (doesn't work for Windows Containers). Note this also works on Docker for Mac.

docker run -it --rm --privileged --pid=host justincormack/nsenter1

more info: https://github.com/justincormack/nsenter1

@surgicalcoder
surgicalcoder / program.cs
Last active August 2, 2020 14:38
Lunr Code Example
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Lunr;
using Index = Lunr.Index;
namespace LunrCodeJsonExample
{
class Program