Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@unscriptable
unscriptable / AMD module list.md
Created May 26, 2011 15:25
List of AMD-compliant modules in the wild

A List of actively-supported, reusable, open-source, AMD-compliant modules in the wild. Let me know if you have another module to add to the list!

querySelectorAll (css3-based dom selector engine)

Promises / Deferreds

@unscriptable
unscriptable / _fast-curl-boot.md
Created November 29, 2012 04:52
fast ways to boot apps with curl

There are a couple of things that bug me about RequireJS's data-main method of single-script loading:

<script src="js/requirejs/require.js" data-main="app/main.js"></script>
  1. the built file (bundle) must be named "require.js". WAT.
  2. it just seems backwards.
  3. data-main does not follow w3c recommendations since it's not name-spaced.
@unscriptable
unscriptable / frak.js
Last active February 12, 2024 00:38
frak.js
(function (define, frakkedConstructor) { define(function (require) { "use strict";
var removeCommentsRx, findFuncRx, fracPrefixSrc, fracSuffixSrc,
undef;
removeCommentsRx = /\/\*[\s\S]*?\*\/|(?:[^\\])\/\/.*?[\n\r]/g;
findFuncRx = /(function\s+NAME\s*\([^\{]+\{)|(?:[^\\]?)(["'])|(\{)|(\})/g;
// TODO: allow individual parameters to be modified
// TODO: allow function return to be modified or passed to after()
fracPrefixSrc = 'frak$backs.before.apply(this, arguments); try {';
@unscriptable
unscriptable / anonymous.js
Last active February 12, 2024 00:36
How we use modules today TODO: inline modules for mocks/testing
/**
* This is a simple module with no id. The loader will assign an id
* according to the url where this file was found. This is done with
* a mapping of id:url, typically, but could be done via url:id as is
* proposed by some ES6 discussions.
*/
define(function (require) {
var wire, spec;
wire = require('wire');
@unscriptable
unscriptable / AMD-factory-with-require.js
Created November 20, 2012 15:11
Simple AMD/node boilerplate. These aren't quite "normal" AMD and aren't "pure" CJS, but work in AMD loaders and node-like environments (like RingoJS).
// Typical AMD factory that returns a value, but uses an r-value (sync) require(),
// rather than a long, awkward dependency list.
// You cannot use module.exports or exports to declare the module:
(function (define){
define(function (require) {
"use strict";
var mod = require('pkb/modA');
return {
@unscriptable
unscriptable / AMD Modules.js
Last active February 11, 2024 22:26
AMD modules that look like CJS Modules/1.1
define(function (require, exports) {
var foo = require('foo');
exports.bar = 'bar';
});
// this also works:
define(function (require) {
var foo = require('foo');
return { bar: 'bar' };
});
@lenary
lenary / gitconfig.ini
Created February 18, 2011 01:21
a special excerpt of my gitconfig
$ git clone github:lenary/guides.git
Cloning into guides...
remote: Counting objects: 255, done.
remote: Compressing objects: 100% (216/216), done.
remote: Total 255 (delta 111), reused 163 (delta 35)
Receiving objects: 100% (255/255), 1.49 MiB | 564 KiB/s, done.
Resolving deltas: 100% (111/111), done.
$ cd guides
$ git remote -v
@domenic
domenic / q-nexttick-times.md
Created May 27, 2012 06:30
Q test suite nextTick results

Comparing Different Implementations of process.nextTick using the Q test suite.

Used: q-spec.js@a1a416.

Implementations compared:

Based on MessageChannel

This is currently in Q:

@domenic
domenic / interop.md
Last active July 7, 2022 19:47
`module.exports =` and ES6 Module Interop in Node.js

module.exports = and ES6 Module Interop in Node.js

The question: how can we use ES6 modules in Node.js, where modules-as-functions is very common? That is, given a future in which V8 supports ES6 modules:

  • How can authors of function-modules convert to ES6 export syntax, without breaking consumers that do require("function-module")()?
  • How can consumers of function-modules use ES6 import syntax, while not demanding that the module author rewrites his code to ES6 export?

@wycats showed me a solution. It involves hooking into the loader API to do some rewriting, and using a distinguished name for the single export.

This is me eating crow for lots of false statements I've made all over Twitter today. Here it goes.