Skip to content

Instantly share code, notes, and snippets.

exports.urlMap = function(map, nextApp){
return function(request){
for (var i = 0; i<map.length; i++){
var match = map[i][0];
var ctor = map[i][1];
var returnRequest = map[i][2];
if (request.pathInfo.match(match)){
print("found match:", match);
var res = ctor(request, match);
if (res && returnRequest) return res;
var session = new Session({url: "http://192.168.5.16:4444/wd/hub"})
var capabilities = session.startSession({browserName: "internet explorer"});
var url = "http://google.com";
when(capabilities,function(capabilities){
print("Connected to Session");
print("sessionId: " + capabilities.sessionId);
print("Session Props: " + json.stringify(capabilities));
pshallow(capabilities);
@dmachi
dmachi / dynrequire.js
Created November 27, 2010 17:56
wrapped dojo require to work around addOnLoad issue in xd when the module has already been loaded
// check to see if this loaded module already exists. Returns a deferred that will already be resolved or
// or will resolve with an addOnLoad after the require
var dynrequire = function(names){
var def = new dojo.Deferred();
var loading=false;
dojo.forEach(names, function(n){
if (!dojo._loadedModules[n]){
dojo.require(n);
loading=true;
@dmachi
dmachi / getChildren
Created December 2, 2010 16:07
Recursive tree item getter for tree.
var getChildren = function(model, item){
children = [];
if (model.mayHaveChildren(item){
var ch = model.getChildren(item);
dojo.forEach(ch, function(child){
children.push(child)
children = children.concat(getChildren(model, child));
});
}
return children;
#content {
border: 3px solid gray;
height: 300px;
width: 150px;
}
@dmachi
dmachi / pom.xml
Created December 8, 2010 22:22
maven profile example for generating and copying docs.
<profile>
<id>docs</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
@dmachi
dmachi / gist:751880
Created December 22, 2010 18:25
Example resolve RQL expression
Here are some examples for an idea i had for the depth resolution of items in persevere using rql.
On the clientside, we could translate these functions into a resolve property of the store.get()'s option
parameter (store.get("something", {resolve:[1]}) for example). It would be nice if on the client side we
could decide upon a way to resolve references that will be consistent across implementations, but I'm
still thinking about it. In the mean time, here is the resolve() idea.
Resolutions - These RQL expressions resolve any links contained in an object to the depth identified
by the first parameter. Subsequent parameters are array of properties that should be the
only properties that get resolved at a particular level. ?resolve(depth,depth1list,depth2list,depth3list,...)
@dmachi
dmachi / MultiRest.js
Created December 23, 2010 02:02
MultiRest store that wraps JsonRest and Cache for the dojo.store system.
define("dojo/store/MultiRest", ["dojo","dojo/store/JsonRest","dojo/store/Cache", "dojo/store/Memory"], function(dojo) {
var MultiRest=function(options){
// summary:
// MultiRest store is provided with a targetUrl and schemaUrl to allow multiple JsonRest stores/data
// types to be treated as a single dojo.store and to manage json-schema relationships. Requests to
// standard api calls (get,query,put,delete,etc) require a schema or schemaId to be passed in the
// directives to know how to interpret the items / requests. Requests can also include a resolve
// array to tell a get() or query() request to recursively retrieve and add in related objects
// available on the schema.links and requested in the resolve array.
@dmachi
dmachi / multirest example.js
Created January 5, 2011 03:49
example using deep resolution
return dojo.when(app.persevere.getStore("Project"),
function(store){
return dojo.when(store.get(data,{resolve: [["triggers"],["destination"],["jobs"]]}),
function(data){
var triggers=[];
var queues=[];
var activity=[];
if(!data|| !data.triggers){
return;
}
@dmachi
dmachi / projectschema.json
Created January 5, 2011 04:17
schema with relations
{
"properties": {
"state": {
"type": "string",
"indexed": true
},
"description": {
"type": "string",
"optional": true
},