Skip to main content

Posts

Populate JSON with multiple string variables

I have simplified what I'm presenting here, but I'm having some trouble "populating" a JSON structure with these 3 variables. I can't figure out how to create new objects and I end up storing all of name, age or state in 1 object. I'm using nodeJS, any tips would be appreciated. const name = "Jason" + '\n' + "Freddy" + '\n' + "Chucky" const age = "31" + '\n' + "25" + '\n' + "15" const state = "CA" + '\n' + "NY" + '\n' + "PA" console output will show this Jason Freddy Chucky 31 25 15 CA NY PA I want to take those values from the 3 variables and create this... { "overview": [ { "people": [ { "name": "Jason", "age": "31", "state": "C...

AWS Lambda Node.js. mysql Error "Cannot enqueue Query after invoking quit" on second call onwards:

I am currently creating an AWS Lambda resolver that utilizes Nodejs mysql library. Right now, my lambda is capable of executing a query to the database during the first invocation. However, on the subsequent invocations the error "Cannot enqueue Query after invoking quit" occurs. I am aware that it is something to do with the connection to the database but if I am not wrong, 'connection.query' should be making an implicit connection to the database. I am also calling the 'connection.end' within the callback. Could someone lend me a helping hand on this one? Here is the Lambda index.js code: /* Amplify Params - DO NOT EDIT API_SIMPLETWITTERCLONE_GRAPHQLAPIENDPOINTOUTPUT API_SIMPLETWITTERCLONE_GRAPHQLAPIIDOUTPUT API_SIMPLETWITTERCLONE_GRAPHQLAPIKEYOUTPUT AUTH_SIMPLETWITTERCLONEB1022521_USERPOOLID ENV REGION Amplify Params - DO NOT EDIT */ const mysql = require("mysql"); // const util = require("util"); const config ...

How to download a chosen DIV with htmltocanvas in javascript image slider?

Html to canvas work but when I click on the download button it only download the first div even if I selected another div in the slider image with the mouse. I would like to select a div with image in the slider with the mouse 1/ select it 2/ Download it.thank you very much in advance for your help. Here is the full code: var $btn = document.getElementById('btnScreenShot'); $btn.addEventListener('mousedown', onScreenShotClick); function download( canvas, filename ) { // create an "off-screen" anchor tag const a = document.createElement('a'); // the key here is to set the download attribute of the a tag a.download = filename; // convert canvas content to data-uri for link. When download // attribute is set the content pointed to by link will be // pushed as "download" in HTML5 capable browsers a.href = canvas.toDataURL("image/png;base64"); a.style.display = 'none'; document.body....

Discord.js: The bot doesn't see message

I have been working on the Quick Math command, it works like this: I execute it, it sends a problem in chat, and whoever sends the correct answer wins. But as you can see, it doesn't see my 46 message, ignores it, and after 30 seconds sends "No one answered!" My code is: const { MessageEmbed } = require('discord.js'); const Discord = require("discord.js") module.exports = { name: "game", description: "smth", aliases: ["gamestart", "startgame"], permissions: ["MANAGE_MESSAGES"], timeout: 10000, execute: async (client, message, args) => { var a = Math.floor(Math.random() * 50) + 1 var b = Math.floor(Math.random() * 50) + 1 var ab = await a + b console.log(ab) let embed = new MessageEmbed() .setTitle(":chart_with_downwards_trend: Quick Math") .setDescription(`Solve the problem below and get XP.\n\n\`${a}\` + \`${b}\` = **???**`) .setFooter("123...

how to get current product category name in woocommerce

In WooCommerce single produce page I'm using some custom fields but one tab (see attachment picture right side tab 'Residential') I'd like to get the product category, which only one will be ticked. But I'm very unsure what code is needed to get that? Image: https://ibb.co/XJ7FvmT Any help to extract one product category name would be much appreciated. The product (a property) will only have one category. Ie. Land, Residential, Commercial, Industry etc. Thanks Here is some code from image that's from the add_action in functions.php <!-- Advanced Custom Feilds--> <span class="property-contract-badge"><?php echo get_field('listing_status'); ?></span> <span class="property-type-badge"><?php echo get_field('property_category'); ?></span> <!-- Get Woocommerce product category --> <span class="property-type-badge"><?php echo $product-...

Play a vizualisation before redirecting a HTML page

I have these different components that I want to mix together so that in result if someone would type 'website.xx' they would be redirected(by index.php) to 'website.xx/homepage.html'. This is not hard and can be found. <!--index.php--> <?php header("location: website.xx/homepage.html"); ?> But what if I want to play a vizualisation before it goes to 'website.xx/homepage.html' something like the code below. But then it needs to autoscroll to the bottom and after it should redirect homepage.html Is that possible or am I just being crazy. In either case, I could use a little bit of help.. Sorry Javascript isnt my strongest point. <!--someweirdcolorchanginghexagonvisual.html--> <html> <style> body { padding: 1em 0; background: #000 } svg { max-width: 100%; height: auto; display: block; } .hex { opacity: 0; transition-duration: 1000ms; transition-property: op...