Skip to content

Instantly share code, notes, and snippets.

View philmander's full-sized avatar

Phil Mander philmander

View GitHub Profile
@philmander
philmander / casper.fetchMicrodata.js
Last active August 29, 2015 13:58
Microdata util for CasperJS
//microdata polyfill (see https://github.com/termi/Microdata-JS)
casper.options.clientScripts.push("../../../support/a.js");
casper.options.clientScripts.push("../../../support/microdata-js.js");
/**
* Fetches microdata from the remote DOM environment, in a json object structure.
* @param itemType The item type of item scopes to fetch data for
* @returns {Object|mixed}
*/
casper.fetchMicrodata = function(itemType) {
@philmander
philmander / casper.test.assertMicrodata.js
Last active August 29, 2015 13:58
Assert Microdata test util for Casper JS. Requires https://gist.github.com/philmander/10012466
/**
* Asserts a microdata item value matches the given expected value in the remote DOM environment
* Depends on the casper.fetchMicrodata method
*
* @param itemType {String} The item type of the item scopes to look for properties in
* @param property {String} The name of the property the compare the expected value against
* @param expectedItemValue {String} The expected value of the item property
* @param message {String} The assertion message
* @param itemTypeIndex {Number} A specific index of an item scope to use. If omitted or null, will look for matches in
* all item scopes
@philmander
philmander / gulpdir
Created July 3, 2014 13:36
Litlle function for concatenating file names in gulp
//little util to do tidier directory concatenation
function dir() {
var args = Array.prototype.slice.call(arguments);
var prefix = "";
if(args[0] === "!") {
prefix = args[0];
args.shift();
}
return prefix + args.join("/");
}
@philmander
philmander / reduce-array-to-html.js
Last active August 29, 2015 14:12
Object array to html string with Array.reduce()
var items = [{
html: '<p>One</p>'
}, {
html: '<p>Two</p>'
}, {
html: '<p>Three</p>'
}];
var html = items.reduce(function(html, item) {
html.push(item.html);
@philmander
philmander / cssembed-ant-1.xml
Created September 5, 2011 20:55
Data URIs and automation with CSSEmbed and Ant 1
<?xml version="1.0"?>
<project default="cssDataUriEmbed" basedir="." xmlns:ca="antlib:net.sourceforge.clearantlib">
<property name="build.dir" location="${basedir}/build" />
<property name="websrc.dir" location="${basedir}/WebContent" />
<taskdef name="cssurlembed" classname="net.nczonline.web.cssembed.CSSEmbedAntTask" >
<classpath>
<fileset dir="${basedir}/lib" includes="cssembed-0.3.3.jar"/>
</classpath>
</taskdef>
<target name="setup">
@philmander
philmander / cssembed-ant-2.html
Created September 5, 2011 20:56
Data URIs and automation with CSSEmbed and Ant 2
<!--[if !IE]>-->
<link type="text/css" rel="stylesheet" href="/css/site-datauri.css">
<!--<![endif]-->
<!--[if gte IE 9]>
<link type="text/css" rel="stylesheet" href="/css/site-datauri.css">
<![endif]-->
<!--[if lte IE 8]>
<link type="text/css" rel="stylesheet" href="/css/site-mhtml.css">
<![endif]-->
@philmander
philmander / interface-1.js
Created September 5, 2011 20:38
Javascript interfaces revisited 1
var Dog = [
"bark", "eat", "defecate"
];
var Poodle = function(name) { //implements Dog
this.name = name;
};
Poodle.prototype = {
bark: function() {},
eat: function() {},
defecate: function() {}
@philmander
philmander / interface-2.js
Created September 5, 2011 20:42
Javascript interfaces revisited 2
//a car factory
var CarFactory = {
getTires: function() {
if(weather.raining) {
return new WetTireSet();
}
else {
return new SlickTireSet();
}
}
@philmander
philmander / cssembed-ant-3.html
Created September 5, 2011 21:00
Data URIs and automation with CSSEmbed and Ant 3
<script>
(function() {
function addStylesheet(dataUriHref, fallbackHref) {
var img = new Image();
img.onload = img.onerror = function() {
var link = window.document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = this.width !== 1 ? fallbackHref : dataUriHref;
@philmander
philmander / casperjs-website-resolution-tester.js
Created October 4, 2015 16:30
CasperJS Website Resolution Tester
var casper = require('casper').create({
verbose: true,
logLevel: 'info'
});
var page = require('webpage').create();
var utils = require('utils');
//args
var base = casper.cli.get('out');
var width = parseInt(casper.cli.get("width"));