Electron app isnt saving my input to json file

I’m encountering a crucial issue with my Electron app – the input isn’t being saved to the JSON file. I’ve tried troubleshooting, but haven’t found a solution. Any help will be appreciated.

The HTML code.

<div class="apikey">
   <label>Enter API Key</label>
   <input type="text", id="fapikey">
   <button onclick="saveApiKey()">Save</button>
</div>

The JavaScript code.

let config = JSON.parse(fs.readFileSync(path.join(__dirname, "data", "config.json")));
let apikey = config.apikey;

function saveApiKey() {
    apikey = document.getElementById("fapikey").value;
    config.apikey = apikey;
}

javascript variable to razor c# to MongoDB

For a school project I have to (no way around it) use c# Razor .Net and MongoDB

I want to get the text from a html element with javascript. This variable should than be used in c# to be added to the database.

I am not able to use the javascript variable in c#.

Also when the page is loaded, the c# code is instantly executed and not when called.

<script>

function addToDB() { 
    var stringToAdd = "demoString";
    @{
        var temp = MongoDatabase.GetoCollection<DemoModel>("DemoModels");

        var insertValue = new DemoModel()
        {
           Feature = new List<FeatureModel>()
           {
             new FeatureModel() { Name = "New Feature", FeatureGroup = "Group A" }
           }
        };

        temp.InsertOne(insertValue);
    }
}

</script>

I tried searching for solutions but they were all about “how to get variables from c# to javascript”, or the solution they provided did not match with my problem (as far as I understood).

Image in firebase store is not showing even with metadata

I’m trying to upload some images in the firebase storage, and the result I’m getting is not the result as I expected.

I was able to add a image into firebase with metadata but I cannot visualize the image.
as you guys can see the Type is correct, but i have this message “Error to load your image”

Here is my code

Here is my code

I expect that someone may help me fix my issue, and explain why my code is not working as I expect

Responsive ness in tailwindcss not working properly

I am confused about what I am doing wrong as there small item is also catching the medium item format as shown in the figure.
enter image description here

What am i doing wrong here?

It works when I try useing the webpage editor.(i don’t know what it’s called if you know, consider telling) me), but this is the expected out come.
enter image description here

            <div class="embeded_map p-3 w-full">
              <iframe
                src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3520.2554797542!2d81.6262151743212!3d28.077748975972206!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3998671773c7e34f%3A0xe85908dc0d1c6717!2sDhambojhi%20Secondary%20School!5e0!3m2!1sen!2snp!4v1685325210940!5m2!1sen!2snp"
                className="w-[600px] h-[450px] rounded-lg shadow-xl"
                allowfullscreen
                loading="lazy"
                referrerpolicy="no-referrer-when-downgrade"
              ></iframe>
            </div>
            <div class="flex flex-col p-3 w-full">
              <ul class=" p-3">
                <li className="py-3 font-bold text-[25px]">
                  <FontAwesomeIcon icon={faLocationDot} className=" pr-3" />
                  Nepalgunj-1, Dhambojhi, Waterpark, Nepalgunj, Banke, Nepal
                </li>
                <li className="py-2 font-medium text-[20px]">
                  <FontAwesomeIcon icon={faSchool} className=" pr-3" />
                  Dhambojhi Secondary School
                </li>
              </ul>
            </div>
          </div> 

Send the address of the selected photo to the database

Suppose we have several photos on the page, for example, I have several photos on the page, now I want when we fill the name field and select a photo, the information of the selected photo, such as its ID and src, along with the value of the name field, will be stored in the database.

When we select an image, the frame around the image turns green:
enter image description here

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .image {
            width: 100px;
            height: 100px;
            float: left;
            margin: 10px;
        }

        .selected {
            border: 3px solid #00ff00;
        }
    </style>
</head>

<body>

    <form action="insert.php" method="post">
        <label for="name">Name: </label>
        <input type="text" name="name" id="name">

        <div>
            <p>Please choose one of the images below:</p>
            <img for="1" class="image" src="gallery/01.jpg" alt="" width="300px">
            <img id="2" class="image" src="gallery/02.jpg" alt="" width="300px">
            <img id="3" class="image" src="gallery/03.jpg" alt="" width="300px">
            <img id="4" class="image" src="gallery/04.jpg" alt="" width="300px">
            <img id="4" class="image" src="gallery/05.jpg" alt="" width="300px">
        </div>
        <div>
            <button sty type="submit">Submit</button>
        </div>

    </form>

    <script src="assets/jquery-3.7.1.min.js"></script>

    <script>
        $(".image").on('click', function() {
            $('.image').removeClass('selected');
            $(this).addClass('selected');
        });
    </script>
