Corona Admob plugin not working with other plugin - plugins

I have a Corona application. If I am using both Admob and Share plugin its crashing in my device. If I use any one its working fine.
Here is the code of setting file
plugins =
{
["plugin.google.play.services"] =
{
publisherId = "com.coronalabs",
},
},
{
["CoronaProvider.native.popup.social"] =
{
publisherId = "com.coronalabs",
},
},
Is there anything wrong with the code.

I got the issue. The code was wrong. It should like this.
plugins =
{
["plugin.google.play.services"] =
{
publisherId = "com.coronalabs",
},
["CoronaProvider.native.popup.social"] =
{
publisherId = "com.coronalabs",
},
},

Related

Insert Multiple records in dynamodb using api gateway

How can I insert multiple rows in dynamodb using body mapping template of API gateway?
Input to my code is "xyz 1,abc 2" which has information about 2 rows to be inserted.
Only second record which is "abc 2" is getting stored, I want both records to be inserted in the table. Below is the code I have written
#set($rawAPIData = $input.path('$'))
#set ($bulk = $rawAPIData.split(","))
{
"TableName": "tablename",
#foreach( $records in $bulk)
#set ($s = $records.split(" "))
"Item": {
"col1": {
"S": "$s.get(0)"
},
"col2": {
"S": "$s.get(1)"
}
}
#if( $foreach.hasNext ), #end
#end
}
I'm new to this, suggestion would really help
This AWS guide shows how to use API Gateway as a proxy for DynamoDB. It's similar the approach you are trying to take. As a suggestion, it might be better have your api focus on a single row at a time, rather than splitting multiple inputs on ,. For example it would simplify your template somewhat to send requests similar to those found in the guide.
Example Request Body:
{
"col1": "xyz",
"col2": "1"
}
Template (derived from your template code):
{
"TableName": "tablename",
"Item": {
"col1": {
"S": "$input.path('$.col1')"
},
"col2": {
"S": "$input.path('$.col2')"
}
}
}
However, if you want to stick to operating on multiple items, The BatchWriteItem documentation would be worth a read. Following the example, I think this should be your body template:
#set($rawAPIData = $input.path('$'))
#set ($bulk = $rawAPIData.split(","))
{
"RequestItems": {
"tablename": [
#foreach($records in $bulk)
#set ($s = $records.split(" "))
{
"PutRequest": {
"Item": {
"col1": {
"S": "$s.get(0)"
},
"col2": {
"S": "$s.get(1)"
}
}
}
}
#if( $foreach.hasNext ),
#end
]
}
#end
}
I used the similar approach as #Gerand, but I solved it using lambda. Here is the working code:
'use strict';
const AWS = require("aws-sdk");
const dynamodb = new AWS.DynamoDB();
exports.handler = (event, context, callback) => {
var data=event.data;
var bulk = data.split(",");
var toSave = [];
for(var i = 0; i < bulk.length; i++) {
var s=bulk[i].split(" ");
var item = {
"col1": {
S: s[0]
},
"col2": {
S: s[1]
}
};
toSave.push(item);
}
var items = [];
for(var i = 0; i < toSave.length; i++) {
items[i] = {
PutRequest: { Item: toSave[i] }
}
}
var params = {
RequestItems: {
'table_name': items
}
};
dynamodb.batchWriteItem(params, function(err, data) {
console.log("Response from DynamoDB");
if(err) console.log(err);
else console.log(data);
});
};

Karma debugging in Chrome no longer working

