Skip to content

Instantly share code, notes, and snippets.

View jdiamond's full-sized avatar

Jason Diamond jdiamond

  • 05:16 (UTC -07:00)
View GitHub Profile
@jdiamond
jdiamond / promises.md
Last active December 16, 2015 13:19
Promise example for Domenic

Problem

This is part of the router in a single-page application I'm working on:

function navigateTo(url) {
    return findOrCreatePageContainer(url)      // finds div or creates new one
        .then(loadAndInitPageIfNotAlreadyDone) // loads content into div
        .catch(injectErrorMessage)             // injects error message into div
        .then(transitionToNewPage);            // displays content in div
@jdiamond
jdiamond / mongoose-as-promised.js
Created December 30, 2012 18:58
Mongoose as Promised
var mongoose = require('mongoose');
var Q = require('q');
mongoose.Promise.prototype.then = function(fulfilled, rejected) {
var deferred = Q.defer();
this.addCallback(deferred.resolve);
this.addErrback(deferred.reject);
return deferred.promise.then(fulfilled, rejected);
@jdiamond
jdiamond / indexeddb.html
Created September 16, 2012 22:25
IndexedDB Example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IndexedDB Example</title>
</head>
<body>
<h1>IndexedDB Example</h1>
<p>
using System;
using NUnit.Framework;
namespace BehaveN.Tests
{
[TestFixture]
public class Describe_NameParser
{
[Test]
public void it_should_throw_an_exception_when_parsing_null()