Skip to content

Instantly share code, notes, and snippets.

@connortreacy
connortreacy / gist:6dc7ea54a6673775d78d
Last active August 29, 2015 14:03
Getting a Parse.User for an authenticated Facebook user.
function authenticateParseUser(authResponse) {
Parse.FacebookUtils.logIn({
id: authResponse.userID,
access_token: authResponse.accessToken,
expiration_date: moment().add('s', authResponse.expiresIn).format()
}).then(function(user){
/* Do useful stuff with your new Parse.User */
}, function(error){
/* Something went wrong with the authentication */
});
@connortreacy
connortreacy / parsedate
Last active December 30, 2015 09:18
Function for 'parsing' a datestamp in the format returned by Parse for the createdAt / updatedAt fields. Written in JavaScript, but the regex is portable.
var parseDate = function(parseDateString) {
var pattern = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d+)Z$/g;
var match = pattern.exec(parseDateString);
var date = new Date(match[1],parseInt(match[2])-1,match[3]-1,match[4],match[5],match[6],match[7]);
return date;
};