We are working on an Angular project where we are using Karma/Jasmine for our testing environment. We've been using the karma-chrome-launcher for debugging the tests and it was working great. For some reason, it has stopped working lately. I can't figure out why though, as we haven't changed anything regarding that pipeline. We tried updating to latest Karma (1.4.1), but that didn't help. Has anyone else seen this issue and been able to fix it? Help is appreciated. I've attached two images of what the Chrome inspector looks like when you first open the debugger and then after setting a breakpoint and hitting Refresh (it should look the same as the 1st image, but doesn't) edit: karma.config at bottom as well
'use strict';
var path = require('path');
var conf = require('./gulp/conf');
var _ = require('lodash');
var wiredep = require('wiredep');
var pathSrcHtml = [
path.join(conf.paths.src, '/**/*.html')
];
function listFiles() {
var wiredepOptions = _.extend({}, conf.wiredep, {
dependencies: true,
devDependencies: true
});
var patterns = wiredep(wiredepOptions).js
.concat([
path.join(conf.paths.src, '/app/**/*.module.js'),
path.join(conf.paths.src, '/app/**/*.js')
])
.concat(pathSrcHtml)
.concat('karmaMobileFramework/*.js');
var files = patterns.map(function(pattern) {
return {
pattern: pattern
};
});
files.push({
pattern: path.join(conf.paths.src, '/assets/**/*'),
included: false,
served: true,
watched: false
});
return files;
}
module.exports = function(config) {
var configuration = {
files: listFiles(),
singleRun: false,
autoWatch: true,
preprocessors : {
'/**/*.html': ['ng-html2js']
},
ngHtml2JsPreprocessor: {
stripPrefix: conf.paths.src + '/',
moduleName: 'directive-templates'
},
logLevel: 'WARN',
frameworks: ['jasmine', 'jasmine-matchers', 'angular-filesort'],
angularFilesort: {
whitelist: [path.join(conf.paths.src, '/**/!(*.html|*.spec|*.mock).js')]
},
browsers : ['Chrome'],
plugins : [
'karma-chrome-launcher',
'karma-angular-filesort',
'karma-coverage',
'karma-jasmine',
'karma-jasmine-matchers',
'karma-ng-html2js-preprocessor',
'karma-htmlfile-reporter',
'karma-junit-reporter'
],
coverageReporter: {
type : 'html',
dir : 'reports/coverage/',
reporters: [
{ type: 'html', subdir: 'report-html' },
{ type: 'cobertura', subdir: 'report-jenkins' }
]
},
reporters: ['progress', 'html', 'junit'],
junitReporter: {
outputDir: 'reports/tests/',
outputFile: 'test-results.xml',
useBrowserName: false
},
htmlReporter: {
outputFile: 'reports/tests/results.html',
pageTitle: 'BOLT Unit Tests'
},
proxies: {
'/assets/': path.join('/base/', conf.paths.src, '/assets/')
}
};
// This is the default preprocessors configuration for a usage with Karma cli
// The coverage preprocessor is added in gulp/unit-test.js only for single tests
// It was not possible to do it there because karma doesn't let us now if we are
// running a single test or not
configuration.preprocessors = {};
pathSrcHtml.forEach(function(path) {
configuration.preprocessors[path] = ['ng-html2js'];
});
config.set(configuration);
};

meteor array $addToSet not adding any items

I'm trying to add instruments to a Profiles collection in meteor using $addToSet. The code works in mongo, but will not work in the meteor methods call. I am able to update all other fields without any issues using $set, so I know that this is finding the correct user.
updateInstruments(instruments) {
if (!this.userId) {
throw new Meteor.Error('not-logged-in',
'Must be logged in to update last name.');
}
check(instruments, String);
if (instruments.length === 0) {
throw Meteor.Error('instruments-required', 'Must provide at least one instrument.');
}
let instrArray = instruments.split(',');
instrArray.forEach(function(instrument){
instrument = instrument.trim();
Profiles.update({ userId: this.userId }, { $addToSet: { instruments: instrument } });
});
},
I have even tried:
Profiles.update({ userId: this.userId }, { $addToSet: { instruments: {$each: [instrument] } }});
as well as:
Profiles.update({ userId: this.userId }, { $addToSet: { instruments: [instrument] }});
I have also tried $push and nothing happened there as well. Is there some sort of bug within meteor? Is there some other setting I need to configure to allow the updating of arrays?
UPDATE:
Per request, here's the client code:
updateInstruments() {
if (_.isEmpty(this.data.instruments)) return;
var self = this;
let instruments = this.data.instruments;
this.callMethod('updateInstruments', instruments, (err) => {
if (err) return this.handleError(err);
});
}
Thanks!
I figured out the issue. I forgot that the scope of 'this' changes in the inline 'instrArray.forEach' function, making this.userId 'undefined'. The Profiles collection was unable to find the record. I changed the following code:
let instrArray = instruments.split(',');
instrArray.forEach(function(instrument){
instrument = instrument.trim();
Profiles.update({ userId: this.userId }, { $addToSet: { instruments: instrument } });
});
to:
let userId = this.userId;
let instrArray = instruments.split(',');
instrArray.forEach(function(instrument){
instrument = instrument.trim();
Profiles.update({ userId: userId }, { $addToSet: { instruments: instrument } });
});
Thanks everyone for looking over my code!
Your query seems fine to me. As long as you are doing that on server, you don't need to configure anything. Not a bug in Meteor.

