Skip to content

Instantly share code, notes, and snippets.

View alastairs's full-sized avatar

Alastair Smith alastairs

View GitHub Profile
@alastairs
alastairs / GitHubSignIn.ts
Created May 6, 2017 14:26
Failing GitHub authorisation
import { ScreenCap } from "../../helpers/ScreenCap"
import { Casper } from "casperjs"
export class GitHubSignIn {
private readonly OAUTH_AUTHORISATION_FORM = '.oauth-review-permissions form[method=post]';
constructor(private casper: Casper, private screencap: ScreenCap) { }
login(username: string, password: string): void {
this.casper
@alastairs
alastairs / ModelBindingExample.cs
Last active May 16, 2017 19:27
Example model binding
namespace Mvc.Examples
{
public class SomeController : Controller
{
public IActionResult Post([FromBody]MyModel model)
{
// Do something with `model` here
}
}
@alastairs
alastairs / ValidateModelAttribute.cs
Created May 16, 2017 19:31
A simple ASP.NET MVC FilterAttribute that validates the model in the request pipeline
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
@alastairs
alastairs / CreateRecordRequest.cs
Created May 16, 2017 19:40
Example Data Model/DTO in ASP.NET MVC
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")]
// 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 / JsonPropertyDisplayMetadataProvider.cs
Created May 16, 2017 20:27
Implementation of `IDisplayMetadataProvider` that reads the display name from `JsonProperty` attributes.
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;
@alastairs
alastairs / NCrunchBugRepro.Test.deps.json
Last active May 27, 2017 01:40
.NET Core dependencies file for an NCrunch bug repro
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v1.1",
"signature": "284bcae32a73d805159b5f9db2a228e815fb23c1"
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v1.1": {
"ncrunchbugrepro.test/1.0.0": {
"dependencies": {
@alastairs
alastairs / Cambridge Software Crafters Email.md
Last active April 12, 2018 12:40
Email to the Cambridge Software Crafters re: name change and CoC

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.

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 / keybase.md
Created August 30, 2019 16:06
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: