Here is my code: var time = new Date(); setInterval(function() { $("#Timer").text(time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds()); }, 1000);
Category: javascript
Category Added in a WPeMatico Campaign
Measure execution time of web worker
I would like to measure execution time of a webworker that computes factorization. The webworker is messaging live results and once computations are terminated, the webworker sends a ‘finished’ message. I used promise to do this in my react app.
useEffect(() => {
const measureTimeStart = performance.now();
(async () => {
try {
await new Promise(resolve => {
const worker = new Worker(new URL('facto.js', import.meta.url));
worker.postMessage(number);
worker.onmessage = message => { //streaming live results
const { facto, status } = message.data;
setResults({ ...facto }); //adding them to React state
if (status === 'finished') {
resolve();
worker.terminate();
};
};
});
} catch (error) {
console.log(error)
}
})();
const measureTimeEnd = performance.now();
setExecutionTime(Math.round((measureTimeEnd - measureTimeStart) * 1000) / 1000 + ' ms');
}, [number]); //number to factorize
However, performance.now() doesn’t wait that the promise resolves and consequently gives me arbitrary timing. Why? thanks.
Mongo return what inputs don’t match for $IN
Is there any way for Mongo to return some indication (flag, field, etc..) for if an input in a $in does not match any docs?
Please see my Mongo Playgrond
That successfully just returns all odd documents.
How can I have some indication that the evens were not found?
I’d like to do this within Mongo itself. I get I can iterate through the results in JS and perform a diff.
Fwiw, I this $in will actually be the first stage of a $match in an aggregate . So maybe I can use something like addFields for the unmatches.
Thanks!
Back button stop working after window.print()
I have a modal with two buttons: print and close modal
html:
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<button class="header__print button--print" title="Print" onclick="printDiv('exportContent')"></button>
</div>
JS:
<script type="text/javascript">
function printDiv(divID) {
var divElements = document.getElementById(divID).innerHTML;
var oldPage = document.body.innerHTML;
document.body.innerHTML =
"<html><head><title></title></head><body>" +
divElements + "</body>";
window.print();
document.body.innerHTML = oldPage;
}
</script>
The issue appears when I press on print btn and close print modal, then back button stop working.
Any idea why is it happening? thanks!
Stack Navigator not showing screen
My Stack Navigator doesn’t show the screen that is rendered beneath it.
This is what my component renders. If I comment the first and last 3 lines, the content is shown as desired.
<Stack.Navigator>
<Stack.Screen name="LoginEmail">
{() => (
<View style={styles.container}>
<View>
<Text style={styles.text}>
{CONNECT_TO_APP_TXT}
</Text>
</View>
<View style={styles.inputsWrapper}>
<Input
label={EMAIL_TXT}
placeholder={EMAIL_TXT}
isRequired={true}
onChangeText={setEmail}
/>
<CustomButton
outerStyle={styles.button}
label={CONTINUE_TXT}
accessibilityLabel={PRESS_CONTINUE_ACC_TXT}
onPress={sendRequest}
/>
</View>
<View>
<Text style={styles.errorMsg}>{errorMsg}</Text>
</View>
</View>
)}
</Stack.Screen>
</Stack.Navigator>
Getting error on React JS while using fontawesome 5 Error: Could not find icon ObjecticonName: “faHeart”prefix: “fas”
I am trying to add fontawesome icon on my react js project but getting an error.
npm version: 8.1.4
node version: 17.2.0
├─┬ @fortawesome/[email protected]
│ └── [email protected] deduped
├─┬ @testing-library/[email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]
I want to add two heart icons on my project. One is solid and one is regular. The code is for the heart icons are:
<i class="far fa-heart"></i>
<i class="fas fa-heart"></i>
On my react.js project, a class component I have declared named Like, and the code is shown below:
import React from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faHeart } from '@fortawesome/free-regular-svg-icons';
class Like extends React.Component {
render() {
return <FontAwesomeIcon icon={['fas', 'faHeart']}></FontAwesomeIcon>;
}
}
export default Like;
I get this error: Could not find icon {prefix: 'fas', iconName: 'faHeart'}
If I use return <FontAwesomeIcon icon={faHeart}></FontAwesomeIcon>; then it solved but I need to add the two icon ones prefix is fas and ones is fas.
How can I do that? Please help me. I am new to React.js.
How to query between dates in CosmosDB? [duplicate]
I am trying to do a query to get a result that includes all objects created in between 2 dates. So far I have something like this. SELECT * FROM c WHERE c.partitionID >= '%-2021-07-07% AND c.partitionID < '%-2021-12-20%'
My Objects look like this:
{
"u_id": "698719sd9618",
"client_id": "097",
"entry_time": "27/8/2021 05:05:11",
"partitionID": "097-2021-08-27T01",
}
{
"u_id": "2ERRT719sd9618",
"client_id": "096",
"entry_time": "28/8/2021 05:05:11",
"partitionID": "097-2021-08-28T01",
}
{
"u_id": "24arYUI4214",
"client_id": "095",
"entry_time": "20/11/2021 05:05:11",
"partitionID": "097-2021-11-20T01",
}
{
...
}
What sites would you recommend for self study for web development? [closed]
I am a newbie to the world of web development, and I would appreciate any help that I can get.
Azure Devops Extension (VSTS) Set a variable that needs to be accessed in next task using Javascript
I am trying to access the variable set in one task from another task in javascript. In the first task I am setting the variable as following –
var connection = tl.getInput("connection", true);
if(connection !== undefined) {
var auth = tl.getEndpointAuthorization(connection, false);
let access_key_1 = auth.parameters["password"];
let username = auth.parameters["username"];
if(auth !== undefined) {
console.log('##vso[task.setvariable variable=access_key_1;]', access_key_1);
In the second task i am trying to access the variable –
console.log(access_key_1);
But I am getting error –
ReferenceError: access_key_1 is not defined.
How to update the data dynamically in vuejs?
User.vue
<template>
<div>
<form>
<label>Val:</label><br />
<input type="text" id="val" name="val" v-model="item.val" /><br />
<label>kk:</label><br />
<input type="text" id="kk" name="kk" v-model="item.kk" /><br /><br />
<input type="submit" value="Submit" @click="updatedata" />
</form>
</div>
</template>
<script>
export default {
name: "User",
data: function () {
return {
val: "",
kk: "",
};
},
methods: {
updatedata() {
val: this.item.val,
kk: this.item.kk,
},
},
};
</script>
Helloworld.vue
<template>
<div>
<b>Vuejs dynamic routing</b>
<div v-for="item in items" :key="item.id">
<b>{{ item.id }}.</b>
<router-link :to="{ name: 'UserWithID', params: { id: item.id } }">
{{ item.kk }}
</router-link>
</div>
<br /><br /><br />
{{ $route.params.id }}
</div>
</template>
<script>
import User from "./User.vue";
export default {
name: "HelloWorld",
components: {},
data() {
return {
items: [
{ id: 1, val: "1", kk: "mm" },
{ id: 2, val: "22", kk: "aa" },
{ id: 3, val: "55", kk: "dd" },
{ id: 4, val: "77", kk: "gg" },
],
};
},
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
I am trying to update data in vuejs, I have given routing and able to make it dynamic. But when trying to update the data. How to give reference to the component and update the data. i have taken click event where onclick of that button. I should able to update the data.
Code link:- https://codesandbox.io/s/agitated-forest-wl76w?file=/src/components/User.vue
Three.js animation with Mixamo
My goal is to make a ROBLOX like customization system for my game, where a user can choose between hundreds of pieces of clothing and accessories for their avatar. Now, I would like to use Mixamo to animate my character, but Mixamo needs a fully boned rig to download the animations. Now that’s a problem: I need Blender to bone the rig, but each rig will be different since the user is creating his own character, and if I had all the rigs pre-made, there would be literally millions of combinations of characters!
The alternative, I’m thinking, is to use Tween.js, but that’s a really bad way since it’ll take a ton of work and time just to get a single animation, and it still won’t be as good as Mixamo.
At this point, I’m sure you have no idea what I’m talking about, so here’s an image to describe my issue:
I hope the diagram made my problem more clear. Below I’ve listed some of the possibilities that could potentially solve this problem, but then again, not sure.
- Maybe you can download an animation from Mixamo without a specified rig to it, so you can apply it to any character?
- Maybe I just animate the base rig and then apply the textures for all the body parts (so instead of downloading all the rig possibilities, I just download all of the clothing textures)?
Any Ideas?
Thanks in advance!
Pass and use a PHP variable in a Javascript file with Ajax
I have a PHP script in which I get the content of a query made into a Postgresql database :
<?php
require_once 'connection.php';
$query1 = pg_query("This_is_my_query");
$instruction = "[";
while ($row = pg_fetch_array($query1)) {
$row1= $row['row1'];
$row2= $row['row2'];
$instruction .= "{name : '". $row1. "', y : ". $row2. "},";
}
$instruction .= "]";
echo $instruction;
?>
The echo $instruction gives :
[{name : 'Prestation', y : 1}]
Then I have a JS file in which I try to display and use the $instruction variable.
I use Ajax and my script is the one :
$.ajax({
url : 'Path_To_Php_File_Is_OK', // requesting a PHP script
dataType : 'json',
type: "GET",
async : false,
success : function (data) { // data contains the PHP script output
alert(data);
},
error: function(data) {
alert('error');
},
})
The result is that the success function is not called and I have the alert('error').
But when I use the dataType ‘text’ and not ‘Json’, the success function is ok and I have the alert(data).
How to explain that behaviour ? And how could I parse the PHP variable $instruction ?
Any help would ve very appreciated, thanks !
ERRO[0000] unknown flag: –summary-export
I have this error when running a project in K6
ERRO[0000] unknown flag: –summary-export
npm ERR! code ELIFECYCLE
npm ERR! errno 255
npm ERR! **************: k6 run dist/main.js "--duration" "120m" "--summary-export" "debug/public/test.json" "-i" "1"
npm ERR! Exit status 255
npm ERR!
npm ERR! Failed at the ********@1.0.0 k6 script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Affiliate link inside on iframe – cookies
I have an idea where I want to have affiliate URL (website) embedded inside of iframe
(for example https://www.asos.com/?affid=1234)
Once I visit it, I will have affid saved inside of cookies. Navigating in new tab to asos.com, affid cookie will be there.
Is it possible to do the same with iframe?
Current setup:
<iframe src="https://www.asos.com/?affid=4321" />
Checking cookies on my website (where iframe is placed), there isn’t affid cookie, also when checking asos.com, there is still previously visited affid (1234).
Thanks!
How to set Monaco editor inline font size?
I want to have the effect like this:
So I use editor.deltaDecorations() to edit inline css class.
this is my code
var content = [
'xxx line 1 xxx',
'xxx title xxx',
'xxx line 3 xxx'
].join('n');
var editor = monaco.editor.create(document.getElementById('container'), {
value: content,
language: 'plaintext'
});
var decorations = editor.deltaDecorations(
[],
[
{
range: new monaco.Range(2, 4, 2, 10),
options: {
inlineClassName: 'myclass'
}
}
]
);
css
.myclass {
color: red;
font-size: 50px;
}
The result is
Monaco editor changed the font size, but didn’t recalculate the height of line,how to solve this problem? help !


