Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@unscriptable
unscriptable / js-to-java.js
Created December 20, 2010 20:28
How to communicate between javascript and java applet
var myApplet = funcToGetApplet();
myApplet.setCallback({
myMethod: function (args) {
// do something with args here
},
anotherMethod: function (args) {
// do something with args here
@unscriptable
unscriptable / Stateful.js
Created December 24, 2010 05:05
cujo.Stateful
/*
cujo.Stateful
(c) copyright 2010, unscriptable.com
author: john
LICENSE: see the LICENSE.txt file. If file is missing, this file is subject to the AFL 3.0
license at the following url: http://www.opensource.org/licenses/afl-3.0.php.
Adds dojo.Stateful behavior to objects without the dojo.declare turds and overhead
<!-- dojo 1.x: all is well -->
<button dojotype="li.widget.Button" type="button" class="flat">Flat button</button>
<!-- dojo 1.6 html5 type and params attr -->
<button data-dojo-type="li.widget.Button" data-dojo-params="type:'button', class:'primary'">Primary button</button>
<!-- dojo 1.6 html5 type and native attrs: DOES NOT PICK UP ATTRS! -->
<button data-dojo-type="li.widget.Button" type="button" class="secondary">Secondary button</button>
@unscriptable
unscriptable / tiny Promise.js
Created February 7, 2011 06:02
A minimalist implementation of a javascript promise
// (c) copyright unscriptable.com / John Hann
// License MIT
// For more robust promises, see https://github.com/briancavalier/when.js.
function Promise () {
this._thens = [];
}
Promise.prototype = {
// Object Pascal separates each unit (file) into two main sections:
// interface and implementation.
// interface declares all of the publicly-facing stuff and has a
// list of dependencies (uses) implementation is the actual code
// and is private. it can have additional dependencies that the
// the interface doesn't have (and it's a good idea to keep as
// many out of the interface as possible to prevent circular
// dependencies).
module('optional name')
[{"match":"/BlackBerry.+AppleWebKit\\/([\\d\\.]+)/","name":"BlackBerry","version":400,"has":{"activex":false,"activex-enabled":false,"array-es5":true,"array-every":true,"array-filter":true,"array-foreach":true,"array-indexof":true,"array-isarray":true,"array-lastindexof":true,"array-map":true,"array-reduce":true,"array-reduceright":true,"array-slice-nodelist":true,"array-some":true,"audio":true,"audio-m4a":true,"audio-mp3":true,"audio-ogg":true,"audio-wav":true,"bug-arguments-instanceof-array":false,"bug-array-concat-arguments":false,"bug-bgimagecache":true,"bug-computed-style-hidden-zero-height":false,"bug-computed-values-for-static":false,"bug-contains":false,"bug-dontenum-enumerable":false,"bug-es5-regexp":true,"bug-es5-trim":true,"bug-function-expression":false,"bug-getelementbyid-ids-names":false,"bug-getelementbyid-ignores-case":false,"bug-getelementsbyname":false,"bug-getelementsbytagname-returns-comment-nodes":false,"bug-offset-values-positioned-inside-static":false,"bug-overflow-style":false,"bug-pre
@unscriptable
unscriptable / opera script load order.txt
Created March 14, 2011 21:22
Opera doesn't fire load events in the same order as the scripts are loaded
Firefox:
script1 executes
script1 fires load event
script2 executes
script2 fires load event
script3 executes
script3 fires load event
@unscriptable
unscriptable / IOC-DI.js
Created May 11, 2011 23:00
IOC/DI as an alternative to module swapping
// admittedly, dependency injection is better for non-integral dependencies.
// integral dependencies like coding constructs such as array iterators (forEach),
// type detectors (isArray, isFunction), etc are easier to work with as declared
// dependencies/modules. there are other ways to inject dependencies (e.g.
// constructor params). this is just how we're doing it.
// this example shows the injection of non-integral dependencies
define(function () {
return {
@unscriptable
unscriptable / another-way.js
Created May 12, 2011 20:49
AMD-compatible CommonJS Module/1.1 that can also be loaded in a script tag
// This boilerplate would allow a module to run in node.js or an
// AMD-enabled browser environment. On node.js, the syntax is:
// var Color = require("./Color").Color,
// color = new Color("#BADA55");
// In the browser, the syntax is:
// var color = new Color("#BADA55"); // window.Color is implied
(function (define) {
define(function () {