</body>

</html>

escaping button on click it change position

I ran into an issue .for fun I wanted to create a yes and no buttons
onclicking on no the no button and if it reach the page limit it go back

function move() {
    var No = document.getElementById('butt2');
    No.style.marginLeft = "100px";
    No.style.marginTop = "100px";

    var Yes = document.getElementById('butt1');
    Yes.style.marginLeft = "100px";
    Yes.style.marginBottom = "0px";

}
<div class="basa">
    <button class="butt" id='butt1'>Yes</button>
    <button class="butt2" id='butt2' onclick="move()">No</button>
</div>

my method change the position of the yes and no and on clicking the second time it doesn’t work

What does the $ sign do in regex?

It says that:

$ specifies a match at the end of a string

So why then is a match returned for c$ in the string abc? If c is the last character of the string, shouldn’t it be looking for what comes after c and not c itself, and therefore return null?

Function takes input, returns multiple inputs as function

I’m trying to figure out how to mock out this function but don’t understand the syntax.

The function is an API call that takes one parameter, which is an Api class, then it returns an async function that takes multiple inputs:

public static updateList(apiAgent: ApiAgent) {
    return async (request: Material[], listTypeAndId: CreatedList): Promise<CreatedList> => {
      return await apiAgent.put(`/v2/lists/list/${listTypeAndId.listType}/material?listId=${listTypeAndId.id}`, request) as MaterialListContent;
    };
}

In code when I have to call this function it looks like this:

await Service.updateList(this.apiAgent)(updateRequest, experimentMaterialLists[0]);

I’m not familiar with this syntax and not exactly sure what it is called.

But the main issue I am trying to solve is I am trying to test this call with Jest. For my particular test, I want to verify that the body of the request contains what I want.

But with this syntax I cannot seem to use any expect.ojbectContaining because they keep being compared to the first parameter of the function, which is the ApiAgent. In this case I don’t care about the ApiAgent I only want to know what is in the body of the request.

For example I have something like this:

const updateCall = jest.spyOn(Service, 'updateList');
expect(updateCall).toBeCalledWith(expect.anything(), expect.objectContaining(updateObject), expect.anything());

This always fails because it thinks there is only one input to the mocked object. And due to my lack of knowledge around this syntax I cannot resolve it.

With the same code, why are the execution results inconsistent?

I have an HTML code.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>demo</title>
</head>
<body>
<script src="./script1.js"></script>
<script src="./script2.js"></script>
<script>
    console.log('inline-111')
    setTimeout(() => {
      console.log('inline-setTimeout-111')
    }, 0);
</script>
<script>
   console.log('inline-222')
    setTimeout(() => {
      console.log('inline-setTimeout-222')
    }, 0);
    setTimeout(() => {
      console.log('inline-setTimeout-333')
    }, 0);
    new Promise(resolve => {
      console.log('inline-Promise1')
      resolve()
    })
      .then(function () {
        console.log('inline-promise2')
      })
      .then(function () {
        console.log('inline-promise3')
      })
</script>
</body>
</html>

The first script tag code.

console.log("external-111");
setTimeout(() => {
  console.log("setTimeout-external-111");
}, 0);

The second script tag code.

console.log("external-222");
setTimeout(() => {
  console.log("setTimeout-external-222");
}, 0);
setTimeout(() => {
    console.log("setTimeout-external-333");
  }, 0);
  
new Promise((resolve) => {
  console.log("external-Promise1");
  resolve();
})
  .then(function () {
    console.log("external-promise2");
  })
  .then(function () {
    console.log("external-promise3");
  });

When running in Google Chrome(Chrome119.0.6045.200), the result is

external-111
setTimeout-external-111
external-222
external-Promise1
external-promise2
external-promise3
inline-111
inline-222
inline-Promise1
inline-promise2
inline-promise3
setTimeout-external-222
setTimeout-external-333
inline-setTimeout-111
inline-setTimeout-222
inline-setTimeout-333

When running in Firefox(121.0.1), the result is

external-111 
external-222  
external-Promise1
external-promise2
external-promise3
inline-111
inline-222
inline-Promise1
inline-promise2
inline-promise3
setTimeout-external-111
setTimeout-external-222
setTimeout-external-333
inline-setTimeout-111
inline-setTimeout-222
inline-setTimeout-333

