Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@unscriptable
unscriptable / HttpError.js
Created January 5, 2012 15:39
Example "subclass" of Error object
// AMD module wrapper.
define(function () {
function HttpError (msg, code) {
var ex;
msg = msg || 'Unknown HTTP error';
ex = new Error(msg); // not all browsers let us inherit, so we do it this way
ex.code = code;
ex.name = 'HttpError'; // thx @cjno! (http://twitter.com/cjno/status/154959746582056960)
@unscriptable
unscriptable / issue53.html
Created January 28, 2012 17:14
reproduce curl.js issue 53
<!DOCTYPE HTML>
<html>
<head>
<title>issue 53</title>
<script src="../src/curl.js" type="text/javascript"></script>
<script type="text/javascript">
curl({
@unscriptable
unscriptable / MethodSpy.js
Created February 28, 2012 22:16
spy on a method
function MethodSpy (method, context) {
var count, orig, spy;
count = 0;
orig = context[method];
context[method] = function () {
count++;
return orig.apply(context, arguments);
};
@unscriptable
unscriptable / cola.transform.expression.js
Created March 3, 2012 19:51
wire and/or cola function to allow an arbitrary expression to be evaluated
/** MIT License (c) copyright B Cavalier & J Hann */
(function (define, globalEval) {
define(function () {
"use strict";
/**
* Creates a function that can be used to evaluate arbitrary expressions
* on a data item.
* @param options {Object}
// this is a test module
define(['curl/tdd/createContext', 'require'], function (createContext, require) {
// supply a require (optional) if your module ids are relative
var context = createContext(require);
context.setup(function (require, define /*, complete*/) {
// define all of your mocks and stubs
define('mock1', function () {});
@unscriptable
unscriptable / DisableItemWhileUnresolved.js
Created March 21, 2012 01:21
event hub with strategies
define(function () {
var undef;
/**
* This strategy will disable a data item during REST operations.
* This strategy only makes sense in a pessimistic network.
* We need to integrate promises into the EventHub in order for this
* strategy to work. Alternatively, we could have item states of
* 'adding', 'removing', 'updating', but that feels brutish.
*/
@unscriptable
unscriptable / _spec.js
Created April 5, 2012 02:43
wire plugin to create functions without violating JSON
define({
myFunc: {
expr: {
body: 'alert(e.target.textContent);',
params: ['e']
}
},
body: {
@unscriptable
unscriptable / module-id.js
Created July 17, 2012 20:26
how to local-require
define(function (require, exports, module) {
return {
component: { module: './something' },
$module: module // has absolute id of spec (as well as other future goodies)
};
});
@unscriptable
unscriptable / umd.js
Created September 13, 2012 14:02
cjs umd
(function (define) {
define(function (require, exports, module) {
return 'foo';
});
}(
typeof define == 'function' && define.amd
? define
: function (factory) { factory(require, exports, module); }
@unscriptable
unscriptable / README.md
Created November 16, 2012 14:30
curl.js (0.7.2) + backbone (0.9.2)

Here's one way to use curl.js with backbone