Skip to content

Instantly share code, notes, and snippets.

View WiredUK's full-sized avatar
💜
Focusing on community

David Glass WiredUK

💜
Focusing on community
View GitHub Profile
// ==UserScript==
// @name Table Formatter
// @author DavidG
// @grant GM_addStyle
// @license MIT
// @version 1.1.0.0
// @description Allow copy & paste of tables on Stack Overflow (ALT+V to paste CSV into a table)
// @include /^https?:\/\/([\w-]*\.)*((stackoverflow|stackexchange|serverfault|superuser|askubuntu|stackapps)\.com|mathoverflow.net)\/(c\/[^\/]*\/)?(questions|posts|review|tools)\/(?!tagged\/|new\/).*/
// @exclude *://chat.stackoverflow.com/*
// @exclude *://chat.stackexchange.com/*
public void Method1((string, string) parameter)
{
switch (parameter)
{
case var tObj when tObj.Item1 == "x":
break;
}
}
//Fails with:
[Blah(SomeValue = 4)]
public void DoStuff()
{
var method = MethodBase.GetCurrentMethod();
var attr = (BlahAttribute)method.GetCustomAttributes(typeof(BlahAttribute), true)[0];
var value = attr.SomeValue;
Console.WriteLine(value);
}
@WiredUK
WiredUK / LandscapeOutput.cs
Created June 22, 2016 09:23
Example code to output landscape PDF when using Wired.RazorPdf
public ActionResult LandscapeControllerlessPdfWithoutLayout()
{
var generator = new StandaloneGenerator(new Parser(), Server.MapPath("~"));
var pdf = generator.GeneratePdf(
(writer, document) =>
{
document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
},
GetModel(),
Server.MapPath("~/Views/Pdf/ControllerlessPdfWithoutLayout.cshtml"));
@WiredUK
WiredUK / JsonExtensions.cs
Created June 14, 2016 16:26
Json Extensions class to allow deserialisation of JSON directly from a stream. Adapted from http://stackify.com/improved-performance-using-json-streaming
public static class JsonExtensions
{
public static T Deserialise<T>(this Stream jsonStream)
where T : class
{
if (jsonStream == null)
{
throw new ArgumentNullException(nameof(jsonStream));
}
void Main()
{
var input = "1113222113";
Enumerable.Range(1, 50).ToList().ForEach(i =>
{
input = Parse(input);
});
Console.WriteLine($"{input.Length}");
}
@WiredUK
WiredUK / AdventOfCodeDay8.cs
Created December 9, 2015 01:06
Advent of code day 8 (LinqPad)
void Main()
{
Part1();
Part2();
}
void Part1()
{
var lines = File.ReadAllLines(@"C:\Users\David\Documents\LINQPad Queries\input-day8.txt");
void Main()
{
var input = File.ReadAllLines(@"C:\Users\David\Documents\LINQPad Queries\input-day2.txt");
var totalPaper = input.Select(i => i.Split('x')).Select(i => i.Select(j => int.Parse(j)).ToList()).Select(i => 2 * i[0] * i[1] + 2 * i[0] * i[2] + 2 * i[1] * i[2] + i.OrderBy(j => j).Take(2).Aggregate((k, l) => k * l)).Sum();
totalPaper.Dump();
var totalRibbon = input.Select(i => i.Split('x')).Select(i => i.Select(j => int.Parse(j)).ToList()).Select(i => i[0]*i[1]*i[2] + i.OrderBy(j => j).Take(2).Aggregate((k, l) => 2*k + 2*l)).Sum();
totalRibbon.Dump();
}
@WiredUK
WiredUK / Logicizer.cs
Created October 9, 2015 23:53
Logicizer
public static class Logicizer
{
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> leftExpression, Expression<Func<T, bool>> rightExpression)
{
var parameter = Expression.Parameter(typeof(T));
var left = new ReplaceExpressionVisitor(leftExpression.Parameters[0], parameter)
.Visit(leftExpression.Body);
var right = new ReplaceExpressionVisitor(rightExpression.Parameters[0], parameter)
// ==UserScript==
// @name SE Tab Notifier
// @namespace https://gist.github.com/WiredUK
// @description Update Tab Title when Inbox has content
// @include http://*.stackexchange.com/*
// @include http://superuser.com/*
// @include http://serverfault.com/*
// @include http://meta.stackoverflow.com/*
// @include http://stackoverflow.com/*
// @include http://stackapps.com/*