Why is the output on the second line inconsistent?
Is there any kind-hearted friend who can try to explain?

At first, I wanted to understand how the event loop would run when multiple scripts were mixed in the browser. But the two running results caused confusion.

Limit length of each element present in an array in angular

I have a requirement where I have an input field. In that input field I am passing string value seperated by commas. I am storing each input value in array. I want to restrict user from entering more than 4 characters.

For example: Suppose we have this input

["mango","papaya","jackfruit"]

I want like

["mang","papa","jack"]

I want that when someone enters more than 4 character it wont allow user to enter anything thereafter. If he presses comma then he is allow to write another string value of 4 character

component.html

<input formControlName="name" (keypress)="singleElement($event)" (input)="inputName($event)">

component.ts

inputName(event){

 this.value = (<HTMLInputElement>event.target).value    
}


singleElement(event) {
 return(
 (event.charCode > 64 && event.charCode < 91) ||
 (event.charCode > 96 && event.charCode < 123) ||
 (event.charCode > 47 && event.charCode < 58) ||
 event.charCode == 44
 )}

How to create a shadowDOM with bootstrap dropdown menu in JS

I am creating a chrome extension where i need to add the split-button provided by the bootstrap as a shadowDOM. but i couldn’t find any clear documentation for it.Could someone tell me how to create a shadowDOM which would inject the bootstrap css, js and popper js file.

I have tried like below but the button was not visible.

const shadowHost = document.getElementById('my-shadow-host');
const shadowRoot = shadowHost.attachShadow({ mode: 'open' });

  // Bootstrap button and dropdown menu HTML
const bootstrapButtonAndDropdown = `
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <div class="btn-group">
    <button type="button" class="btn btn-primary">Bootstrap Button</button>
    <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      <span class="sr-only">Toggle Dropdown</span>
    </button>
    <div class="dropdown-menu">
      <a class="dropdown-item" href="#">Action</a>
      <a class="dropdown-item" href="#">Another action</a>
      <a class="dropdown-item" href="#">Something else here</a>
      <div class="dropdown-divider"></div>
      <a class="dropdown-item" href="#">Separated link</a>
    </div>
  </div>
`;

  // Append Bootstrap components to the shadow root
  shadowRoot.innerHTML = bootstrapButtonAndDropdown;

  // Add an event listener to the button inside the Shadow DOM
  const buttonInsideShadowDom = shadowRoot.querySelector('.btn-primary');
  buttonInsideShadowDom.addEventListener('click', () => {
    alert('Button inside Shadow DOM clicked!');
  });

class SplitButton extends HTMLElement {
  constructor() {
    super();
    this.render();
  }

  render() {
    this.attachShadow({ mode: "open" });
    this.shadowRoot.innerHTML += template;
  }
}

window.customElements.define("split-button", SplitButton);

Calling the splitbutton

const button = document.createElement('split-button');

But the button returns null.

KeyboardEvent: detect that a key has a printed representation

In my React/Javascript app, I am listening for KeyboardEvents. The documentation for the key property is quite clear on how to get the pressed key value:

Its value is determined as follows:

  • If the pressed key has a printed representation, the returned value is a non-empty Unicode character string containing the printable representation of the key.
  • If the pressed key is a Space key, the returned value is a single space
  • If the pressed key is a control or special character, the returned value is one of the pre-defined key values.

I want to test that the pressed key has a printed representation or is a Space. i.e. it is NOT one of the pre-defined key values.

I could not find a hasPrintedRepresentation property. Should I write my own hasPrintedRepresentation() that tests and excludes each one of those 400-or-so pre-defined key values before returning true? I could not find a library that already does this grunt work. Did I miss something? Thank you!

Handle Node Js schedule

I need some help. Here, you can see I created a Mongoose model and statics. In this system, a user can create tasks and assign them to employees. Additionally, the user can configure the date and time. The main factor is implementing a reminder system. Users can configure daily, weekly, or monthly reminders. If a user creates a task for 8 a.m. and repeats it daily, I need to handle cron jobs at 8 a.m. every day. Users can configure any time from 8 a.m. to 11:59 p.m.

For this scenario, handling cron jobs every minute is necessary because I don’t know which user created tasks for specific times, like 8:10 a.m. and another at 8:11 a.m. However, creating cron jobs for every minute may overload the server due to frequent API calls. What is a good way to handle this efficiently? How do developers manage this type of system effectively?

I use Node.js, Express.js, and Mongoose. For cron jobs, I use the node-scheduler package.

Thank you.
The code:enter image description here