How to enhance performance of MySQL query with for loop

I have node/express app and it connects to MySQL to fetch data.

I have a simple query like below

    const queries = [];

    for (let i = 0; i < students?.length; i++) {
        let query =
            ` SELECT 
                id,
                addmissionDate,
                standard

              FROM
                 studentTable

              WHERE 
                id = student[i].id `;

        queries.push(query);
    }

How do I execute above list of queries ? => using promise with map.

            db.getConnection(async (connectionErr, connection) => {

                if (connectionErr) {
                    return cb(connectionErr);
                }

                const queryResults = await Promise.all(
                    queries.map(async (query) => {
                        return new Promise((resolve, reject) =>
                            db.query(query, [], (err, result) => { // every time each query executes against database
                                if (err) {
                                    return resolve([]); 
                                } else {
                                    const separeteQueryResult = [];
                                    if (result === null) {
                                        result = []
                                    }
                                   
                                    return resolve(result);
                                }
                            })
                        );
                    })
                );
                
                connection.release();
                return cb(null, queryResults);
            })
        

Problem: with this approach is as students (array of objects) length increases, it takes time to execute individual query (basically one after another – NOTE above is just an example, in real world I have complex and heavy queries) because each query will execute against database.

Benefit:: If one of the queries fails, I will still get result of other successfully executed queries. So I had opted this approach.


I know one solution is to use union all as show below,

