Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@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 / _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 / 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 {
@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:

@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: {
@briancavalier
briancavalier / soon.js
Created January 6, 2012 19:31
Enqueue a task for nextTick in many environments
soon = (function() {
var enqueueTask;
if(typeof process != 'undefined' && typeof process.nextTick == 'function') {
// Node nextTick
enqueueTask = process.nextTick;
} else if (typeof setImmediate == 'function') {
// setImmediate for new IE
@unscriptable
unscriptable / ZZZ_MyView.js
Created November 23, 2011 11:05
cujo-ish view/widget
// MyView.js when concatenated together using cram.js
// cram.js needs two new features to make this work:
// 1. an option to NOT normalize module ids
// 2. an option to more easily exclude modules from the build (wire plugins, for instance)
define('./myView/controller', {
_onClick: function (e) {
this.rootNode.classList.toggle(this.states.selected);
}
});
(function(){
function Klass(id){ this._id = id; }
Klass.prototype.id = function(){ console.log(this._id); }
var freeExports = typeof exports == 'object' && exports;
if (freeExports) {
for (var prop in Klass) freeExports[prop] = Klass[prop];
} else if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
define(function() { return Klass; });
@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

@bgerrissen
bgerrissen / js-loader.js
Created May 24, 2011 09:05
Robust cross browser JS Loader for dependency management.
/**
* Author: Ben Gerrissen
* Date: 9-3-11
* License: MIT
*/
(function( global ){
var undefined
, preloads = false