Skip to content

Instantly share code, notes, and snippets.

View mde's full-sized avatar

Matthew Eernisse mde

View GitHub Profile
// 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;
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;
@mde
mde / gist:967610
Created May 11, 2011 23:20
HTML markdown viewer
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="./showdown.js"></script>
<title>
Markdown Viewer
</title>
<style type="text/css">
@mde
mde / gist:1005311
Created June 2, 2011 20:57
JS inheritance stuff
var MyThing = function () {
this.a = function () {
};
this.b = [];
this.c = 'foo';
};
MyThing.prototype = new (function () {
var MY_SETTING = 2112;
var _myPrivateFunc = function () {
js> null > -1;
true
js> null < 1;
true
js> null > 0;
false
js> null < 0;
false
js> null == 0;
false