Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@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.html
Last active February 12, 2024 00:36
async module "factory" evaluation for inline module declarations. I want to ensure that our AMD+CJS tools have consistent behavior with ES6.
<script>
var flag;
// this variable is the interesting bit
flag = "initial value";
define('unicorn', function (require, exports) {
var rainbow = require('rainbow');
@unscriptable
unscriptable / isolate.md
Last active February 12, 2024 00:37
example of possible curl/tdd/isolate

curl/tdd/runner is a bit complicated atm. Just thinking of something that might be a bit simpler:

curl(['curl/tdd/isolate'], function (isolate) {

	// inject AMD `require` and `define`, as well as a "done" callback.
	// the test function is guaranteed to run in isolation and all modules 
	// are undefined afterward.
	isolate(function test (require, define, done) {
var dfd, p1;
dfd = defer();
p1 = dfd.promise;
p1.then(null, function () { console.log('onRejected 1 failed'); });
p1.then(null, function () { console.log('onRejected 2 failed'); });
dfd.reject('wat');
@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' };
});
@unscriptable
unscriptable / main_spec.js
Last active February 12, 2024 00:37
todomvc with an additional "properties view"
define({
// Cujo uses OOCSS principles and thus separates theme (skin)
// from structure CSS.
theme: { module: 'css!theme/base.css' },
// The root node where all the views will be inserted
root: { $ref: 'dom!todoapp' },
// Render and insert the create view
@unscriptable
unscriptable / curl+plain-js.md
Last active February 12, 2024 00:37
should curl.js support non-modules natively?

Q: should curl.js support non-modules natively?

from original Pull Request

Proposal:

code is here

  • Auto-define a module if dev includes a ".js" extension (inject a noop factory: function () {})
  • Fail if the dev used a ".js" extension with modules (define()s found in file)
@unscriptable
unscriptable / hide-replies-bkmklet.js
Last active February 12, 2024 00:38
bookmarklet to collapse all replies and retweets on a person's twitter timeline feed page
javascript:/**(c)2013_unscriptable.com.License:MIT*/(function(){var a=document;try{var b;if(!a.getElementById("page-container"))throw"Are you sure you're on a Twitter page?";b=a.getElementById("collapse-stuff");b||(b=a.createElement("style"),b.id="collapse-stuff",a.head.appendChild(b));0==b.sheet.cssRules.length?b.sheet.insertRule("[data-mentions],[data-retweet-id]{display:none}",0):b.sheet.deleteRule(0)}catch(c){alert("Oops! "+c+" That didn't work :(")}}());
@unscriptable
unscriptable / run-module.js
Last active February 12, 2024 00:38
run.js versus main module
/**
* The bootstrap for the app is a module. The weird thing about this option
* is that it uses curl(), rather than require(), inside the module to load
* other modules, such as the app's main module.
* The script element to execute this bootstrap would look like this:
*
* <script data-main="client/run-module" src="client/lib/curl.js"></script>
*/
define(['curl'], function (curl) {
@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 {';