I am trying to connect my R script and Node JS - html

But this error has been coming up lately:
C:\Users\vidyush.bakshi\Desktop\node-karteek\node_modules\r-script\index.js:48 if (child.stderr) throw child.stderr;
The source code is as follows:
R.prototype.callSync = function(_opts) {
var opts = _opts || {};
this.options.env.input = JSON.stringify([this.d, this.path, opts]);
var child = child_process.spawnSync("Rscript", this.args, this.options);
if (child.stderr) throw child.stderr;
return(JSON.parse(child.stdout));
};
Can anyone help me with this please..

Related

How to properly use html-to-react?

so i am learning about this package html-to-react, and for the most part, i understand it. However, their is a piece of code i just cannot seem to be able to get my head around. The code is:
var React = require('react');
var HtmlToReact = require('html-to-react');
var HtmlToReactParser = require('html-to-react').Parser;
var htmlToReactParser = new HtmlToReactParser();
var htmlInput = '<div><div data-test="foo"><p>Text</p><p>Text</p></div></div>';
var htmlExpected = '<div><div data-test="foo"><h1>Heading</h1></div></div>';
var isValidNode = function () {
return true;
};
var processNodeDefinitions = new HtmlToReact.ProcessNodeDefinitions(React);
// Order matters. Instructions are processed in
// the order they're defined
var processingInstructions = [
{
// This is REQUIRED, it tells the parser
// that we want to insert our React
// component as a child
replaceChildren: true,
shouldProcessNode: function (node) {
return node.attribs && node.attribs['data-test'] === 'foo';
},
processNode: function (node, children, index) {
return React.createElement('h1', {key: index,}, 'Heading');
}
},
{
// Anything else
shouldProcessNode: function (node) {
return true;
},
processNode: processNodeDefinitions.processDefaultNode,
},
];
var reactComponent = htmlToReactParser.parseWithInstructions(
htmlInput, isValidNode, processingInstructions);
var reactHtml = ReactDOMServer.renderToStaticMarkup(
reactComponent);
assert.equal(reactHtml, htmlExpected);
The code i don't understand is the:
shouldProcessNode: function (node) {
return node.attribs && node.attribs['data-test'] === 'foo';
},
Any help would be very appreciated. Thanks

How to fix: API call to gmail.users.settings.filters.create failed with error: Empty response

I wrote a script in google apps scripts that creates two filters. I implemented it into web app and it works fine on couple of accounts that aren't that big. But when i try to use it on main account, where it supposed to work I am getting an error that can't really understand.
'API call to gmail.users.settings.filters.create failed with error: Empty response (vers 69, file„createFilter”)'
function createFitler(labelold,me){
var response = Gmail.Users.Labels.list('me');
var labelID = "";
var labelName = "";
for (var i = 0; i < response.labels.length; i++) {
var label = response.labels[i];
if(label.name == labelold)
{
labelID = label.id;
labelName = label.name;
}
}
var filter = Gmail.newFilter();
var filter2 = Gmail.newFilter();
filter.criteria = Gmail.newFilterCriteria();
filter.criteria.from = labelold;
filter2.criteria = Gmail.newFilterCriteria();
filter2.criteria.to = labelold;
filter.action = Gmail.newFilterAction();
filter.action.removeLabelIds = ['INBOX'];
filter.action.addLabelIds = [labelID];
filter2.action = Gmail.newFilterAction();
filter2.action.removeLabelIds = ['INBOX'];
filter2.action.addLabelIds = [labelID];
// Create the filter
Gmail.Users.Settings.Filters.create(filter, me);
Gmail.Users.Settings.Filters.create(filter2, me);
}
The weirdest part is that it works normal on my domain account but not on archive#mydomain.com account.

NativeScript JobScheduler JobService.class is undefined

