Skip to content

Instantly share code, notes, and snippets.

View Raynos's full-sized avatar

Jake Verbaten Raynos

View GitHub Profile
@Raynos
Raynos / jQuery.md
Created January 14, 2012 22:44
Why you don't need jQuery

Why the jQuery Abstraction isn't needed.

(One needs some form of browser normalization so that modern features works, no-one is doubting that).

Related: [jQuery library critique][2]

Abstractions that aren't needed

Selectors

var Point = {
constructor: function constructor(x, y) {
this.x = x;
this.y = y;
return this;
},
dist: function dist() {
return Math.sqrt((this.x * this.x) + (this.y * this.y));
},
toString: function toString() {
@Raynos
Raynos / wrap-modules.js
Created January 15, 2012 12:48
minimal define/require boilerplate
/*
Server side tool minimises the path to file to a small string.
It then goes and recompiles every require call to that path to be that string
Hopefully closure compiler will optimize module -> m and optimise m.exports -> m.e
*/
// define
define("/path/to/file", function (require, module) {
// your code should require some other things
(function (modules) {
var getBuild = function (build) {
return function (ignore, module) {
module.exports = build.exports;
};
};
var getModule = function (scope, tree, path) {
var name, dir, exports = {}, module = { exports: exports }, require, build;
path = path.split('/');
name = path.pop();
int some_method() {
SOME_STRUCT* reallyBigObject = malloc(sizeof(SOME_STRUCT));
// FORGET TO DEREFERENCE reallyBigObject
return 42;
}
(function () {
/*
totally future proof.
*/
var hostElementPrototype = window.Element && window.Element.prototype;
if (!!hostElementPrototype && ! "nextElementSibling" in hostElementPrototype ) {
// .defineProperty for IE8 & modern, defineProperty shim for legacy non-IE
@Raynos
Raynos / x.md
Created January 17, 2012 22:27
Host objects

Why use or shim host objects?

Shims allow you to work without a browser compliance or without a browser abstraction library. Modern browsers have enough native and host APIs that you do not need any third party libraries for these features, you just need shims as your legacy browser compliance strategy.

Standard APIs

Host objects defined in the WHATWG and W3C specifications are standard APIs. They are well known, readable and maintainable. They are highly optimised and efficient.

Consider getElementsByClassName, you can either use it and have a shim for non-compliant browsers. This gives you maximum performance for compliant browsers, good performance for non-compliant browsers.

@Raynos
Raynos / weak-map.js
Last active September 18, 2019 07:49 — forked from Gozala/weak-map.js
Harmony WeakMap shim for ES5
// Original - @Gozola. This is a reimplemented version (with a few bug fixes).
window.WeakMap = window.WeakMap || (function () {
var privates = Name()
return {
get: function (key, fallback) {
var store = privates(key)
return store.hasOwnProperty("value") ?
store.value : fallback
},
var Base = require('./base')
module.exports = Reporter;
function Reporter(runner) {
Base.call(this, runner);
/*
suite: { title: String }
*/
@Raynos
Raynos / x.js
Created January 19, 2012 08:39
// empty suite
var suite = new mocha.Suite(),
BaseReporter = mocha.reporters.Base,
// our runner
Reporter = function () { ... };
// force tdd (or bdd or exports) style on suite
mocha.interfaces.tdd(suite);
// create runner