I’m working on a project in react native expo, And i want to Execute a python script inside my react native expo project to run a script, where it will then find a JSON file in my project and use that information to create an excel sheet and email it to the user, that is all it needs to do, I don’t need information to come back to me I just need the file to be executed within my project.
Category: javascript
Category Added in a WPeMatico Campaign
Creating Connection of an existing Mongo DB Database in an existing Docker Container
I want to create a connection from an existing Mongo DB collection to an existing Docker container. Can anybody see it out.
I tried out several syntaxes and approaches but It always give me error.
Thanks in advance!
player-cloud_1 | error { MongoError: failed to connect to server [cluster0.bgso9.mongodb.net:27017] on first connect [MongoError: getaddrinfo ENOTFOUND cluster0.bgso9.mongodb.net cluster0.bgso9.mongodb.net:27017]
player-cloud_1 | at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:336:35)
player-cloud_1 | at Pool.emit (events.js:182:13)
player-cloud_1 | at Pool.EventEmitter.emit (domain.js:442:20)
player-cloud_1 | at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:280:12)
player-cloud_1 | at Object.onceWrapper (events.js:273:13)
player-cloud_1 | at Connection.emit (events.js:182:13)
player-cloud_1 | at Connection.EventEmitter.emit (domain.js:442:20)
player-cloud_1 | at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:189:49)
player-cloud_1 | at Object.onceWrapper (events.js:273:13)
player-cloud_1 | at Socket.emit (events.js:182:13)
player-cloud_1 | at Socket.EventEmitter.emit (domain.js:442:20)
player-cloud_1 | at emitErrorNT (internal/streams/destroy.js:82:8)
player-cloud_1 | at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
player-cloud_1 | at process._tickCallback (internal/process/next_tick.js:63:19)
player-cloud_1 | name: 'MongoError',
player-cloud_1 | message:
player-cloud_1 | 'failed to connect to server [cluster0.bgso9.mongodb.net:27017] on first connect [MongoError: getaddrinfo ENOTFOUND cluster0.bgso9.mongodb.net cluster0.bgso9.mongodb.net:27017]' }
player-cloud_1 | error connecting to the database
How to modify children to wrap them inside another key
I have the following form.
const MyForm = ({
myFormRef,
}) => (
<form id="myForm" ref={myFormRef} method="POST">
<input name="test_token" type="hidden" />
<input name="id" type="hidden" />
<input name="versionId" type="hidden" />
<input name="additionalId" type="hidden" />
</form>
);
export default MyForm;
Information from above form is captured here within another component.
[...myFormRef.current.children].forEach((child) => {
// child.name is 'test_token'
// child.value is 'some_token'
});
Thus children here is the above data.
children is
{
test_token: 'some_token',
id: 'some_id',
versionId: 'some_version',
additionalId: 'some_additional_id'
}
I want to modify children to become
{
token,
overallData: {
id,
versionId,
additionalId
}
}
Is it possible to do that?
Closest I found was appendChild()
but that is to append a node.
i can’t sign with facebook account in my recat app
Modify objects in array when combining two arrays into one
I have two arrays of objects that I must combine in one array. If an object is present in both arrays, it should be only once in the final array. If an object is not present in an array, I need to add it with a modified attribute.
Here’s the situation:
const Array1 = [
{value: "id1", name: "Element1", boolean: false},
{value: "id2", name: "Element2", boolean: false},
{value: "id3", name: "Element3", boolean: false}
]
const Array2 = [
{value: "id1", name: "Element1", boolean: false},
{value: "id2", name: "Element2", boolean: false},
{value: "id4", name: "Element4", boolean: false}
]
Expected output:
const result = [
{value: "id1", name: "Element1", boolean: false},
{value: "id2", name: "Element2", boolean: false},
{value: "id3", name: "Element3", boolean: true},
{value: "id4", name: "Element4", boolean: true}
]
Test passing locally but failing in gitlab pipeling
I wrote some tests, which pass locally, but fail in the pipeline.
Here’s the test:
async displaysMachineTypeWhenOtherMachineIsSelected () {
const { asFragment } = render(
FunctionsFactory.componentFactory({ fetchedState: { machine: mockedMachineState } }),
);
// Functions is an object. It's used in other tests and they all pass
await Functions.selectMachineState1();
Functions.clickEditText();
await Functions.clickOnSelect(DetailsNames.Category);
screen.getByText('Other machine').click();
await waitFor(() => {
expect(screen.getByText(DetailsLabels.MachineType)).toBeInTheDocument();
});
expect(Array.from(document.querySelectorAll('input')).length).toEqual(10);
expect(asFragment()).toMatchSnapshot();
}
it(
'should display machine type dropdown when other machine is selected',
displaysMachineTypeWhenOtherMachineIsSelected,
);
And as I said, it passes locally, but fails in the gitlab pipeline.
Error from gitlab:
● States › Testing machine view › Testing behavior › should display machine type dropdown when other machine is selected
thrown: "Exceeded timeout of 5000 ms for a test.
Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
64 | machineBehavior(sharedArgs);
65 |
> 66 | it(
| ^
67 | 'should display machine type dropdown when other machine is selected',
68 | displaysMachineTypeWhenOtherMachineIsSelected,
69 | );
at components/pages/states/tests/States.test.tsx:66:7
at components/pages/states/tests/States.test.tsx:62:5
at components/pages/states/tests/States.test.tsx:49:3
at Object.<anonymous> (components/pages/states/tests/States.test.tsx:25:1)
● States › Testing machine view › Testing behavior › should return to machine view on Cancel click
expect(received).toMatchSnapshot()
Snapshot name: `States Testing machine view Testing behavior should return to machine view on Cancel click 1`
- Snapshot - 1
+ Received + 0
@@ -782,11 +782,10 @@
Layers
</div>
</div>
<div
class="ant-tabs-ink-bar ant-tabs-ink-bar-animated"
- style="left: 0px; width: 0px;"
/>
</div>
</div>
<div
class="ant-tabs-nav-operations ant-tabs-nav-operations-hidden"
85 |
86 | Functions.checkIfLabelsArePresent(machineLabels);
> 87 | expect(asFragment()).toMatchSnapshot();
| ^
88 | },
89 | };
90 | };
at Object.returnsToMachineViewOnCancelClick (components/pages/states/tests/testFunctions/machine-view/machineView.ts:87:28)
› 1 snapshot failed.
dependencies from package.json
:
"jest": "^27.0.5",
"babel-jest": "^27.0.5",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^12.0.0",
"jest-cli": "^27.0.5",
Any idea what I’m doing wrong here?
Using new collections for each user
I am building an Expense Tracking app using Node.js where all the Income and Costs should get saved in a database.
My idea is to create a new collection for each registered user and save all their income/cost actions in that collection.
The things i would like to consider before writing it are:
- how do i name the collections
- Efficiency of this method
- is it even secure
- how do i save their data when they login from an another device
- can two users have the same collection name causing them to save their actions in one collection
- are there any better ways to do this
What i came up with to solve it was to make a model which takes the given company/user name to create a collection.
const mongoose = require('mongoose');
const bcrypt = require ('bcrypt');
const Schema = mongoose.Schema;
const UserSchema = new Schema({
userName: {
type: String,
required: true,
unique: true
},
userPass: {
type: String,
required: true
},
userEmail: {
type: String,
required: true,
unique: true
}
}, { timestamps: true });
UserSchema.pre('save', async function (next) {
try {
const hashed = await bcrypt.hash(this.userPass, 10)
console.log('saved user with hashed password.')
this.userPass = hashed
next();
} catch {
next(error)
}
})
const User = mongoose.model(userName, UserSchema);
module.exports = User;
And that collection can only be accessed by the one who has the password for that unique name.
So what i would like to ask is: Are there any better ways to do this?
how to convert array of object to comma separated array of object
I have array of object and I want to convert this to comma separated object.
let arr = [{name:"k"},{name:"p"}];
console.log(...arr.join(','));
I’m getting this [ o b j e c t O b j e c t ] , [ o b j e c t O b j e c t ]
I want to in this format {name:”k”},{name:”p”}. please help. thanks in advance.
How to detect idle time if open site in more than one tabs
If i add conditions for idle time, it worked when site is opened in single tab. How to resolve it?
Buefy autocomplete deselect and input issue
I have a Buefy autocomplete field in my project.
<b-field>
<b-autocomplete
v-model="client"
:data="agencyClients"
field="name"
@input="setClient"
:clearable="true"
open-on-focus
size="is-small"
>
</b-autocomplete>
</b-field>
The v-model property should be the object in form
{id: 10, name: 'AAA'}
Therefore I use field property in the input which is set to name. This basic set up works well. But if I trigger @input event which looks like
async setClient(clientName) {
if( clientName ) {
const client = this.agencyClients.find((item) => item && item.name === clientName);
if( client ) {
await this.$store.dispatch(`${this.storeName}/updateClientId`, {clientId: client.id});
this.client = client; // Set client as object.
}
}
},
I get and [object] as value in input field. Autocomplete is not able to show client.name value as onload. Why is it so?
The second issue is that with deselect function. It does not trigger @input event. It does not make sence. If I clear the value input event is not triggered? Why?
Can somebody explain me what am I doing wrong? Thanks a lot.
Updating array of objects with recursing function (Mapping replies to comments dynamiclly)
I am receiving a list of comments from a graphql backend in the following format:
[
{
"__typename": "Comment",
"id": "1",
"userId": "1",
"postId": "1",
"parentCommentId": null,
"content": "test 1"
},
{
"__typename": "Comment",
"id": "2",
"userId": "1",
"postId": "1",
"parentCommentId": null,
"content": "this is a comment"
},
{
"__typename": "Comment",
"id": "34",
"userId": "1",
"postId": "1",
"parentCommentId": "1",
"content": "reply to test1"
},
{
"__typename": "Comment",
"id": "35",
"userId": "1",
"postId": "1",
"parentCommentId": "34",
"content": "nested reply to "reply to test1"nn"
},
{
"__typename": "Comment",
"id": "36",
"userId": "1",
"postId": "1",
"parentCommentId": "34",
"content": "test?"
}
]
The comments with parentCommentId === null
are the highest level comments, while comments where parentCommentId !== null
are replies to a comment where id === parentCommentId
I would like to transform this data structure to something like:
[{
"__typename": "Comment",
"id": "1",
"userId": "1",
"postId": "1",
"parentCommentId": null,
"content": "test1",
"replies": [{
"__typename": "Comment",
"id": "34",
"userId": "1",
"postId": "1",
"parentCommentId": "1",
"content": "reply to test1",
"replies": [{
"__typename": "Comment",
"id": "35",
"userId": "1",
"postId": "1",
"parentCommentId": "34",
"content": "reply to test1"
}]
}]
},
{
"__typename": "Comment",
"id": "2",
"userId": "1",
"postId": "1",
"parentCommentId": null,
"content": "this is a comment",
"replies": []
}
]
I have the following function to do the data transformation:
function formatData(comments: Array < IComment > ) {
let commentList = Array < IComment > ();
// add comments without `parentCommentId` to the list.
// these are top level comments.
for (let i = 0; i < comments.length; i++) {
if (!comments[i].parentCommentId) {
commentList.push({ ...comments[i],
replies: []
});
}
}
for (let i = 0; i < comments.length; i++) {
if (comments[i].parentCommentId) {
const reply = comments[i];
mapReplyToComment(commentList, reply);
}
}
return commentList;
function mapReplyToComment(
commentList: Array < IComment > ,
reply: IComment
): any {
return commentList.map((comment) => {
if (!comment.replies) {
comment = { ...comment,
replies: []
};
}
if (comment.id === reply.parentCommentId) {
comment.replies.push(reply);
return comment;
} else {
return mapReplyToComment(comment.replies, reply);
}
});
}
}
However this only works for one level deep into the object tree. so I am getting the replies of a main comment, but replies to replies are not added to the object.
this is what I am getting now:
[{
"__typename": "Comment",
"id": "1",
"userId": "1",
"postId": "1",
"parentCommentId": null,
"content": "test1",
"replies": [{
"__typename": "Comment",
"id": "34",
"userId": "1",
"postId": "1",
"parentCommentId": "1",
"content": "reply to test1"
// -- I should have here another node of "replies"
}]
},
{
"__typename": "Comment",
"id": "2",
"userId": "1",
"postId": "1",
"parentCommentId": null,
"content": "this is a comment",
"replies": []
}
]
Could you please point out what am I doing wrong and provide some explanation?
Thanks in advance
Not able to launch another component in react. passing values as params
I am calling another from current component
<Link to={`/${props.certificate.id}/edit` } >Edit</Link>
in the receiving component I am receiving it using props.
export function EditCertificate(props: any)
then I am accepting id
as
const {id} = props.match.params;
so in the url
below is coming but EditCertificate
component is not getting launched.
http://localhost:4200/934108e0-ca73-4837-bbf2-26482ece1cb6/edit
in the route I have defined below.
<SecureRoute path=":id/edit">
<EditCertificate id={':id'} />
</SecureRoute>
what mistake I am doing?
CSS Modules not working after upgrading nodejs version
I upgraded the version of Node JS on the project from v12 to v14 and with that some of the packages including laravel-mix.Through-out the project there are these css modules “:global(selector)” being used , that after updating are not working.
I tried adding css-loader as a module in webpack.mix.js
:
module: {
rules: [
{
test: /.css$/,
use : [
{
loader: 'css-loader',
options: {
modules: true,
}
}
]
}]} // there are some other babel rules as well.
After running npm run watch
and it compiles it shows this error:
ERROR in ./resources/css/fontello.css (./node_modules/laravel-mix/node_modules/css-loader/dist/cjs.js??clonedRuleSet-7[0].rules[0].use[1]!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-7[0].rules[0].use[2]!./node_modules/css-loader/dist/cjs.js??clonedRuleSet-23[0].rules[0].use[0]!./resources/css/fontello.css)
Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
SyntaxError
(1:1) C:UsersosmanDesktopProjectsmyhomeresourcescssfontello.css Unknown word
> 1 | // Imports
| ^
2 | import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from "../../node_modules/css-loader/dist/runtime/noSourceMaps.js";
3 | import ___CSS_LOADER_API_IMPORT___ from "../../node_modules/css-loader/dist/runtime/api.js";
There are 14 errors exactly the same as this that appear, just the path ./resources/css/fontello.css
changes.
In the browser console the error appears like this:
Uncaught Error: Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
SyntaxError
(1:1) C:UsersosmanDesktopProjectsmyhomeresourcescssthemeindex.css Unknown word
[1m[31m>[39m[22m[90m 1 | [39m// Imports
[90m | [39m[1m[31m^[39m[22m
[90m 2 | [39mimport ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from [32m"../../../node_modules/css-loader/dist/runtime/noSourceMaps.js"[39m[33m;[39m
[90m 3 | [39mimport ___CSS_LOADER_API_IMPORT___ from [32m"../../../node_modules/css-loader/dist/runtime/api.js"[39m[33m;[39m
Any help would be appreciated.
Dependent dropdown for dynamic form not working
Hello Everyone here I am trying to assign a dependent dropdown to the current dynamic form i.e. if I select the cost center it will load the cost center dependent child Sub Head data from DB.
It is working fine for a single row but when I add another row it was not working
please help
when I work with single row it will work fine
but when i click Add More and do same with other row it will not work
this is my HTML code
<!DOCTYPE html>
<html>
<head>
<title>Laravel 5 - onChange event using ajax dropdown list</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<table class="table" id="dynamicTable12">
<tr>
<th scope="col"width="250" >Ledger</th>
<th scope="col" width="250">Costcentre</th>
<th scope="col" width="250">Sub Head</th>
<th scope="col" width="75">Dr/Cr</th>
<th scope="col" width="175">Amount</th>
</tr>
<tr>
<td> <select name="addmore[0][ledger]" id="" class="form-control js" required="required">
<option value="">--Please select one--</option>
@foreach ($bud as $buds)
<option value="{{$buds->id}}">{{$buds->name}}</option>
@endforeach
</select></td>
<td> <select name="addmore[0][project]" class="form-control js" id="state" required="required">
<option value="">-- Select Project --</option>
@foreach ($countries as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</select>
</td>
<td> <select name="sub" class="form-control">
<option>-- Sub Head--</option>
</select>
</td>
<td><select name="addmore[0][cr_dr]" id="" class="cr_dr form-control" required="required">
<option value="">----</option>
<option value="Dr">Dr</option>
<option value="Cr">Cr</option>
</select></td>
<input type="hidden" value='0' name='addmore[0][banks]' >
<td><input type="number" name="addmore[0][amount]" placeholder="Amount" class="txt form-control" required="required"/></td>
<td><button type="button" name="add" id="add12" class="btn btn-success">Add More</button></td>
</tr>
</table>
And this is Javascript code
<script type="text/javascript">
$(document).ready(function() {
$(document.body).on("change.select2", "#state",function () {
var id_country = $(this).val();
var token = $("input[name='_token']").val();
$.ajax({
url: "<?php echo route('select-ajax') ?>",
method: 'GET',
dataType: 'json',
data: {id_country:id_country, _token:token},
success: function(data) {
$("select[name='sub'").html('');
$("select[name='sub'").html(data.options);
}
});
});
});
</script>
<script>
let initializeSelect2 = function() {
$('.js').select2();
}
var i = 0;
$("#add12").click(function(){
++i;
$("#dynamicTable12").append('<tr><td><select name="addmore['+i+'][ledger]" id="" class="form-control js" required="required"><option value="">--Please select--</option>@foreach($bud as $iit_bank)<option value="{{$iit_bank->id}}">{{$iit_bank->name}}</option>@endforeach</select></td> <td> <select id="state" class="form-control js" name="addmore['+i+'][project]" required="required"><option value="">--select--</option>@foreach($buud as $iit_bank)<option value="{{$iit_bank->id}}">{{$iit_bank->name}}</option>@endforeach</select></td> <td> <select name="sub" class="form-control"><option>-- Sub Head--</option></select></td><td><select name="addmore['+i+'][cr_dr]" id="" class="cr_dr form-control" required="required"><option value="">--select--</option><option value="Dr">Dr</option><option value="Cr">Cr</option></select></td><td><input type="number" name="addmore['+i+'][amount]" placeholder="Amount" class="txt form-control" required="required"/></td><td><button type="button" class="btn btn-danger remove-tr">Remove</button></td></tr>');
initializeSelect2()
});
$(document).on('click', '.remove-tr', function(){
$(this).parents('tr').remove();
});
$(document).ready(function() {
initializeSelect2()
});
</script>
And also I want to name the Subhead with an array but it was not working fine
Binance API, how to read total balance value in BTC (or USD), or how to read earn wallet details
Using Binance API, I want to get my total account balance in BTC (or USD)
I am able to get the spot
wallet balance by querying /api/v3/account
endpoint.
In my case, the total balance is the SUM of spot wallet + earn wallet
.
const totalBalance = spot + earn
With only spot
, I am not able to calculate totalBalance
nor earn
.
Using the Binance API, how can I get the totalBalance
or earn
?