Skip to content

Instantly share code, notes, and snippets.

@csuzw
csuzw / index.js
Created November 7, 2019 10:49
Azure AD Single Sign On with Cypress
// This goes in cypress/plugins/index.js
const AzureAdSingleSignOn = require('./azure-ad-sso/plugin').AzureAdSingleSignOn
module.exports = (on, config) => {
on('task', {AzureAdSingleSignOn:AzureAdSingleSignOn})
}
@csuzw
csuzw / keybase.md
Created February 19, 2019 10:43
keybase.md

Keybase proof

I hereby claim:

  • I am csuzw on github.
  • I am csuzw (https://keybase.io/csuzw) on keybase.
  • I have a public key ASCRAdPs2_BCK9ur7mkddBoPT03Wpqh_eNGaF4cuhcDPDQo

To claim this, I am signing this object:

@csuzw
csuzw / HighEntropyPassphrases.cs
Last active December 4, 2017 15:20
Advent of Code 2017 Day 4
int HighEntropyPassphrasesPartOne(string[] passPhrases)
{
return DoHighEntropyPassphrases(passPhrases, w => w);
}
int HighEntropyPassphrasesPartTwo(string[] passPhrases)
{
return DoHighEntropyPassphrases(passPhrases, w => string.Concat(w.OrderBy(c => c)));
}
@csuzw
csuzw / SpiralMemory.cs
Last active December 4, 2017 11:52
Advent of Code 2017 Day 3
int SpiralMemoryPartOne(int location)
{
if (location <= 1) return 0;
var ring = 1;
var max = 9;
while (max < location)
{
ring += 1;
max += (((ring + 1) * 2) - 2) * 4;
@csuzw
csuzw / CorruptionChecksum.cs
Last active December 4, 2017 09:19
Advent of Code 2017 Day 2
int CorruptionChecksumPartOne(int[][] input)
{
return input.Sum(r =>
{
(var max, var min) = r.Aggregate((max: int.MinValue, min: int.MaxValue), (acc, i) => (i > acc.max ? i : acc.max, i < acc.min ? i : acc.min));
return max - min;
});
}
int CorruptionChecksumPartTwo(int[][] input)
@csuzw
csuzw / InverseCaptcha.cs
Last active December 3, 2017 18:16
Advent of Code 2017 Day 1
int InverseCaptchPartOne(string input)
{
return DoInverseCaptcha(input, _ => 1);
}
int InverseCaptchPartTwo(string input)
{
return DoInverseCaptcha(input, x => x.Length / 2);
}
@csuzw
csuzw / GetKeyPresses.cs
Created March 15, 2017 23:46
Gets number of key presses required to input message on old phone keypad
int GetKeyPresses(string message)
{
return (int)message.Select(c => c < 83 ? ((c - 29) % 3) + 1 : Math.Round(Enumerable.Range(0, 8).Zip(new[] { -400129224492.361d, 32421475419.7348d, -1125710194.76048d, 21711311.9794762d, -251208.877408241d, 1743.70653338347d, -6.72322436313127d, 0.011108192375644d }, (a, b) => b * Math.Pow(c, a)).Sum())).Sum();
}
@csuzw
csuzw / DateDiff.cs
Last active November 13, 2017 15:41
Gets the number of days between 2 dates (at least if they fall between 01/01/0001 and 29/02/4096 (I think!)). Note that this could be even faster if I used such exotic things as conditionals to weed out the easy cases but where would the fun be in that!?!
public int DateDiff(int y1, int m1, int d1, int y2, int m2, int d2)
{
return GetDays(y2, m2, d2) - GetDays(y1, m1, d1);
}
private int GetDays(int y, int m, int d)
{
var y1 = y - 1;
var m1 = m - 1;
var yleap = y - ((18 - m) >> 4);
@csuzw
csuzw / ExpressionMemberInfo.cs
Last active August 29, 2015 14:17
MemberInfo for non-Member expressions
/// <summary>
/// Crude but effective for my requirements.
/// </summary>
public class ExpressionMemberInfo<T, TProperty> : MemberInfo
{
private static readonly Dictionary<ExpressionType, string> _operatorDescriptions = new Dictionary<ExpressionType, string>
{
{ ExpressionType.Add, "+" },
{ ExpressionType.AddAssign, "+" },
{ ExpressionType.AddAssignChecked, "+" },
@csuzw
csuzw / dynamicpredicates.cs
Last active August 29, 2015 14:07
Dynamic Predicates
// using DynamicLinq
public static Func<TInput, TOutput> GetFuncFromLinq<TInput, TOutput>(this string predicate)
{
if (string.IsNullOrWhiteSpace(predicate)) return null;
LambdaExpression expression = DynamicExpression.ParseLambda(typeof(TInput), typeof(TOutput), predicate);
Func<TInput, TOutput> func = x => (TOutput)expression.Compile().DynamicInvoke(x);
return func;