Skip to content

Instantly share code, notes, and snippets.

View mdobson's full-sized avatar
😺
Petting a cat

Matthew Dobson mdobson

😺
Petting a cat
View GitHub Profile
@mdobson
mdobson / gist:5163258
Last active December 14, 2015 23:08
Basic UserGrid Queries
//Setting query parameters in javascript.
//Begin with initializing your client
var client = new Usergrid.Client({
"orgName":"",
"appName":""
});
//Setup an options object that contains the query language you'd
//like to filter your data with. This query will look for all
@mdobson
mdobson / gist:5163276
Last active December 14, 2015 23:08
Geolocation in UserGrid query
//Geolocation query against a restaurants collection.
//Geolocation queries are just another subset of queries
//that can be done in App Services. There aren't any differences
//in how you perform a geolocation query and other queries/
//Remember that the distance is in meters!
var client = new Usergrid.Client({
"appName":"",
"orgName":""
});
@mdobson
mdobson / gist:5165602
Last active December 14, 2015 23:29
Connecting entities in javascript
//We want to fred to follow barney!
//Intialize your client
var client = new Usergrid.client({
"orgName":"",
"appName":""
});
//Setup entity retrieval options.
//Here we are going to get the user named fred.
@mdobson
mdobson / gist:5165651
Last active December 14, 2015 23:28
Getting all followers in javascript
//Getting all of fred's followers
var client = new Usergrid.Client({
"appName":"",
"orgName":""
});
client.getLoggedInUser(function(error, data, fred){
//Get the "followers" connection here!
fred.getConnections("followers", function(error, data, connections){
for(var i = 0; i < connections.length; i++) {
@mdobson
mdobson / gist:5165704
Last active December 14, 2015 23:29
Connecting entities through a like
//Connecting fred likes dino the dog!
var client = new Usergrid.Client({
"appName":"",
"orgName":""
});
var options = {
"type":"dog",
"dogName":"Dino"
};
@mdobson
mdobson / sketchy.js
Created March 19, 2013 13:09
Sketchily extending our Usergrid SDK for supporting some introspection for codecademy.
var extension = Usergrid.Client.prototype.getEntity;
function logGetEntity(options){
console.log("In get entity");
console.log(JSON.stringify(options));
}
Usergrid.Client.prototype.getEntity = function(options, callback){
extension.apply(this, arguments);
logGetEntity(options);
@mdobson
mdobson / inject.js
Created March 26, 2013 18:10
Prototypical Injection useful for codecademy unit tests.
var sub = Usergrid.Client.prototype.getFeedForUser;
Usergrid.Client.prototype.getFeedForUser = function(user, callback){
sub.call(this, user, function(err, data, acts){
console.log("err:"+err);
console.log("data:"+data);
console.log("acts:"+acts);
callback(err, data, acts);
});
}
var createCollection = Usergrid.Client.prototype.createCollection;
Usergrid.Client.prototype.createCollection = function(options, callback){
createCollection.call(this, options, function(err, entityCollection){
//Here is where we access the callback results
callback(err, entityCollection);
});
}
@mdobson
mdobson / gist:5665913
Created May 28, 2013 20:36
PhoneGap .gitignore
.DS_Store
*.mode1v3
*.pbxuser
*.perspective
*.perspectivev3
*.pyc
*~.nib/
build/*
xcuserdata
@mdobson
mdobson / gist:5807345
Last active December 18, 2015 15:49
create book in obj-c
UGClientResponse *response = [self.client createEntity:book];
//Lets check if our response was accepted by the server, and add the created object to a collection called _objects
if (response.transactionState == kUGClientResponseSuccess) {
[_objects insertObject:response.response[@"entities"][0] atIndex:0];
}