Skip to content

Instantly share code, notes, and snippets.

View andyedinborough's full-sized avatar

Andy Edinborough andyedinborough

View GitHub Profile
@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
@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 / 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 / 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\\"))
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 / 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;
}
@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,