Skip to content

Instantly share code, notes, and snippets.

View gaboelnuevo's full-sized avatar

Gabriel S. L gaboelnuevo

View GitHub Profile
@gaboelnuevo
gaboelnuevo / Readme.md
Created July 30, 2017 02:46
Loopback Facebook login

"passport-facebook-token": "^3.3.0",

=CONCAT(CONCAT(CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(65,90)),CHAR(RANDBETWEEN(97,122)))&CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(65,90)),CHAR(RANDBETWEEN(97,122))), CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(65,90)),CHAR(RANDBETWEEN(97,122)))&CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(65,90)),CHAR(RANDBETWEEN(97,122)))), CONCAT(CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(65,90)),CHAR(RANDBETWEEN(97,122)))&CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(65,90)),CHAR(RANDBETWEEN(97,122))), CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(65,90)),CHAR(RANDBETWEEN(97,122)))&CHOOSE(RANDBETWEEN(1,2),CHAR(RANDBETWEEN(65,90)),CHAR(RANDBETWEEN(97,122)))))
var express = require('express');
var app = express();
var url = "https://username.jsreportonline.net/";
var client = require("jsreport-client")(url, "[email protected]", "password");
app.get('/', function (req, res) {
res.send('Go to /report or /base64');
@gaboelnuevo
gaboelnuevo / Loopback facebook login
Created October 13, 2016 03:59
loopback.io: Facebook login with out cookie (only json)
npm install --save passport-facebook-token
Then add this entry in providers.json:
"facebook-mobile" : {
"provider": "facebook-token",
"module": "passport-facebook-token",
"strategy": "FacebookTokenStrategy",
"clientID": "XXXXXXX",
"clientSecret": "XXXXXXX",
"callbackPath": "/auth/facebook-token/callback",
@gaboelnuevo
gaboelnuevo / knockout-tags.js
Last active October 12, 2016 19:17 — forked from droyad/knockout-tags.js
Knockout binding for Tagit
// Based on https://gist.github.com/droyad/6136446
// Use with a observableArray.
// Example:
// <ul data-bind="tags: Tags"></ul>
ko.bindingHandlers.tags = {
init: function(element, valueAccessor, allBindingsAccessor) {
var bind = function() {
@gaboelnuevo
gaboelnuevo / model.js
Created July 8, 2016 21:30
Loopback.io current user
// common/models/model.js
app.models.Model.beforeRemote('create', function(ctx, modelInstance, next) {
ctx.args.data.userId = ctx.req.accessToken.userId;
next();
});
@gaboelnuevo
gaboelnuevo / authentication.js
Created July 8, 2016 21:24
Loopback user literal
// server/boot/authentication.js
server.middleware('auth', loopback.token({
model: server.models.accessToken,
currentUserLiteral: 'me'
}));
@gaboelnuevo
gaboelnuevo / Normalizer.js
Created July 5, 2016 14:39
Normalizr takes JSON and a schema and replaces nested entities with their IDs, gathering all entities in dictionaries.
// App/Services/Normalizer.js
import { Schema, arrayOf, normalize } from 'normalizr'
import { camelizeKeys } from 'humps'
const normalizer = (data, schema) => {
const camelizedJson = camelizeKeys(data)
return normalize(camelizedJson, schema)
}
@gaboelnuevo
gaboelnuevo / place.js
Created June 2, 2016 03:51
Loopback geopoint nerby place example
module.exports = function(Place) {
Place.nearby = function(here,cb){
Place.find({where: {location: {near: here}}, limit:3}, function(err, nearbyPlaces) {
cb(null, nearbyPlaces);
});
};
Place.remoteMethod('nearby', {
accepts: [
{arg: 'here', type: 'GeoPoint', required: true, description: 'geo location (lat & lng)'}
@gaboelnuevo
gaboelnuevo / gist:35ed9e96e8194b103fad
Created September 13, 2015 23:35
loopback: Model filtered properties
var FILTERED_PROPERTIES = ['createdAt', 'updatedAt'];
Model.observe('before save', function filterProperties(ctx, next) {
if (ctx.options && ctx.options.skipPropertyFilter) return next();
if (ctx.instance) {
FILTERED_PROPERTIES.forEach(function(p) { ctx.instance.unsetAttribute(p); });
} else {
FILTERED_PROPERTIES.forEach(function(p) { delete ctx.data[p]; });
}
next();
});