Skip to content

Instantly share code, notes, and snippets.

View michaelcox's full-sized avatar

Michael Cox michaelcox

View GitHub Profile
@michaelcox
michaelcox / collections.js
Last active August 29, 2015 14:05
Backbone Unit Testing
define(function(require) {
var Backbone = require('backbone');
var _ = require('underscore');
var models = require('./models');
var collections = {};
collections.Posts = Backbone.Collection.extend({
model: models.Post,
@michaelcox
michaelcox / FAQ-XSL-Template.xsl
Created February 14, 2011 20:37
XSL Template for saving Frequently Asked Questions as XML, and outputting to HTML.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no" omit-xml-declaration="yes" />
<xsl:template match="/faq_page">
<xsl:if test="count(//question) &gt; 5">
<xsl:for-each select="category">
@michaelcox
michaelcox / AllowCrossSiteJson.cs
Created February 17, 2012 16:23
Allow Cross Site JSON in .NET MVC
public class AllowCrossSiteJson : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
var headers = Enumerable.ToList(HttpContext.Current.Request.Headers.AllKeys);
headers.Add("X-HTTP-Method-Override");
@michaelcox
michaelcox / email.js
Created May 3, 2012 15:17
Command Line nodejs App For Sending Test Emails
#!/usr/bin/env node
var program = require('commander');
var email = require("mailer");
program
.version('0.0.1')
.option('-s, --subject <text>', 'subject line of email')
.option('-b, --body <text>', 'body area of email')
.option('-r, --recipient <email>', "recipient's email address")
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f
class view extends Backbone.View
initialize: =>
@template = _.template($('#mytemplate').html())
render: =>
@$el.html @template(
model: @model.toJSON()
)
import {Component, bootstrap, FORM_DIRECTIVES, CORE_DIRECTIVES} from 'angular2/angular2';
import {HeroList} from './hero-list.component';
import {Hero} from './hero';
@Component({
selector: 'my-app',
directives: [FORM_DIRECTIVES, CORE_DIRECTIVES, HeroList],
template:`
<h1>{{title}}</h1>

Keybase proof

I hereby claim:

  • I am michaelcox on github.
  • I am mdcox (https://keybase.io/mdcox) on keybase.
  • I have a public key whose fingerprint is FFD1 0A59 BEC1 CC64 2BC3 549E F5AA 5B80 1E3C 847A

To claim this, I am signing this object:

Verifying that "michaelcox.id" is my Blockstack ID. https://onename.com/michaelcox
@michaelcox
michaelcox / xdr.js
Created May 10, 2012 18:56
Adds XDomainRequest IE CORS support to jQuery
// Based on https://github.com/jaubourg/ajaxHooks/blob/master/src/ajax/xdr.js
(function( jQuery ) {
if ( window.XDomainRequest && !jQuery.support.cors ) {
jQuery.ajaxTransport(function( s ) {
if ( s.crossDomain && s.async ) {
if ( s.timeout ) {
s.xdrTimeout = s.timeout;
delete s.timeout;