nodegit – How to know if a commit is empty (to avoid pushing empty commits)

I’m using nodegit and I can’t figure out how to detect whether the there has been changes to commit.

Currently, I’m committing when an external event happens, but I don’t know if this will cause a real difference in the files. I don’t check whether the commit is empty before pushing, which led me to end up with lots of empty commits, I’d like to avoid that.

When doing it manually, I usually run a git status to check whether there were changes to commit, I was thinking about doing something similar here, but can’t figure out how. (here is the documentation)

  console.log('committing...');
  const commitResult = await commitFile(`schema.json`, schemaAsString, `${appName} (${appId})`);
  const statuses = await repo.getStatus();
  console.log('getStatus status', statuses);
  console.log('getStatus status', statuses[0].status());
  console.log('getStatus isModified', statuses[0].isModified());
  console.log('getStatus path', statuses[0].path());
  console.log('getStatus statusBit', statuses[0].statusBit());

  console.log('pushing...');
  const pushResult = await push(repo);
  console.log('pushResult', pushResult);

MIME type (‘text/html’) error in HTML and JS

So i am working with html, scss and javascript. But when i try to turn a file into a module and try to import another file, It throws an error
Loading module from “http://localhost:3000” was blocked because of a disallowed MIME type (“text/html”).

Here is my html (imports):

    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="shortcut icon" href="./images/core/Favicon.png">
        <link rel="stylesheet" href="./CSS/main.css">
        <link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
        <link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet"> 
        <link href="https://www.cssscript.com/wp-includes/css/sticky.css" rel="stylesheet" type="text/css">

        <!-- The script imports -->
        <script src="./Scripts/animations.js" defer></script>

        <!-- The file where i try to import a function from another file -->
        <script src="./Scripts/delivery.js" type="module" defer></script>
        <title>Home</title>
    </head>

Here is the file where I try to import a function (delivery.js):

import { confetti } from './confetti';

confetti();

// ...

Yes, i am exporting a function from confetti.js:

export function confetti() {
    // ...
}

Here is my file and folder structure for reference:

folders

Can anyone help.

Get only one element from nested array Mongoose

this is my schema

const ElectionScheme= new mongoose.Schema({
id:{
    type:Number
},
description:{
    type:String
},
startDate:{
    type:Date
},
closeDate:{
    type:Date
},
certificatesMaxAmount:{
    type:Number
},
voters:[{
   idCard:Number,
   credential:String,
   names: String,
   surnames:String,
   gender:String,
   birthDate:Date,
   department:String,
   idCircuit:Number,
   phone:Number,
   mail:String,
   votesCount:Number,
   certificatesCount:Number
}]

})

Hello, I am trying to extract a single voter by filtering by their idcard from an array in a model, but I always get the complete list of voters.
I try this

