Skip to content

Instantly share code, notes, and snippets.

View andyedinborough's full-sized avatar

Andy Edinborough andyedinborough

View GitHub Profile
@andyedinborough
andyedinborough / AntiForgery.cs
Created December 4, 2018 14:16
ASP.NET Core Antiforgery with custom cache header value
using Microsoft.AspNetCore.Antiforgery.Internal;
using Microsoft.AspNetCore.Http;
using Microsoft.Net.Http.Headers;
public class Antiforgery : DefaultAntiforgery
{
public Antiforgery(
Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Antiforgery.AntiforgeryOptions> antiforgeryOptionsAccessor,
IAntiforgeryTokenGenerator tokenGenerator,
IAntiforgeryTokenSerializer tokenSerializer,
@andyedinborough
andyedinborough / ConditionalTypes.tsx
Created March 28, 2018 13:57
Demo of conditional types
import * as React from 'react';
type Parse<T> = { parse: (value: string) => T };
type MaybeParse<T> = T extends string ? {} : Parse<T>;
interface GenericTextboxBaseProps<TModel, TProperties extends keyof TModel> {
model: TModel;
name: TProperties;
display?: (prop: TModel[TProperties]) => string;
}
const noop = () => {};
export default class CancellablePromise {
constructor(executorOrPromise){
this._promise = new Promise((resolve, reject) => {
let promise = executorOrPromise;
if(!promise.then) promise = new Promise(executorOrPromise);
promise.then((...args) => {
if(this.cancelled) reject('cancelled', ...args);
@andyedinborough
andyedinborough / IntegrationTest.cs
Created February 23, 2012 14:29
This would be so epic...
using System;
using System.Web;
namespace TestOfMyDreams {
[TestClass]
public class Test {
[TestMethod]
public void TestRequest(){
using(var app = MyMvcApplication.Create("C:\\path\\to\\project\\"))
@andyedinborough
andyedinborough / Example.html
Created February 8, 2012 17:01
A simple JavaScript implementation of the Razor view engine.
<!doctype html>
<html>
<head>
</head>
<body>
<div id="notices"></div>
<script src="Razor.js"></script>
<script type="application/x-razor-js" data-view-id="notice">
@andyedinborough
andyedinborough / rx.js
Created January 22, 2012 16:49
One RegExp to match urls, email addresses, Twitter usernames and hashtags.
function combine() {
var ret = '', flags = '';
[ ].forEach.call(arguments, function (exp) {
exp = exp.toString();
if (exp[0] !== '/') {
flags = exp;
} else {
ret += exp.substr(1, exp.length - 2);
}
@andyedinborough
andyedinborough / LICENSE.txt
Created December 28, 2011 15:07 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
using System;
using System.IO;
namespace AE.Net.Mail {
//http://stackoverflow.com/questions/842465/reading-a-line-from-a-streamreader-without-consuming
public class PeekableTextReader : TextReader {
private TextReader _Underlying;
private MemoryStream _Buffer;
private StreamReader _BufferReader;
private StreamWriter _BufferWriter;
@andyedinborough
andyedinborough / jquery.oauth.js
Created October 12, 2011 13:10
Adds an $.oauth() function to jQuery which mimics the $.ajax() function
/*
MIT License (MIT)
Copyright (c) 2011 Andy Edinborough
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH TH
public class MvcApplication : System.Web.HttpApplication {
void Application_Start() {
MvcMiniProfiler.Data.ProfiledDbProviderFactory.RegisterProviders();
}
}