Skip to content

Instantly share code, notes, and snippets.

Avatar

Alastair Smith alastairs

View GitHub Profile
View gist:1142957
Write a function that returns true or false depending on whether its input integer is a leap year or not.
A leap year is divisible by 4, but is not otherwise divisible by 100 unless it is also divisible by 400.
2001 is a typical common year
1996 is a typical leap year
1900 is an atypical common year
2000 is an atypical leap year
@alastairs
alastairs / EqualityDemo.cs
Created Apr 1, 2020
Equality implementation in C#
View EqualityDemo.cs
namespace EqualityDemo
{
public class Person : IEquatable<Person>
{
public string GivenName { get; }
public string FamilyName { get; }
public Address Address { get; }
public override bool Equals(object other)
{
View keybase.md

Keybase proof

I hereby claim:

  • I am alastairs on github.
  • I am alastairs (https://keybase.io/alastairs) on keybase.
  • I have a public key ASA8efXB1aDLQ-vHTUfdKHZOxzIKQk1SK8EyJGJtHKxNpgo

To claim this, I am signing this object:

View bxp-eu-1.md

Letter no. 1 to Brexit Party MEPs for East of England, 2019-

Dear <name>

Congratulations on taking your seat in the eighth European Parliament. I hope you are delighted with your election and are looking forward to representing your constituents. I've been following the rise of the Brexit Party with interest over the last five months but am struggling to find detailed answers to much of your stated position on Brexit. I am sure you will want to set the highest standard of accountability and transparency in your new role -- putting the principles of Trust, Honesty and Integrity at the heart of

@alastairs
alastairs / Cambridge Software Crafters Email.md
Last active Apr 12, 2018
Email to the Cambridge Software Crafters re: name change and CoC
View Cambridge Software Crafters Email.md

Changes to the Cambridge Software Craftsmanship Community

Hi everyone

It's not often that we email our members, so please bear with me and read this to the end.

Recent events in the wider tech community, and reactions within the Software Craftsmanship community, have prompted wider discussions about the inclusiveness of the community, and I've decided to make some small but important changes to our local chapter.

@alastairs
alastairs / NCrunchBugRepro.Test.deps.json
Last active May 27, 2017
.NET Core dependencies file for an NCrunch bug repro
View NCrunchBugRepro.Test.deps.json
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v1.1",
"signature": "284bcae32a73d805159b5f9db2a228e815fb23c1"
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v1.1": {
"ncrunchbugrepro.test/1.0.0": {
"dependencies": {
@alastairs
alastairs / JsonPropertyDisplayMetadataProvider.cs
Created May 16, 2017
Implementation of `IDisplayMetadataProvider` that reads the display name from `JsonProperty` attributes.
View JsonPropertyDisplayMetadataProvider.cs
namespace Mvc.Examples
{
internal class JsonPropertyDisplayMetadataProvider : IDisplayMetadataProvider
{
public void CreateDisplayMetadata(DisplayMetadataProviderContext context)
{
var attributes = context.Attributes;
var jsonPropertyAttribute = attributes.OfType<JsonPropertyAttribute>().FirstOrDefault();
var displayMetadata = context.DisplayMetadata;
View IDisplayMetadataProvider.cs
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata
{
/// <summary>
/// Provides <see cref="DisplayMetadata"/> for a <see cref="DefaultModelMetadata"/>.
/// </summary>
public interface IDisplayMetadataProvider : IMetadataDetailsProvider
{
@alastairs
alastairs / CreateRecordRequest.cs
Created May 16, 2017
Example Data Model/DTO in ASP.NET MVC
View CreateRecordRequest.cs
namespace Mvc.Examples
{
public class CreateRecordRequest
{
[JsonProperty("employee_id")]
[Required, DisplayName("employee_id")]
public string EmployeeId { get; set; }
[JsonProperty("source_id")]
[Required, DisplayName("source_id")]
@alastairs
alastairs / ValidateModelAttribute.cs
Created May 16, 2017
A simple ASP.NET MVC FilterAttribute that validates the model in the request pipeline
View ValidateModelAttribute.cs
namespace Mvc.Examples
{
internal class ValidateModelAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext actionContext)
{
if (actionContext.ModelState.IsValid == false)
{
actionContext.Result = new BadRequestObjectResult(
actionContext.ModelState.Values
You can’t perform that action at this time.