This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// note, this file should actually be /codez/foo.js but gist won't allow folders | |
var req = require('request'); | |
module.exports.foo = function() { | |
console.log('wrapped? making HTTP request'); | |
req.get('http://www.thejoyofcode.com', function(error, response, body) { | |
console.log('http status code: ' + response.statusCode); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var req = require('request'); | |
function insert(item, user, request) { | |
item.userId = user.userId; | |
if (user.userId.indexOf('Twitter:') === 0) { | |
var twitterId = user.userId.replace('Twitter:', ''); | |
req.get('https://api.twitter.com/1/users/show.json?user_id=' + twitterId, | |
function(error, result, body) { | |
item.imageUrl = ''; | |
if (error || result.statusCode != 200) { console.error(error || result); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var watch = require('watch'); | |
var util = require('util'); | |
var sys = require('sys'); | |
var exec = require('child_process').exec; | |
var service = process.argv[2]; | |
var directory = process.argv[3] || __dirname; | |
console.log('Mobile Service name: ', service); | |
console.log('Directory: ', directory); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the insert script that encrypts the text column | |
var crypto = require('crypto'); | |
function insert(item, user, request) { | |
// your encryption key - choose something better and randomly generated in real-life | |
var password = 'zumoisawesome' | |
var cipher = crypto.createCipher('aes256', password); | |
var output = cipher.update(item.text, 'utf-8', 'base64'); | |
item.text = output + cipher.final('base64'); | |
// go ahead, insert the modified data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function zumoJwt(expiryDate, aud, userId, masterKey) { | |
var crypto = require('crypto'); | |
function base64(input) { | |
return new Buffer(input, 'utf8').toString('base64'); | |
} | |
function urlFriendly(b64) | |
{ | |
return b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, ''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fetchBasicProfile(user, callback) { | |
var req = require('request'); | |
var util = require('util'); | |
var sep = user.userId.indexOf(':'); | |
var profile = {}; | |
profile.source = user.userId.substring(0, sep).toLowerCase(); | |
profile.id = user.userId.substring(sep + 1); | |
var createError = function(e, r) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .NET C# | |
var mobileServiceClient = new MobileServiceClient("<your-app-url>", "<your-app-key>"); | |
mobileServiceClient.CurrentUser = new MobileServiceUser("Foo:123456789"); | |
mobileServiceClient.CurrentUser.MobileServiceAuthenticationToken = "<your-users-JWT>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a modified App.xaml.cs file from the Mobile Services quickstart, showing how to add the AuthFilter above | |
private static MobileServiceClient GetClient() | |
{ | |
var client = new MobileServiceClient( | |
"<your-app-url>", | |
"<your-app-key>" | |
); | |
var filter = new AuthFilter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the MSFilter protocol implementation taken from the iOS Mobile Services'\ | |
// quickstart and modified to log the user in if a 401 Unauthorized response is received | |
#pragma mark * MSFilter methods | |
- (void) handleRequest:(NSURLRequest *)request | |
onNext:(MSFilterNextBlock)onNext | |
onResponse:(MSFilterResponseBlock)onResponse | |
{ | |
// Increment the busy counter before sending the request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <WindowsAzureMobileServices/WindowsAzureMobileServices.h> | |
@interface MSClient (CustomId) <MSFilter> | |
- (void) registerUsername:(NSString *) username withPassword: (NSString *) password withCompletion: (MSItemBlock) completion; | |
- (void) loginUsername:(NSString *) username withPassword: (NSString *) password completion: (MSClientLoginBlock) completion; | |
@end |
OlderNewer