Skip to content

Instantly share code, notes, and snippets.

View philmander's full-sized avatar

Phil Mander philmander

View GitHub Profile
@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-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 / 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 / app-config.js
Last active December 10, 2015 08:38
inverted intro 3: app config
define(function() {
return {
protos: {
movieLister: {
module: "movies/movie-lister",
args: [
"*jsonMovieFinder"
]
},
jsonMovieFinder: {
@philmander
philmander / inverted-movie-app.js
Last active December 10, 2015 08:38
inverter intro 3: using app context
require(["inverted", "app-config"], function(inverted, conf) {
var appContext = inverted.create(conf);
appContext.getProto("movieLister", function(movieLister) {
movieLister.showMovies();
};
});
@philmander
philmander / inverted-instantiation-1.js
Last active December 10, 2015 10:29
Simple example of how to instantiate objects with Inverted
//movies/move-lister.js
define(function() {
var MovieLister = function() {
//constructor stuff
};
return MovieLister;
});
//movies/move-viewer.js
define(function() {
@philmander
philmander / inverted-intro-1-1.js
Last active January 19, 2016 14:32
First inverted intro with no dependency injection
// movies/movie-lister.js
define(["movies/json-movie-finder"], function(MovieFinder) {
var MovieLister = function() {
//hard coded dependency
this.movieFinder = new MovieFinder();
};
MovieLister.prototype.showMovies = function(query) {
@philmander
philmander / inverted-intro-2-1.js
Last active December 10, 2015 10:38
Inverted intro 2 with dependency injection
//movies/movie-lister.js
define(function() {
var MovieLister = function(movieFinder) {
this.movieFinder = movieFinder;
};
MovieLister.prototype.showMovies = function(query) {