I have weird error while i'm trying to create component in the JobScheduler
At the first line when setting a component value i get this error:
ERROR TypeError: Cannot read property 'MyJobService' of undefined
Both of the files are in the same folder, and its all worked yesterday.
I cleaned up the platforms folder just to be sure, because i dragged some pics to the drawble folders in the app_Resources and i had to build the project again and maybe something has changed. but it did not helped.
What can cause this problem ? am i missing something ?
JobScheduler.js :
function scheduleJob(context) {
var component = new android.content.ComponentName(context, com.tns.notifications.MyJobService.class);
const builder = new android.app.job.JobInfo.Builder(1, component);
builder.setPeriodic(15 * 60 * 1000);
builder.setOverrideDeadline(0);
const jobScheduler = context.getSystemService(android.content.Context.JOB_SCHEDULER_SERVICE);
console.log("Job Scheduled: " + jobScheduler.schedule(builder.build()));
}
module.exports.scheduleJob = scheduleJob;
MyJobService.js :
android.app.job.JobService.extend("com.tns.notifications.MyJobService", {
onStartJob: function(params) {
console.log("Job execution ...");
var utils = require("utils/utils");
var context = utils.ad.getApplicationContext();
var builder = new android.app.Notification.Builder(context);
console.log("setting notification head and body")
builder.setContentTitle("notification triggered ")
.setAutoCancel(true)
.setColor(android.R.color.holo_purple)//getResources().getColor(R.color.colorAccent))
.setContentText("body)
.setVibrate([100, 200, 100])
.setSmallIcon(android.R.drawable.btn_star_big_on);
var mainIntent = new android.content.Intent(context, com.tns.NativeScriptActivity.class);
var mNotificationManager = context.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
const channelId = "my_channel_01";
const name = "Channel name";
const description = "Channel description";
const importance = android.app.NotificationManager.IMPORTANCE_LOW;
if (android.os.Build.VERSION.SDK_INT >= 26) {
console.log("api level is good",android.os.Build.VERSION.SDK_INT)
}
const mChannel = new android.app.NotificationChannel(channelId, name,importance);
mChannel.setDescription(description);
mChannel.enableLights(true);
mChannel.enableVibration(true);
mNotificationManager.createNotificationChannel(mChannel);
builder.setChannelId(channelId);
mNotificationManager.notify(1, builder.build());
return false;
},
onStopJob: function() {
console.log("Stopping job ...");
}
});

Mongo Connection Exception handling

I am trying to make some exception handling on the following code. Basically I want a MessageBox.Show("ErrorMessage") to show if the connection to the server can't be established.
public List<MongoDBModel> MongoDBModel
{
get
{
string connectionString = "mongodb://127.0.0.1";
var mongoClient = new MongoClient(connectionString);
var mongoServer = mongoClient.GetServer();
var databaseName = "TestPointToPoint";
var db = mongoServer.GetDatabase(databaseName);
var mongodb = db.GetCollection<MongoDBModel>("OCS.MeterEntity");
var mongodbQuery = Query<MongoDBModel>.EQ(x => x._id, MeterUID);
List<MongoDBModel> Cursor = mongodb.FindAs<MongoDBModel>(mongodbQuery).ToList();
return Cursor;
}
}
I have already tryed with
if (mongoServer.State == MongoServerState.Connected)
{
var databaseName = "TestPointToPoint";
var db = mongoServer.GetDatabase(databaseName);
var mongodb = db.GetCollection<MongoDBModel>("OCS.MeterEntity");
var mongodbQuery = Query<MongoDBModel>.EQ(x => x._id, MeterUID);
List<MongoDBModel> Cursor = mongodb.FindAs<MongoDBModel>(mongodbQuery).ToList();
return Cursor;
}
else
{
MessageBox.Show("Connection to MongoDB lost");
return null;
}
but that did not work since the state of the mongoServer first changes to connected in the query.
What should I do to make it work?
I feel stupid now :P
Using a simple try-catch worked.
public List<MongoDBModel> MongoDBModel
{
get
{
string connectionString = "mongodb://127.0.0.1";
var mongoClient = new MongoClient(connectionString);
var mongoServer = mongoClient.GetServer();
var databaseName = "TestPointToPoint";
var db = mongoServer.GetDatabase(databaseName);
var mongodb = db.GetCollection<MongoDBModel>("OCS.MeterEntity");
try
{
var mongodbQuery = Query<MongoDBModel>.EQ(x => x._id, MeterUID);
List<MongoDBModel> Cursor = mongodb.FindAs<MongoDBModel>(mongodbQuery).ToList();
return Cursor;
}
catch (MongoConnectionException e)
{
MessageBox.Show(e.Message);
return null;
}
}
}
Sorry for your troubles.

Error parsing undefined value. Path '', line 0, position 0.when serializing anonymous type in windows phone 8 development

Here is my code..
var signUpData = new
{
first = "abcd",
last ="efgh",
email ="sometext",
password = "sometext",
phone = contactSession.ContactNumber,
dialing_code = "some",
country = "some"
};
JsonBody = Newtonsoft.Json.JsonConvert.SerializeObject(signUpData);
var tcs = new TaskCompletionSource<Tuple<string, bool>>();
tcs.SetResult(new Tuple<string, bool>(request.ResponseBody,false));//request.ResponseBody is jsonbody that comes from server.
var result = await tcs.Task;
if (result.Item2 == false)
{
var errors = JsonConvert.DeserializeAnonymousType(result.Item1, new { error = "" });
return false;
}
Then i am getting above error sometimes not all the time.
What is the scenario?
Can anyone tell?`