const Elections = require("../models/Elections");
Elections.findOne({ id: voteData.idElection,"voters.idCard":voteData.idCard, "candidates.idCard": voteData.idCandidate})
.select(["candidates", "voters", "electionMode"])
.lean().then(election => {...
}

enter code here

JavaScript pyramid where edges are odd numbers

I’m trying to print a pyramid that has odd numbers for edges. For example output should be:
…….5
…3,4,3
1,2,3,2,1
(dots are hear just to show formating)

I managed to write:

function p(n){
  let string = "";

for (let i = 1; i <= n; i++) {
 
  for (let j = 1; j <= n - i; j++) {
   string += " " ;
  }
  
  for (let k = 1; k <= 2*i-1; k++) {
    string += n-k +1;
  }
 string += "n";
}
console.log(string);
  
}


p(5);

But I’m not sure how to continue to get wanted result

Use imports in pyscript

I have wirtten some lines in python and want to integrate them into my website. As soon as I want to use them I recieve an error-message stating that the module can’t be found:

JsException(PythonError: Traceback (most recent call last): File "/lib/python3.10/site-packages/_pyodide/_base.py", line 429, 
in eval_code .run(globals, locals) File "/lib/python3.10/site-packages/_pyodide/_base.py", 
line 300, in run coroutine = eval(self.code, globals, locals) File "", line 1, 
in ModuleNotFoundError: No module named 'theblockchainapi' )

The html is very basic:

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<title>Document</title>

</head>
<body>
    <div>
        <input type="text" id = "address"> <br>
       <button id="button">Verify NFT</button>
        <div id="out">none</div>
    </div>
</body>
</html>
<py-env>
- theblockchainapi 
</py-env>
<py-script> 
from theblockchainapi import SolanaAPIResource, SolanaNetwork
</py-script>

How can I detect the IP address of a browser in Express?

This is not a duplicate of this SO post. That method does not work for me. The output is shown below. I am running a local node server on my MacBook and using chrome to test. I get this output.

undefined | ::1

I am connected to the network and can verify that my browser does have an IP address using zshell on Mac which is actually ( I have hidden the last 3 digits for this post):

100.64.98.xxx

However from my server I do not get a reading.

// derived from SO Post above
function getIP(app) {
  app.use((req, res, next) => {
    const ip1 = req.headers['x-forwarded-for'];
    const ip2 = req.socket.remoteAddress;
    const ip =  ip1 || ip2;

    // undefined | ::1
    console.log(ip1 + ' | ' + ip2);
    next();
  });
}

Sometimes the ordering of middleware seems to effect things, and I’m not sure if this might be the case here.

Smooth Concentric Radial Gradient in CSS

I’m trying to create a blurry donut shape like this on a canvas with js.
I tried

gradient.addColorStop(0, "rgba(0, 0, 0, .1)");
gradient.addColorStop(0.5, "rgba(128, 128, 128, .1)");
gradient.addColorStop(1, "rgba(0, 0, 0, .1)");

But I only get
enter image description here

It has a distinct defined circle at the stop radius. What I want is a smooth falloff. Something like this..

enter image description here

Is this possible?

create csv from objects with different keys

I have an array of objects. Some of their keys are identical but some of them exist only in one of the object:

const data =[
{id:123, name:foo, number:25},
{id:124, name:boo, number:35, blue:8},
{id:125, name:soo, number:40, red:10}
]

I want to convert my data into a CSV, so that the headers will include all keys. if key doesn’t exists in the object its value should be null , see example below:

id name number blue red
123 foo 25 null null
124 boo 35 8 null
125 soo 40 null 10

I was able to achieve this with few loops , but the code is ugly 🙂

Thanks!

HTML object is blocking eventlistener

I have imported a svg as an object in HTML:

  <object data="mySVG.svg" type="image/svg+xml" id="circle">
    <img src="mySVG.svg" />
  </object>

and I am trying to set an eventlistener on the whole page:

window.addEventListener('click', function(){
   alert('Hello')
})

The problem is that the object blocks the eventlistener and when the user clicks on the image the alert is not fired. But when the user clicks anywhere else or over other elements, the alert is fired. How can I make it so the object is acting as the other elements and doesn’t block the eventlistener?

I tried wait after the object is beaing loaded and then set the eventlistener but it didn’t work.

If I import the SVG directly into HTML with svg tag it works, but the svg is quit big and it makes the HTML code really messy. I can’t use the img tag either becuase I am also interacting with parts of the SVG with JS later.

Math rich text editor in react application

I need some starting points in math based text editor. I want to render both math expressions and also text stylings like headings, fonts etc…
I tried using React quill and draft libraries to add custom components, but latex as a component is not working.
Kindly help…

Select and deselect multiple div in react-js

In react-js click a div that div will highlight and click again it will normal, we select multiple div and unselect, select maximum four div only these are the conditions.
I beginner in react-js my div are ,

<div className='todoDiv select'>Task1</div>
<div className='todoDiv'>Task2</div>
<div className='todoDiv'>Task3</div>
<div className='todoDiv'>Task4</div>
<div className='todoDiv'>Task5</div>

here select class is used to highlight the div, how to solve this problem i have basic knowledge in react-js please help me

Can’t figure out why my React Component isn’t rendering?

Is there an issue with how I imported react or am I just missing something small? Any feedback would be greatly appreciated. I’m pretty new to programming so there’s probably a really simple solution here that I’m just not informed enough to see. Thanks.

    <!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- CSS only -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">


    <!-- React Import -->
    <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>

    <title>Markdown Previewer</title>
  </head>

    <script>
      class App extends React.Component {
        render() {
          return(
            <div class="">
            Hi
            </div>
          );
        }
      }

      ReactDOM.render(<App/>,
      document.getElementById('app'));
    </script>

  <body>
    <!--<wrapper>
      <div id="app"></div>
      <textarea name="name" rows="8" cols="80" id="editor"></textarea>
      <div id="preview"></div>
    </wrapper>-->
    <!-- JavaScript Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
    <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>



  </body>
</html>

I get an error whilst trying to load table

I get these errors whilst trying to load the table
‘Uncaught ReferenceError: usersArray is not defined
at loadUsers (trgames.js:20:17)
at trgames.js:22:1’ and ‘Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML’)
at XMLHttpRequest.xhttp.onreadystatechange (trgames.js:15:29)’
i’ve checked everything

