Skip to content

Instantly share code, notes, and snippets.

View mde's full-sized avatar

Matthew Eernisse mde

View GitHub Profile
@mde
mde / gist:3825a3732effbe76ee62
Created May 19, 2015 23:49
JavaScript "this"
var foo = {
a: function () {
console.log(this);
}
};
foo.a(); // Logs the foo obj
foo['a'](); // Same, logs the foo obj
@mde
mde / gist:ae752b3bb4a66c152371
Created June 20, 2015 04:54
PropagateAction mixin
import Ember from 'ember';
export default Ember.Mixin.create({
_sendActionPropagateChannel: '_sendActionPropagateChannel',
actions: {
_sendActionPropagateChannel: function () {
try {
this.send.apply(this, arguments);
}
catch (err) {
// If foo is true, then we do all this stuff
if (foo) {
// Do foo stuff
}
// This is the stuff that happens in the else case
else {
// asdf here is 'QWER' because we like it
var asdf = 'QWER';
// zoobie ... well, what to say about zoobie
var zoobie = 'FRANG';
var wm = windmill.jsTest;
var asserts = windmill.controller.asserts;
var test_openProject = new function () {
this.test_click = function () {
wm.actions.click( { link: "Food" } );
};
this.test_wait = { method: "waits.forPageLoad", params: { timeout: "20000" }};
// Totally naive mixin for demonstration purposes
var mixInProperties = function (to, from) {
for (var p in from) {
to[p] = from[p];
}
}
// Base pseudoclass
var InheritedCodeObj = function (id) {
this.id = id || '(none)';
var isArray = function (obj) {
return obj &&
typeof obj === 'object' &&
typeof obj.length === 'number' &&
typeof obj.splice === 'function' &&
!(obj.propertyIsEnumerable('length'));
};
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
div {
border: 1px solid red;
width: 400px;
}
textarea {
margin: 0 -11px;
@mde
mde / iterative_cps.js
Created September 22, 2015 00:06
Iterative, but CPS
var iterativeRunner = function (arr) {
var funcs = arr.map(function (item, index) {
return function () {
item(function () {
if (funcs[index + 1]) {
funcs[index + 1]();
}
});
};
});
node> var parentFunc = function () { this.a = []; };
node> typeof parentFunc;
'function'
node> var foo = new parentFunc();
node> foo;
{ a: [] }
node> var subFunc = function () {};
node> subFunc.prototype = foo;
{ a: [] }
node> var bar = new subFunc();
var assertImageLoaded = function (img) {
var complete = img.complete;
// Workaround for Safari -- it only supports the
// complete attrib on script-created images
if (typeof complete == 'undefined' || complete === false) {
var test = new Image();
// If the original image was successfully loaded,
// src for new one should be pulled from cache
test.src = img.src;
complete = test.complete;