Skip to content

Instantly share code, notes, and snippets.

View elithompson's full-sized avatar

Eli Thompson elithompson

View GitHub Profile
@elithompson
elithompson / HtmlExtensions.cs
Last active December 19, 2015 15:29
ValidateAngularAntiForgeryTokenAttribute - A FilterAttribute which does xsrf validation for calls from angular. EnsureXsrfCookie - A method which ensures that a cookie is available for angular to read which supplies the form half of the xsrf information which ASP.NET uses to validate the request. IIRC, this requires ASP.NET 4.
using System.Web.Helpers;
namespace System.Web.Mvc
{
public static class HtmlExtensions
{
public static IHtmlString AngularAntiForgeryToken(this HtmlHelper html)
{
const string xsrfTokenCookieName = "XSRF-TOKEN";
@elithompson
elithompson / gist:3442106
Created August 23, 2012 21:31 — forked from stefanrusek/gist:3436540
It turns out HashSet<string> is SUPER fast!
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace tpl_await_test
{
@elithompson
elithompson / Global.asax.cs
Created February 16, 2012 02:12
Static resources, caching, and cache busting on AppHarbor
namespace Website
{
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Statics",
@elithompson
elithompson / DimensionResizer.java
Created October 20, 2011 03:23
DimensionResizer
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dimensionresizer;
import java.awt.Point;
/**
*
@elithompson
elithompson / dog.coffee
Created July 29, 2011 04:51
Unit testing CoffeeScript with QUnit
class Dog
speak: -> "woof"
legs: 4
@elithompson
elithompson / turntable-track-muter.js
Created June 29, 2011 02:22
Mute until next track starts
(function(){
function toggleMute() {
$(".mute_btn:first").click();
}
toggleMute();
console.log("muted!");
var $messagesDiv = $(".messages");
function onMessageReceived(event) {
if (event.target.tagName !== "DIV") {
@elithompson
elithompson / createEvent.js
Created May 25, 2011 00:11
A simple C#-style event system in Javascript
function createEvent() {
var handlers = [];
var event = function(handler) {
if (arguments.length === 0) {
for(var i = 0, action; (action = handlers[i]); i++) {
action();
}
return;
}
handlers.push(handler);