var userTbody=document.getElementById('user-tbody');

function loadUsers(){
var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200){
         var userJSON=this.responseText;
         var usersArray=JSON.parse(userJSON);
         var tobodyHtml="";
         for(let index = 0; index < usersArray.lenght; index++) {
             const user = usersArray[index];
             tobodyHtml="<tr><td>"+user.id+"</td><td>"+user.username+"</td><td>"+user.password+"</td><td>"+user.birthdate+"</td></tr>";
             console.log(tobodyHtml);
         }
         userTbody.innerHTML=tobodyHtml;
        }
    };
    xhttp.open("GET", "http://localhost:8279/users", true);
    xhttp.send();
    console.log(usersArray);
}
loadUsers();
<!DOCTYPE html>
   <html>
       <head>
           <link rel="stylesheet" href="css/trgames.css">
          
           <meta charset="utf-8">
           <meta name="viewport" content="width=device-width, initial-scale=1">
           <script src="js/trgames.js"></script>
           <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.11.5/umd/popper.min.js" integrity="sha512-8cU710tp3iH9RniUh6fq5zJsGnjLzOWLWdZqBMLtqaoZUA6AWIE34lwMB3ipUNiTBP5jEZKY95SfbNnQ8cCKvA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
           <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
           <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
           <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
    </head>
     <body>
        <nav class="navbar navbar-expand-md bg-dark navbar-dark sticky-top">
        <div class="container-fluid">
            <a class="navbar-brand" href="/home">
              <img src="download.png" alt="Avatar Logo" style="width:40px;" class="rounded-pill"/> </a>
              <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapsibleNavbar">
                <span class="navbar-toggler-icon"></span>
              </button>
              <div class="collapse navbar-collapse" id="collapsibleNavbar">
                <ul class="navbar-nav"> 
                  <li class="nav-item">
                    <a class="nav-link" href="register.html">Game Register</a>
                  </li>
                  <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">Categories</a>
                    <ul class="dropdown-menu">
                      <li><a class="dropdown-item" href="#">User List</a></li>
                      <li><a class="dropdown-item" href="#">Most Popular</a></li>
                      <li><a class="dropdown-item" href="#">Most Downloads</a></li>
                    </ul>
                  </li>
                </ul>
              </div>
          </div>
        </nav>
        <table id="user-table">
           <thead>
               <tr>
                   <th>Id</th>
                   <th>Name</th>
                   <th>Password</th>
                   <th>Birthday</th>
               </tr>
           </thead> 
           <tbody id="user-tbody">

          </tbody>
        </table>

    </body>
   </html>