function convertNameToObject(string) {
let obj = {};
obj.firstName = ;
obj.lastName = ;
return obj;
}
console.log(convertNameToObject(“Harry Potter”));
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
function convertNameToObject(string) {
let obj = {};
obj.firstName = ;
obj.lastName = ;
return obj;
}
console.log(convertNameToObject(“Harry Potter”));
I’ve got some simple browser-side JS code, and thought I’d try using @ts-check to pick out any fluff. Some valid bugs were found, and I’ve added js-doc parameter type information as well. I don’t want a transpile step so this needs to be vanilla Javascript.
When I access DOM element properties I get errors, because TS doesn’t know the real type of these elements.
s.YWindows = document.getElementById("rows-input").valueAsNumber
gives…
Property 'valueAsNumber' does not exist on type 'HTMLElement'
I thought I could use a JSDoc type hint to resolve that, but it only moves the problem.
/** @type {HTMLInputElement} */
let r = document.getElementById("rows-input")
s.YWindows = r.valueAsNumber
Type 'HTMLElement' is missing the following properties from type 'HTMLInputElement': accept, align, alt, autocomplete, and 52 more.
Suggestions, or do I just have to disable around this section somehow?
I’m trying to get specific message content on the server by its ID, but without knowing exact channel.
This is the code I’m using:
message.guild.channels.cache.filter(c => c.type === 'GUILD_TEXT').each((c) => {
console.log(c.messages.cache.get("ID").content)
})
but the only thing I get in the end is:
TypeError: Cannot read properties of undefined (reading 'content')
I’d really appreciate if someone helps me to find more optimal way to do it or to fix mine!
In my app I’m sending a request to my backend app from which I get a response with id like { 'id': '12345'}. I saves this id as loadId inside data, here:
export default {
name: 'SyncProducts',
data() {
return {
loadId: '',
Now I want to send another POST fetchSyncedProductsResultRequest when this data loadId change from empty. How to do so?
Below my code:
imports.js
const createApparelMagicProductsRequest = (self, products) => {
const jwtToken = self.$store.state.idToken;
console.log(products)
console.log()
const payload = JSON.stringify({ product_codes: products['product_codes'].split(',') })
return axios
.post(`/api/v1/imports/products_batches`, payload,{
headers: {
Authorization: `Bearer ${jwtToken}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})
.then(response => response.data['id'])
};
const fetchSyncedProductsResultRequest = (token, id) => {
return axios
.get(`/api/v1/imports/products_batches`, {
params: { id: id },
headers: {
Authorization: `Bearer ${token}`,
}
})
.then(response => {
return response.data['result']
})
};
sync_products.vue
<script>
import {
fetchSyncedProductsResultRequest,
createApparelMagicProductsRequest
} from '../../api/imports'
export default {
name: 'SyncProducts',
data() {
return {
styleCodes: [],
fetchedProductSyncResult: [],
loadId: '',
}
},
async mounted() {
await fetchSyncedProductsResultRequest(this, load.id)
this.syncedProductsFetched = true
this.pageChanged(this.currentPage)
},
async mounted() {
const jwtToken = this.$store.state.idToken;
fetchSyncedProductsResultRequest(jwtToken).then(data => {
this.fetchedProductSyncResult = data
})
},
</script>
As you can see, each ellipse is part of a wave object and the fill is getting applied on each frame over and over and giving this blinking effect on all ellipses. I want to take a random colour and assign to each ellipse when it is drawn so that it remains with that fill colour instead of defining a new colour at each frame. I tried a lot but couldn’t achieve that. Any help would be appreciated.
class Wave {
constructor(amp, period, phase) {
this.amplitude = amp;
this.period = period;
this.phase = phase;
}
evaluate(x) {
return sin(this.phase + (TWO_PI * x) / this.period) * this.amplitude;
}
update() {
this.phase += 0.05;
}
}
let waves = [];
let y;
function setup() {
createCanvas(600, 400);
for (let i = 0; i < 5; i++) {
waves[i] = new Wave(random(20, 80), random(100, 600), random(TWO_PI));
}
}
function draw() {
background(0);
for (let x = 0; x < width; x += 10) {
for (let wave of waves) {
y = wave.evaluate(x);
noStroke();
fill(random(255), random(255), random(255));
ellipse(x, y + height / 2, 6);
}
}
for (let wave of waves) {
wave.update();
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>
I have been working to change a github code to upload multiple images and get result.
https://github.com/giventofly/pixelit
Tried many ways. But not working.
document.addEventListener("DOMContentLoaded", function () {
//load image to canvas
document.getElementById("pixlInput").onchange = function (e) {
var img = new Image();
img.src = URL.createObjectURL(this.files[0]);
img.onload = () => {
//create element
//document.getElementById('teste').src = img.src;
px.setFromImgSource(img.src);
pixelit();
//.pixelate()
//.convertGrayscale()
//.convertPalette();
//.saveImage();
//console.log(px.getPalette());
};
};
This is the source code. Please help
I am developing a dynamic step wizard feature using React. I am using the react-step-wizard package.
I am using hooks. ( the functional way )
Within the step wizard There are more than 10 pages/components.
At any point, any page can be disabled or enabled; Because of this, the number of steps/pages might change.
On any page there might be a button that disables/enabled the next page.
If a page is disabled, that page will no longer be within the step wizard. ( if there were 13 pages, after disabling the page, there will be 12 pages )
If a page is enabled, the page is available within the step wizard .( if there were 12 pages, after enabling the page, there will be 13 pages )
<StepWizard>
<page-1 />
<page-2 />
<page-3 />
<page-4 />
<page-5 />
<page-6 />
<page-7 />
<page-8 />
<page-9 />
<page-10 />
<page-xyz />
</StepWizard>
On each page there is a form.
The data gathered from each page will be stored within redux.
Issue #1:
Let’s say that I am on the 2nd page.
From the 2nd page I am disabling the current 3rd page.
Now, the old 4th page should become the new 3rd page.
Issue #2:
Let’s say that I am on the 2nd page.
From the 2nd page I am enabling a currently disabled page and this page will become the new 3rd page.
The old 3rd page will be push and will become the 4th page.
There are the two scenarios where the issue is happening.
And this is where the issue/bug is happening, when a page is getting added or removed.
The add/remove event is happening within a submit event.
Within the submit event I have this 2 lines :
dispatch( storeUpdateAction( { page_name_to_disable_or_enable : boolean_value_goes_here } ) );
return nextStep();
When dealing with dynamic pages within a react step wizard, the wizard might take the user to a wrong URL like URL#hash_A and it will mount the component B.
If the hash was hash_A it should have mounted the A component, but the A component might have been disabled by the time the return and the nextStep() method have occured …
So, if I am on the 2nd page and I disable the 3rd page, I should land on the 4th page, because the 4th page should be the new 3rd page.
But it seams that something is wrong with the nextStep() method because it takes the user to the old hash ( the hash of the freshly disabled page ), but it mount the right component, it mount the old 4th page, because the old 4th page is the new 3rd page.
I need a solution or someone to explain why this strange behavior is happening ..
It’s Part of the Code-Examples in the README-File.
“B4c0//” stands for ‘password_example’ I found out from another question here.
What means ‘bacon’ and ‘not_bacon’?
To check a password:
```javascript
// Load hash from your password DB.
bcrypt.compareSync("B4c0//", hash); // true
bcrypt.compareSync("not_bacon", hash); // false
```
Auto-gen a salt and hash:
```javascript
var hash = bcrypt.hashSync('bacon', 8);
```
All I would like to know is, what these words stand for.
I am just guessing and have no clue.
"B4c0//" === the actual hash (of the correct password) from the database
"bacon" === hash of the correct password input
"not_bacon" === hash of a wrong password input
Is my guess correct?
Hope doing well. I was trying run a conditional group and push. I don’t know if it is possible with MongoDb aggregate or with NodeJs.
I have attendance collection and shifts collection like bellow. And also created Playground for my current try mongoplayground.
Attendances
[
{
"_id": "62206c873b2eaac4b15d42f9",
"employee": "6220624b3b2eaac4b15d42e8",
"createdAt": "2022-04-28T04:11:13.036Z"
},
{
"_id": "62206b173b2eaac4b15d42f1",
"employee": "6220624b3b2eaac4b15d42e8",
"createdAt": "2022-04-28T04:22:04.573Z"
},
{
"_id": "626cb9329a6fe1422b61d4e4",
"employee": "622062023b2eaac4b15d42e6",
"createdAt": "2022-04-30T04:21:06.965Z"
},
{
"_id": "626e19409a6fe1422b61d4f5",
"employee": "622062023b2eaac4b15d42e6",
"createdAt": "2022-05-01T05:23:12.342Z"
},
{
"_id": "626cb9329a6fe1422b61d4e6",
"employee": "622062023b2eaac4b15d42e6",
"createdAt": "2022-05-01T15:42:39.827Z"
},
{
"_id": "626cb9329a6fe1422b61d4e5",
"employee": "622062023b2eaac4b15d42e6",
"createdAt": "2022-05-02T09:46:51.439Z"
}
]
Shifts
[
{
"_id": "626965ee9a6fe1422b61d4b1",
"employee": "6220624b3b2eaac4b15d42e8",
"date": "2022-04-28",
"name": "Day",
"isNight": false
},
{
"_id": "626965ee9a6fe1422b61d4b2",
"employee": "622062023b2eaac4b15d42e6",
"date": "2022-04-30",
"name": "Night",
"isNight": true
},
{
"_id": "626965ee9a6fe1422b61d4b3",
"employee": "622062023b2eaac4b15d42e6",
"date": "2022-05-01",
"name": "Night",
"isNight": true
}
]
My requirement is, if isNight === true then push the next attendance record to previous date.
My required JSON should something like bellow.
[
{
"_id": {
"createdAt": "2022-04-28",
"employee": "6220624b3b2eaac4b15d42e8"
},
"attendances": [
{
"_id": "62206c873b2eaac4b15d42f9",
"createdAt": "2022-04-28T04:11:13.036Z",
"employee": "6220624b3b2eaac4b15d42e8"
},
{
"_id": "62206b173b2eaac4b15d42f1",
"createdAt": "2022-04-28T04:22:04.573Z",
"employee": "6220624b3b2eaac4b15d42e8"
}
],
"shifts": [
{
"_id": "626965ee9a6fe1422b61d4b1",
"date": "2022-04-28",
"employee": "6220624b3b2eaac4b15d42e8",
"isNight": false,
"name": "Day"
}
]
},
{
"_id": {
"createdAt": "2022-04-30",
"employee": "622062023b2eaac4b15d42e6"
},
"attendances": [
{
"_id": "626cb9329a6fe1422b61d4e4",
"createdAt": "2022-04-30T04:21:06.965Z",
"employee": "622062023b2eaac4b15d42e6"
},
{
"_id": "626e19409a6fe1422b61d4f5",
"createdAt": "2022-05-01T05:23:12.342Z",
"employee": "622062023b2eaac4b15d42e6"
}
],
"shifts": [
{
"_id": "626965ee9a6fe1422b61d4b2",
"date": "2022-04-30",
"employee": "622062023b2eaac4b15d42e6",
"isNight": true,
"name": "Night"
}
]
},
{
"_id": {
"createdAt": "2022-05-01",
"employee": "622062023b2eaac4b15d42e6"
},
"attendances": [
{
"_id": "626cb9329a6fe1422b61d4e6",
"createdAt": "2022-05-01T15:42:39.827Z",
"employee": "622062023b2eaac4b15d42e6"
},
{
"_id": "626cb9329a6fe1422b61d4e5",
"createdAt": "2022-05-02T09:46:51.439Z",
"employee": "622062023b2eaac4b15d42e6"
}
],
"shifts": [
{
"_id": "626965ee9a6fe1422b61d4b2",
"date": "2022-04-30",
"employee": "622062023b2eaac4b15d42e6",
"isNight": true,
"name": "Night"
}
]
}
]
How can I do with MongoDb or NodeJs. Please help me out.
I need to execute some action only when the tab is the active/current tab in a given browser window.
I tried this:
let intID = setInterval(()=>{
if(document.visibilityState == "visible"){
//doSomething();
}
}, 1000);
and this:
let intID = setInterval(()=>{
if(!document.hidden){
//doSomething();
}
}, 1000);
Both the above examples don’t work if the browser window is covered by another maximized window.
As far as I could understand from other articles on the web, focus and blur don’t do the job either.
I specifically need something that will work even in a completely covered or even minimized window.
I’m trying to build an app where you can toggle effects by clicking on the navitems.
On the nav items I have an event listener that toggles state
const [marker, setMarker] = useState(false);
onClick={() => setMarker(!marker)}
The idea is when it’s set to true, you can click on the map to set a waypoint. And when it’s false, clicking does the default behavior.
I tried using an if statement like this
if (marker) {
map.current.on('click', (e) => {
new mapboxgl.Marker().setLngLat(e.lngLat).addTo(map.current);
// Create a new marker.
});
}
Whether state is true or false, you can still place a waypoint after toggling it for the first time.
Can someone please tell me what I’m missing here? I know it’s something stupid.
We have a script that gets input from the cmd (easy trough commander, we are running Node) but once we have this input how can set a array?
For example, the input is “doge” and I want to call the Doge element of a dict.
I searched and tought window[] could do this, but is not the case for node.
const { program } = require('commander');
program
.option('-p, --pair <type>', 'pair tocken to farm');
program.parse(process.argv);
const options = program.opts();
if (options.pair) console.log(`- ${options.pair}`);
if (options.pair=='MATIC,BANANA') {
console.log(options.pair.split(',')[0])
}
const pair = obj[options.pair]
console.log(pair)
var dict = {
Name: ["Eric","rodrigez"],
Age: 23,
Job: "Freelancer",
Skills : "JavaScript",
BANANA :"perfect"
};
console.log(dict.pair)
I am setting up a div container to include both an image and an input element with type checkbox. The checkbox input includes a click handler that passes a value as an argument to some function. The input also includes a :value binding, which is passed to an array called checkBoxArray. Finally, the input uses v-model=checkBoxArray to check when the array contains a value. If the array contains a value, then the checkbox will be checked. I also wish to enable clicking on an image next to the checkbox, in order to also check and uncheck the checkbox. However, simply adding the click handler to the image is not enough. How can I go about enabling a click handler on the image element to also check and uncheck a box?
Here is my code so far:
<div v-for="item in items" :key="item.id">
<span class="flex-1 flex">
<span class="flex flex-col mr-4 mt-16">
<input v-model="checkBoxArray" :value="item.id" @click="someFunction(item.id)" type="checkbox" class="h-5 w-5" />
</span>
<span class="flex flex-col">
<img @click="someFunction(item.id)" class="h-full w-full" :src="item.image_url" alt="" />
</span>
</span>
</div>
const checkBoxArray = ref([])