Ionic2 Push notification with background processing

I am using ionic.io to send push to my app. I have following body
{"tokens":["DeviceToken"],
"profile":"Profile",
"notification":{ "payload": {
"type": "loadCategories"
},
"ios": {
"content_available": 1
},
"android": {
"content_available": "1"
}}}
Type script code.
var push = Push.init({
android: {
senderID: "ID"
},
ios: {
alert: "true",
badge: true,
sound: 'false'
},
windows: {}
});
if((<any>push).error) {
console.log((<any>push).error);
return;
};
push.on('registration', (data)=>{
console.log(data.registrationId);
this.pushToken = data.registrationId;
this.updateToken();
});
push.on("notification", (data)=>{
console.log(data);
// if(data.additionalData.payload && data.additionalData.payload.type == 'categoryEvent') {
// console.log("at date")
// }
});
push.on('error', function(e) {
console.log(e.message);
});
Idea is that I need to send push to user and load data from the server. But problem is that if app is in background then notification event is not fired. It works only if app is active. But as soon as i understand from documentation it should work.
Known issue that has been addressed with setting content_available = 1. See https://github.com/phonegap/phonegap-plugin-push/issues/93 for more.

How to create a user in MongoDB

I'm using the latest version of the driver and MongoDB database 2.6 and I used to create users using the following code:
MongoUser _user1 = new MongoUser("username", "password", false);
MongoDatabase.AddUser(_user1);
and now it is saying MongoDatabase.AddUser() is deprecated by showing the following information:
...is obsolete: Use the new user management command 'createUser' or
'updateUser'."
Where is this new user management command? How do I create a user using the new MongoDB C# driver?
For those interested in creating a user with the C# v2.0.1 driver and MongoDB v3.0.6 use the following:
var client = new MongoClient(connectionString);
var database = client.GetDatabase("database_to_create_user_in");
var user = new BsonDocument { { "createUser", "fred" }, { "pwd", "some_secure_password" }, { "roles", new BsonArray { new BsonDocument { { "role", "read" }, { "db", "database_to_create_user_in" } } } } };
await database.RunCommandAsync<BsonDocument>(user);
I'm using MongoDB 2.6.2 and latest C# driver 1.9.2.
This is how you can add new users with 'createUser':
public static void AddUser(string user, string password, string[] roles)
{
var database = GetDatabase();
var command = new CommandDocument { { "createUser", user}, { "pwd", password }, { "roles", new BsonArray(roles) } };
var result = database.RunCommand(command);
}
I did a search for 'createUser' on the latest code on the GitHub repository:
https://github.com/mongodb/mongo-csharp-driver/search?q=createUser&ref=cmdform
At the time of writing, the only reference to 'createUser' is here
The method has been marked as obsolete however in this commit
However; on closer inspection of the code, I see this:
if (_server.RequestConnection.ServerInstance.Supports(FeatureId.UserManagementCommands))
{
AddUserWithUserManagementCommands(user);
}
else
{
AddUserWithInsert(user);
}
So, it is calling the required method under the hood
For me I struggled with the roles. I wanted to add an admin (initial user) to the mongodb. My working solution looks like that.
private static bool CreateAdminUser(string databaseUser, string databasePassword)
{
try
{
var databaseName = "admin";
var user = new CommandDocument
{
{ "createUser", databaseUser },
{ "pwd", databasePassword },
{
"roles", new BsonArray
{
new BsonDocument { { "role", "readWriteAnyDatabase" }, { "db", databaseName } },
new BsonDocument { { "role", "userAdminAnyDatabase" }, { "db", databaseName } },
new BsonDocument { { "role", "dbAdminAnyDatabase" }, { "db", databaseName } }
}
}
};
new MongoClient().GetServer().GetDatabase(databaseName).RunCommand(user);
return true;
}
catch
{
return false;
}
}