let query = ""

    for (let i = 0; i < students?.length; i++) {

       if(i!==0 && query!==""){
              query = query + " union all"
       }


        query = query + 
            ` SELECT 
                id,
                addmissionDate,
                standard

              FROM
                 studentTable

              WHERE 
                id = student[i].id `;

    }



            db.getConnection(async (connectionErr, connection) => {

                if (connectionErr) {
                    return cb(connectionErr);
                }
               
                db.query(query, [], (err, result) => {
                                if (err) {
                                    cb(err)
                                } else {
                                    cb(result)
                                }
                
                connection.release();
                return cb(null, queryResults);
            })
       

Problem: if one if union all queries fails, then entire query fails

Benefit: is it is faster in execution than previous approach


I guess the best solution could be writing a stored procedure(SP) but I don’t know how SP works with list of objects/array.

If someone can help me write better and performant approach….

How to concatenete 2 String to base64 String

How can i concatenete 2 Strings to Base64 String?

Ive tried this:

const base64basic = "data:image/png;base64,";
    const base64back = JSON.stringify(dataNew.base64Img);
    
    const base64picture = base64basic.concat(base64back)
      console.log(base64picture)

dataNew.base64Img is my Base64 String:

iVBORw0KGgoAAAANSUhEUgAAAEAAAAAwCAYAAAChS3wfAAAAAXNSR0IArs4c6QAAASFJREFUaEPtmsEOxCAIRAf3//94Ixu8CySkQbfTSw/VpLwOA2pljKFougTAZwJ2310i+6cqwBeKSgDSDkABcSL4ewCmPw+AJ05TwBTcrQAL3ksB1b081pMhlwOwIJwU8AAsddwOIPJfnZ5BAOYR15qgBe/JP4ITiCczHa1VIPWGDw86HkDkAV6ZzLAjgM5GKPOFqACnD1gm6rTKGcBMAaZA42owI1F6AD3Ab3RpgqwCtdUEyyDLIMtg364w+4AEgdc3QglGpSHHV4FSdInJBHB6GUx8xNIQKoAKOLwRKuk7MZkpwBRgCpy9FkikcWkIPYAeQA+gB1R+sCgZ0AmT200w2vCIIF1/LkAAwdEXFRAQYAqUjsak/y+xXg94PYBBBfwA5wWZJstGb8AAAAAASUVORK5CYII=

After concatenetion i get the output in console this:

data:image/png;base64,"iVBORw0KGgoAAAANSUhEUgAAAEAAAAAwCAYAAAChS3wfAAAAAXNSR0IArs4c6QAAASFJREFUaEPtmsEOxCAIRAf3//94Ixu8CySkQbfTSw/VpLwOA2pljKFougTAZwJ2310i+6cqwBeKSgDSDkABcSL4ewCmPw+AJ05TwBTcrQAL3ksB1b081pMhlwOwIJwU8AAsddwOIPJfnZ5BAOYR15qgBe/JP4ITiCczHa1VIPWGDw86HkDkAV6ZzLAjgM5GKPOFqACnD1gm6rTKGcBMAaZA42owI1F6AD3Ab3RpgqwCtdUEyyDLIMtg364w+4AEgdc3QglGpSHHV4FSdInJBHB6GUx8xNIQKoAKOLwRKuk7MZkpwBRgCpy9FkikcWkIPYAeQA+gB1R+sCgZ0AmT200w2vCIIF1/LkAAwdEXFRAQYAqUjsak/y+xXg94PYBBBfwA5wWZJstGb8AAAAAASUVORK5CYII="

There are " in the String, which should not there.

Deleting border-bottom from previous item on hover

I have this dropdown menu with categories and locations

categories:

news
politics
economy
health
education

locations (sub-categories)

europe
asia
africa
oceania
north america
South America

By default each category have a border-bottom:1px solid #121212, so obviously when you hover these categories (divs), and the sub-categories (locations) opens on hover, you will see that border too.

I want to have no borders on the selected (hovered) category, but whatever I do I can not get rid of this border, displayed on top of the hovered category, because it is not set on the hovered category but by default in the previous non-hovered category as border-bottom.

I do not know how to set the border on the category just above the selected one (hovered with black background and white text), to border:none

I think it could be done with some nth-child but maybe there is another way

Here is the HTML

<div id="menu" class="active">
  <div class="categories" tabindex="0">
    <div class="touch">News</div>
    <div class="locations">
      <a href="link.html">Europe</a>
      <a href="link.html">Asia</a>
      <a href="link.html">Africa</a>
      <a href="link.html">Oceania</a>
      <a href="link.html">North America</a>
      <a href="link.html">South America</a>
    </div>
  </div>

  <div class="categories" tabindex="0">
    <div class="touch">Politics</div>
    <div class="locations">
      <a href="link.html">Europe</a>
      <a href="link.html">Asia</a>
      <a href="link.html">Africa</a>
      <a href="link.html">Oceania</a>
      <a href="link.html">North America</a>
      <a href="link.html">South America</a>
    </div>
  </div>

  <div class="categories" tabindex="0">
    <div class="touch">Economy</div>
    <div class="locations">
      <a href="link.html">Europe</a>
      <a href="link.html">Asia</a>
      <a href="link.html">Africa</a>
      <a href="link.html">Oceania</a>
      <a href="link.html">North America</a>
      <a href="link.html">South America</a>
    </div>
  </div>

  <div class="categories" tabindex="0">
    <div class="touch">Health</div>
    <div class="locations">
      <a href="link.html">Europe</a>
      <a href="link.html">Asia</a>
      <a href="link.html">Africa</a>
      <a href="link.html">Oceania</a>
      <a href="link.html">North America</a>
      <a href="link.html">South America</a>
    </div>
  </div>

  <div class="categories" tabindex="0">
    <div class="touch">Education</div>
    <div class="locations">
      <a href="link.html">Europe</a>
      <a href="link.html">Asia</a>
      <a href="link.html">Africa</a>
      <a href="link.html">Oceania</a>
      <a href="link.html">North America</a>
      <a href="link.html">South America</a>
    </div>
  </div>

  <div class="categories" tabindex="0">
    <div class="touch">Culture</div>
    <div class="locations">
      <a href="link.html">Europe</a>
      <a href="link.html">Asia</a>
      <a href="link.html">Africa</a>
      <a href="link.html">Oceania</a>
      <a href="link.html">North America</a>
      <a href="link.html">South America</a>
    </div>
  </div>
</div>

And here is the CSS

a {
  color: #121212;
  text-decoration: none;
}
a:hover {
  color: #e5633f;
  text-decoration: none;
}

#menu {
  grid-area: menu;
  width: 100%;
  height: auto;
  text-align: left;
  border-bottom: 3px solid #121212;
  background-color: inherit;
  position: sticky;
  top: 0;
  cursor: pointer;
  z-index: 8;
}
.categories {
  display: block;
  position: relative;
  width: 92%;
  height: 42px;
  line-height: 42px;
  margin: 0 auto;
  overflow: hidden;
  text-align: left;
  border-bottom: 1px dotted #121212;
  font-size: 1em;
  text-transform: uppercase;
  font-weight: 400;
}
.categories .touch {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0;
}
.categories:hover .touch {
  color: #ffffff;
  background-color: #121212;
  padding-left: 25px;
}
.categories:hover .touch:before {
  content: "▪ News ▪ ";
}
.categories .touch:before {
  content: "▪ ";
}
.categories:last-of-type {
  border: 0;
}
.categories .touch:hover:before {
  content: "▪ News ▪ ";
}
.categories:first-of-type .touch:hover:before {
  content: "▪ Super Times ▪ ";
}
.categories:first-of-type:hover .touch:before {
  content: "▪ Super Times ▪ ";
}
.locations {
  display: none;
  position: relative;
  width: auto;
  height: auto;
  text-align: left;
  overflow: hidden;
  padding-left: 25px;
  padding-right: 25px;
  margin: 0 auto;
}
.locations a {
  display: block;
  font-size: 0.938em;
  color: #121212;
  text-transform: capitalize;
  text-align: left;
  height: 38px;
  line-height: 38px;
  border-bottom: 1px dotted #121212;
}
.locations a:hover {
  -webkit-tap-highlight-color: #e5633f;
  background-color: inherit;
}
.locations a:active {
  color: #e5633f;
  background-color: inherit;
}
.locations a:last-child {
  border: 0;
}
.categories:hover .locations {
  display: block;
  animation: supertimes 500ms ease-in-out forwards;
  transform-origin: top center;
}
.locations a:before {
  content: "• ";
}
@keyframes supertimes {
  0% {
    transform: scaleY(0);
  }
  80% {
    transform: scaleY(1.1);
  }
  100% {
    transform: scaleY(1);
  }
}

I also fixed a Codepen to play around with the code
https://codepen.io/familias/pen/jOQLRjp

How to fix this?

how to Deploy Lambda functions through Serverless framework with existing s3 bucket

I’m working on a project where I need to upload JS scripts using AWS Lambda serverless.

I provided the following functions in the Yaml file:

index:
handler: index.handler
events:
– s3:
bucket: s3-bucket-name
event: s3:ObjectCreated:*
rules:
– prefix: auction/
existing: true

I can activate an S3 bucket in a lambda function using the code above, however another S3 bucket is automatically created as well.

Can any one help on this

How can I change country flag in ngx-intl-tel-input programmatically?

I have a form where I ask user for their address and phone number. When the user enters his address I want to pick the country and automatically set the ngxx-int-tel-input phone field to the user country.

How can I do that.
Here is the stackblitz I have made
Stackblitz link to code

Right now I am able to change the country from Japan to Yemen. But how can I dynamically change to any country based on user Input. Say I have the country stored in a variable. For now I am hardcoding Yemen.
Is ther a way to add country dynamicallly like

 this.selectedCountryISO = CountryISO.<any-country>

I’m making an amazon clone website. How can i align this two div elements in the navigation bar, they are coming below the navigation bar

How do i align it in navbar

my index.html code

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Amazon</title>
    <link rel="stylesheet" href="styles.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
        integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>

<body>
    <header>
        <div class="navbar">
            <div class="nav-logo border">
                <div class="logo"></div>
            </div>
            <div class="nav-address border">
                <p class="add-first">Deliver To</p>
                <div class="add-icon">
                    <i class="fa-solid fa-location-dot"></i>
                    <p class="add-second">India</p>
                </div>
            </div>
            <div class="nav-search">
                <select class="search-select">
                    <option>All</option>
                </select>
                <input placeholder="Search Amazon" class="search-input">
                <div class="search-icon">
                    <i class="fa-solid fa-magnifying-glass"></i>
                </div>
            </div>
        </div>

        <div class="nav-signin border">
            <p><span>Hello,sign in</span></p>
            <p class="nav-second">Account & Lists</p>
        </div>
        <div class="nav-return border">
            <p><span>Returns</span></p>
            <p class="nav-second">& Orders</p>
        </div>


    </header>
</body>

</html>

**my styles.css code**
* {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    border: border-box;
}

.navbar {
    height: 60px;
    background-color: black;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-evenly;
}

.nav-logo {
    height: 50px;
    width: 100px;
}

.logo {
    background-image: url(amazon_logo.png);
    height: 50px;
    width: 100%;
    background-size: cover;
}

.border {
    border: 1.5px solid transparent;
}

.border:hover {
    border: 1.5px solid white;
}

/**box2**/

.add-first {
    color: #cccc;
    font-size: 0.85rem;
    margin-left: 15%;
}

.add-second {
    font-size: 1rem;
    margin-left: 3px;
}

.add-icon {
    display: flex;
    align-items: center;
}

/**box3**/
.nav-search {
    display: flex;
    justify-content: space-evenly;
    background-color: pink;
    width: 620px;
    height: 40px;
    border-radius: 4px;
}

.search-select {
    background-color: #f3f3f3;
    width: 50px;
    text-align: center;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
    border: none;
}

.search-input {
    width: 100%;
    font-size: 1rem;
    border: none;
}

.search-icon {
    width: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    background-color: rgb(255, 170, 0);
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    color: black;
}

/**box4**/
span {
    font-size: 0.7rem;
}

.nav-second {
    font-size: 0.85rem;
    font-weight: 700;
}

……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………..
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

How do I capture a hyperlink that has a customized text present in a mail body

My outlook add-in is currently capturing the body content of an email using the below code

Office.context.mailbox.item.body.getAsync(
        "text",
        function (result) {
            if (result.status === Office.AsyncResultStatus.Succeeded) {
                body = result.value;
                $('#item-Content').text(body);
            }
        }
    );

It is capturing hyperlinks that does not have a customized text. For example, it is capturing www.google.com, but does not capture the same link with a customized text like “click me”.

getModifierState() not working on dispatched Event

I’m trying to check for capslock state on page load. So far I’ve made this event listener:

document.addEventListener("keydown", capslockCheck)

and I’m dispatching an event on page load:

const event = new KeyboardEvent("keydown", { key: "Tab" })  // the key doesn't matter
document.dispatchEvent(event);

The event listener catches the event correctly but when I try to call getModifierState("CapsLock") on this simulated event, it always returns false. Whereas when a real key is pressed, it properly returns true | false as it should.

Thanks for your time guys!

ERROR: Unhandled exception: Cannot read properties of undefined (reading ‘FLAGS’)

please fix it its a discord bot antiswear.js code its sad i cant fix it , i have to exclude admins from antiswear module of bot but its not working properly tho –

const { Permissions } = require('discord.js');
const badWords = require('@src/badwords.json');

const warnedMessages = new Set();

function checkMessage(message) {
  const content = message.content.toLowerCase();

  if (message.member && message.member.permissions && message.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR, true)) {
    return; // Skip moderation actions for administrators
  }

  

Build a object with JSONPath-plus

Is it possible use JSONPath-plus for build an object starting from empty object?

EG:

const data = {}; // start from empty object

const updater = (cb: (value: string) => string): JSONPathCallback => (value, _, { parent, parentProperty }) => {
    parent[parentProperty] = cb(value);
   return parent;
}
// add in book object author name Foo Bar
const r = JSONPath({
    path: '$.book.author',
    json: data,
   callback: updater(() => 'Foo Bar'),
});
console.log(data)

expected output

{
  book: {
    author: 'Foo Bar'
  }
}

output

{}

ReactJS with Axios , AxiosError: Network Error

I have this code for API request.

var formData = new FormData();     
axios.defaults.xsrfHeaderName = "X-CSRFTOKEN";
axios.defaults.xsrfCookieName = "csrftoken";
axios.defaults.withCredentials = true;
axios.post(
    `http://localhost:8088/api/demo/`,formData,{
        headers: {'Content-Type': 'multipart/form-data'}
    }
);

It shows error like this below.

"AxiosError: Network Error
    at XMLHttpRequest.handleError (webpack://frontend_react/./node_modules/axios/lib/adapters/xhr.js?:171:14)"

However from console, it works.

curl -X POST http://localhost:8088/api/demo/
{"Hello":"DummyAPI"}

So I guess there is something wrong wigh axios,

I try this in local environment my server works on http://localhost:8000 and api works on http://localhost:8088 where should I check?

How can I solve this problem?

Drag items without triggering blur or mouseleave events

I perform some actions on blur or mouseleave, but initiating dragging of items in the container triggers these.

window.addEventListener(`blur`, () => {
  console.log(`blur triggered`)
})

document.documentElement.addEventListener(`mouseleave`, () => {
  console.log(`mouseleave triggered`)
})

document.documentElement.addEventListener(`mouseenter`, () => {
  console.log(`mouseenter triggered`)
})
.item {
  background-color: blue;
  border: 1px solid black;
  color: white;
}
<div>
  <div draggable=true class='item'>Item 1</div>
  <div draggable=true class='item'>Item 2</div>
  <div draggable=true class='item'>Item 3</div>
</div>

Basically I want none of these events triggering except when I normally move the cursor out of the window (and click in the case of blur).

Sending date in “YYYY-MM-DDTHH:MM:SS.MSZ” – Date-Time Picker in Angular

I am currently facing an issue with filtering data by date. Specifically, I need to send the date in the format “YYYY-MM-DDTHH:MM:SS.MSZ” to the backend.

I have attempted to use the simple HTML date picker with the input type set to “date”. However, this approach only sends the date, resulting in an error on the backend. I have also tried using the input type “datetime-local”, but it does not send the data in the required format of “YYYY-MM-DDTHH:MM:SS.MSZ”.

I have ng-bootstrap installed in my project, but unfortunately, it does not support a date time picker either.