Skip to content

Instantly share code, notes, and snippets.

@jyarbro
jyarbro / aoc2018_4.cs
Created December 4, 2018 08:22
Advent of Code 2018 Day 4
class Day4_2018 {
const string INPUTFILE = @"2018\day4.txt";
public void Part1() {
var guardSleepMinutes = LoadGuardSleepMinutes();
var guardSleepTotals = new Dictionary<int, int>();
foreach (var guard in guardSleepMinutes) {
if (!guardSleepTotals.ContainsKey(guard.Key)) {
@jyarbro
jyarbro / aoc2018_3.cs
Created December 3, 2018 20:29
Advent of Code 2018 Day 3
class Day3_2018 {
const string INPUTFILE = @"2018\day3.txt";
public void Part1() {
var input = File.ReadAllLines(INPUTFILE);
var dimension = 1000;
var area = dimension * dimension;
var fabric = new int[area];
@jyarbro
jyarbro / aoc2018_2.cs
Last active December 2, 2018 09:26
Advent of Code 2018 Day 2
class Day2_2018 {
const string INPUTFILE = @"2018\day2.txt";
public void Part1() {
var input = File.ReadAllLines(INPUTFILE);
var twos = 0;
var threes = 0;
foreach (var line in input) {
@jyarbro
jyarbro / aoc2018_1.cs
Last active December 2, 2018 09:25
Advent of Code 2018 Day 1
class Day1_2018 {
public void Part1() {
var input = File.ReadAllLines(@"2018\day1.txt");
var output = 0;
foreach (var line in input) {
var number = Convert.ToInt32(line);
output += number;
}
@jyarbro
jyarbro / bookmarklets
Created January 3, 2018 10:35
Paywall Bookmarklets
javascript:void(open('https://archive.today/?run=1&url='+encodeURIComponent(document.location)))
javascript:void(window.open('https://outline.com/'+window.location.href))
@jyarbro
jyarbro / PreventDuplicateRequestAttribute.cs
Last active May 23, 2024 11:56
MVC Core async attribute for preventing duplicate requests.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class PreventDuplicateRequestAttribute : ActionFilterAttribute {
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) {
if (context.HttpContext.Request.Form.ContainsKey("__RequestVerificationToken")) {
await context.HttpContext.Session.LoadAsync();
var currentToken = context.HttpContext.Request.Form["__RequestVerificationToken"].ToString();
var lastToken = context.HttpContext.Session.GetString("LastProcessedToken");
if (lastToken == currentToken) {
@jyarbro
jyarbro / SharePointWorkflowStub.cs
Created October 25, 2017 06:15
The bare minimum necessary to get an SP2010 workflow going in VS2017.
using Client.SharePoint.Services;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using System.Workflow.ComponentModel;
namespace Client.SharePoint.Workflow {
public class ReportWorkflow : Activity {
public WorkflowContext __Context {
get => ((WorkflowContext)(GetValue(__ContextProperty)));
set => SetValue(__ContextProperty, value);