Error in deploying react application to github pages: cannot find git

I’m building a react app and then I’m trying to deploy it to github pages using the gh-pages node module.

Here’s my package.json file:

package.json

package.json(continued)

Here’s the error that I’m getting when I run “npm run deploy”(react-script for gh-pages -d build):

error from both zsh and bash terminals

I’ve updated the PATH variable with where the git module is located but the error still persists. Please help.

asp-action and asp-controller in innerHtml in js file

I need insert Html in Html document. I use innerHtml for this.

let newCardHTML = `
                    <div class="header">
                        <h4 class="card-counter">${currentCardNumber}</h4>
                        a class="button-bin btn" asp-action="DeleteCard" asp-controller="Cards" asp-route-cardId="currentCardNumber" ></a>                       
                    </div>`

I receive error Attribute DeleteCard is not allowed here.

I try

var url = '@Url.Action("DeleteCard","Cards", new {cardId = 0})';
var linkHtml = '<a class = button-bin btn" href ="' + url+ '"></a>';
newCardHTML.querySelector('.header').innerHTML = linkHtml;

However this doesn’t work and Local variable linkHtml is redundant.

How to create unique id on each block of quill editor?

I want to add a uniq id to each p block of quill editor.

I have tried this piece of code but it only adds the same id to each p block.

const BlockBlot = Quill.import('blots/block');

class CustomBlockBlot extends BlockBlot {
  static create(value) {
    const node = super.create(value);
    node.setAttribute('id', Math.random());
    return node;
  }
}
Quill.register('formats/block', CustomBlockBlot);

const quill = new Quill('#surface-render', {
  theme: 'snow',
  modules: {
    toolbar: toolbarOptions
  }
});

How would you do this?

Handlebars is not defined” Error in NetSuite User Event Script

I’m fairly new to NetSuite, although I have done some maintenance work on existing SuiteScript code before. Currently, I’m working on a NetSuite User Event Script that uses Handlebars.js to generate a JSON payload from customer record data. However, I keep running into an error where the script logs “Handlebars is not defined”. Despite trying different approaches to load and initialize Handlebars, the issue persists.

Environment:
NetSuite API Version: 2.0
Script Type: User Event Script
Script Trigger: After Submit on Customer record creation and edit
What I’ve Tried:
Loading Handlebars.js:

I uploaded the handlebars.min.js file to the SuiteScripts/Libraries folder in NetSuite.
I’m loading the library using the file.load() function and then trying to execute it using Function().

Attempt to Initialize Handlebars:

var handlebarsFile = file.load({ id: 'SuiteScripts/Libraries/handlebars.min.js' });
var handlebarsLib = handlebarsFile.getContents();
var Handlebars = Function(handlebarsLib + 'return Handlebars;')();

Error Handling:

Despite this, I’m consistently seeing the error “Handlebars is not defined” in the script execution logs.

Script Details:
Here’s my script:

     /**
     * @NApiVersion 2.x
     * @NScriptType UserEventScript
     * @NModuleScope SameAccount
     */

    define(['N/record', 'N/log', 'N/file', 'N/https'], function(record, log, file, https) {

    function afterSubmit(context) {
        log.debug('Script Triggered', 'After Submit script triggered for customer record.');
        if (context.type !== context.UserEventType.CREATE && context.type !== context.UserEventType.EDIT) return;

        try {
            // Load the Handlebars.js library
            var handlebarsFile = file.load({
                id: 'SuiteScripts/Libraries/handlebars.min.js'
            });
            var handlebarsLib = handlebarsFile.getContents();

            // Execute the Handlebars library code in the current scope
            var Handlebars = Function(handlebarsLib + 'return Handlebars;')();

            log.debug('Handlebars Loaded', 'Successfully loaded Handlebars.');

            // Load the customer record
            var customer = record.load({
                type: record.Type.CUSTOMER,
                id: context.newRecord.id
            });

            log.debug('Customer Record Loaded', 'Customer ID: ' + customer.id);

            // Extract customer data
            var data = {
                email: customer.getValue('email') || '',
                firstname: customer.getValue('firstname') || '',
                lastname: customer.getValue('lastname') || '',
                username: customer.getValue('email') || '',
                phone: customer.getValue('phone') || '',
                role: customer.getText('pricelevel') || '',
                password: customer.getValue('custentity_pm_int_cust_pass') || '',
                billing: {},
                shipping: {}
            };

            // Extract address book data
            var addressCount = customer.getLineCount('addressbook');
            for (var i = 0; i < addressCount; i++) {
                var isBilling = customer.getSublistValue({
                    sublistId: 'addressbook',
                    fieldId: 'defaultbilling',
                    line: i
                });
                var isShipping = customer.getSublistValue({
                    sublistId: 'addressbook',
                    fieldId: 'defaultshipping',
                    line: i
                });

                var address = {
                    company: customer.getValue('companyname') || '',
                    firstname: customer.getValue('firstname') || '',
                    lastname: customer.getValue('lastname') || '',
                    addr1: customer.getSublistValue({
                        sublistId: 'addressbook',
                        fieldId: 'addr1',
                        line: i
                    }) || '',
                    addr2: customer.getSublistValue({
                        sublistId: 'addressbook',
                        fieldId: 'addr2',
                        line: i
                    }) || '',
                    city: customer.getSublistValue({
                        sublistId: 'addressbook',
                        fieldId: 'city',
                        line: i
                    }) || '',
                    state: customer.getSublistValue({
                        sublistId: 'addressbook',
                        fieldId: 'state',
                        line: i
                    }) || '',
                    zip: customer.getSublistValue({
                        sublistId: 'addressbook',
                        fieldId: 'zip',
                        line: i
                    }) || '',
                    country: customer.getSublistValue({
                        sublistId: 'addressbook',
                        fieldId: 'country',
                        line: i
                    }) || '',
                    phone: customer.getValue('phone') || ''
                };

                if (isBilling) {
                    data.billing = address;
                    log.debug('Billing Address Found', JSON.stringify(address));
                }

                if (isShipping) {
                    data.shipping = address;
                    log.debug('Shipping Address Found', JSON.stringify(address));
                }
            }

            // Handlebars template as a string
            var templateSource =
                '{' +
                '"data":{' +
                '"email": "{{record.email}}",' +
                '"first_name": "{{record.firstname}}",' +
                '"last_name": "{{record.lastname}}",' +

                '{{#if record.pricelevel}}' +
                '"role": [' +
                '"{{wooCommerceRole record.pricelevel.name}}",' +
                '{{#if record.custentity_pm_int_ws_credit_hold}} "credit_hold", {{/if}}' +
                '{{#if_eq record.terms.internalid "4"}} "cod" {{else}} "terms" {{/if_eq}}' +
                '],' +
                '{{/if}}' +
                '{{#if record.custentity_pm_int_update_ws_pass}}' +
                '"password": "{{record.custentity_pm_int_cust_pass}}",' +
                '{{/if}}' +
                '"username": "{{record.email}}",' +
                '"phone": "{{record.phone}}"' +
                '{{#if (gt record.addressbook.length 0)}}' +
                '{{#each record.addressbook}}' +
                '{{#if defaultbilling}}' +
                ',"billing": {' +
                '"company": "{{../record.companyname}}",' +
                '"first_name": "{{../record.firstname}}",' +
                '"last_name": "{{../record.lastname}}",' +
                '"address_1": "{{addr1}}",' +
                '"address_2": "{{addr2}}",' +
                '"city": "{{city}}",' +
                '"state": "{{state}}",' +
                '"postcode": "{{zip}}",' +
                '"country": "{{country}}",' +
                '"phone": "{{../record.phone}}"' +
                '}' +
                '{{/if}}' +
                '{{/each}}' +
                '{{#each record.addressbook}}' +
                '{{#if defaultshipping}}' +
                ',"shipping": {' +
                '"company": "{{../record.companyname}}",' +
                '"first_name": "{{../record.firstname}}",' +
                '"last_name": "{{../record.lastname}}",' +
                '"address_1": "{{addr1}}",' +
                '"address_2": "{{addr2}}",' +
                '"city": "{{city}}",' +
                '"state": "{{state}}",' +
                '"postcode": "{{zip}}",' +
                '"country": "{{country}}",' +
                '"phone": "{{../record.phone}}"' +
                '}' +
                '{{/if}}' +
                '{{/each}}' +
                '{{/if}}' +
                '}' +
                '}';

            // Compile the Handlebars template with the data
            var hbTemplate = Handlebars.compile(templateSource);
            var jsonData = hbTemplate({
                record: data
            });

            log.debug('Generated JSON', jsonData);

            // Send the JSON to the middleware endpoint
            var response = https.post({
                url: 'https://middleware.exampleserver.io/customer-sync',
                body: jsonData,
                headers: {
                    'Content-Type': 'application/json'
                }
            });

            log.debug('Response from API', response.body);

        } catch (e) {
            log.error('Error in afterSubmit', e.message);
        }
    }

    return {
        afterSubmit: afterSubmit
    };
});

Original Handlebars Template:
Here’s the original Handlebars template I’m trying to work with:

{
"data": {
    "email": "{{record.email}}",
    "first_name": "{{record.firstname}}",
    "last_name": "{{record.lastname}}",

    {
        {
            #if record.pricelevel
        }
    }
    "role": [
            "{{wooCommerceRole record.pricelevel.name}}",
            {
                {
                    #if record.custentity_pm_int_ws_credit_hold
                }
            }
            "credit_hold",
            {
                {
                    /if}} {
                        {
                            #if_eq record.terms.internalid "4"
                        }
                    }
                    "cod" {
                        {
                            else
                        }
                    }
                    "terms" {
                        {
                            /if_eq}}
                        ], {
                            {
                                /if}} {
                                    {
                                        #if record.custentity_pm_int_update_ws_pass
                                    }
                                }
                                "password": "{{record.custentity_pm_int_cust_pass}}", {
                                    {
                                        /if}}
                                        "username": "{{record.email}}",
                                        "phone": "{{record.phone}}" {
                                            {
                                                #ifgreaterthan record.addressbook.length 0
                                            }
                                        } {
                                            {
                                                #each record.addressbook
                                            }
                                        } {
                                            {
                                                #if defaultbilling
                                            }
                                        }, "billing": {
                                            "company": "{{{../record.companyname}}}",
                                            "first_name": "{{../record.firstname}}",
                                            "last_name": "{{../record.lastname}}",
                                            "address_1": "{{addressbookaddress.addr1}}",
                                            "address_2": "{{addressbookaddress.addr2}}",
                                            "city": "{{addressbookaddress.city}}",
                                            "state": "{{addressbookaddress.state}}",
                                            "postcode": " {{addressbookaddress.zip}}",
                                            "country": "{{addressbookaddress.country.internalid}}",
                                            "phone": " {{{../record.phone}}}"
                                        }

                                        {
                                            {
                                                /if}} {
                                                    {
                                                        /each}}

                                                        {
                                                            {
                                                                #each record.addressbook
                                                            }
                                                        } {
                                                            {
                                                                #if defaultshipping
                                                            }
                                                        }, "shipping": {
                                                            "first_name": "{{../record.firstname}}",
                                                            "last_name": "{{../record.lastname}}",
                                                            "company": "{{{../record.companyname}}}",
                                                            "address_1": "{{addressbookaddress.addr1}}",
                                                            "address_2": "{{addressbookaddress.addr2}}",
                                                            "city": "{{addressbookaddress.city}}",
                                                            "state": "{{addressbookaddress.state}}",
                                                            "postcode": " {{addressbookaddress.zip}}",
                                                            "country": "{{addressbookaddress.country.internalid}}",
                                                            "phone": " {{{../record.phone}}}"
                                                        } {
                                                            {
                                                                /if}} {
                                                                    {
                                                                        /each}} {
                                                                            {
                                                                                /ifgreaterthan}}
                                                                            }
                                                                        }

What I Need Help With:

Correct Method for Loading Handlebars.js: Is there a more reliable way to load and initialize Handlebars in a NetSuite SuiteScript environment?

Alternatives: If Handlebars is not viable in SuiteScript, what alternatives would you suggest for dynamically generating JSON from a template?

Maybe I’m going about this the wrong way, so I’d really appreciate any guidance or suggestions you can offer.

How can i visualise node-cache data, similar to redis-commander for redis

Is there a way I can visualise my node-cache data similar to redis-commander for redis?

Actually I m using node-cache for api data caching, some times I faces issue on production environment, which i can only trouble shoot via console logs, and if I add console log for node-cache on each line, that will be a mess to code as well for console. I was looking towards to see some web based solution to monitor the values.

I tried to separate out logs in a text file for latest values but it reduces the performance for API, so I m looking towards some web based solution.

iPhone 15 safari browser switch event trigger

It is possible to trigger an event eg browser or profile switch or incognito mode by using the volume up and power buttons in iOS ?
Something is happening when she does this but I can’t pin it ?

I believe I’m watching some body do it but they are keeping it on the low .i don’t write code but i need to learn this .

Where primitives inside objects are actually stored

When i Declare an Object and inside of that object i made a property that holds a primitive value

so in this Example

const foo =  {
  firstName: 'bar'
}

where the bar actually stored is it points the specific memory on the stack then and the value in there or it stored as it is in a some address in the heap

How to pass a global environment variable set during docker run command into a react app?

I am trying to run a container on my image.

The container run command I am using is:

docker run -e REACT_APP_BACKEND_WEBSERVICE="http://webservice-backend:8080" -p 3000:3000 username/webservicename

Then in my react code, I am trying to access it at the runtime using

console.log(process.env.REACT_APP_BACKEND_WEBSERVICE);

But in my console it is printing undefined.

I dont want to pass the env variable from the dockerfile itself.

Why is Django App Not Rendering HTML Page

Hello I am using Django version 4.2.3 to build my website for building my website. I have an Object called UE (upcoming_events) that I have added several fields to however, these fields don’t seem to be rendering when I call the object instead the words No Events render which only happen when the upcoming_events object is empty. In order to see why this is happening I used the Django Shell to visualize the code post processing. But in the visualization the code seems to populate the objects just fine just not when rendering the object on the website.

{% extends "webapp/header.html" %}

{% block content %}
<div class = "centerbody">
    <div class="liner">
    <!--Carousel Starts-->
    <div class = 'dive'></div>
    <div class = float_col>
      <div id="carouselExampleFade" class="carousel slide carousel-fade span" data-ride="carousel">
      <div class="carousel-inner carouselMargin1">
        <div class="carousel-item active">
          <img src="/static/images/CarouselPictures1/canyonphoto1.jpg/" class="d-block w-100 carouselImgs" alt="...">
        </div>
        <div class="carousel-item">
          <img src="/static/images/CarouselPictures1/canyonphoto2.jpg" class="d-block w-100 carouselImgs" alt="...">
        </div>
        <div class="carousel-item">
          <img src="/static/images/CarouselPictures1/canyonphoto3.jpg/" class="d-block w-100 carouselImgs" alt="...">
        </div>
      </div>
      <a class="carousel-control-prev" href="#carouselExampleFade" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="carousel-control-next" href="#carouselExampleFade" role="button" data-slide="next">
        <span class="carousel-control-next-icon next_button" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
      </div>
    </div>
  
   <div class="announcements">
      <h2>Announcements</h2>
      <div class="announcement-container">
      {% for announcement in announcements %}
          <div class="announcement-item">
              <img src="{{ announcement.image.url }}" alt="{{ announcement.title }}" class="announcement-image">
              <div class="announcement-info">
                  <h3>{{ announcement.title }}</h3>
                  <p>{{ announcement.description }}</p>
                  <span class="announcement-date">{{ announcement.event_date }}</span>
              </div>
          </div>
      {% empty %}
          <p>No announcements at this time.</p>
      {% endfor %}
      </div>
  </div>
   <!--Carousel Ends-->
  
  <!--This cell contains the table for the main content area-->
  <table cellpadding="0" cellspacing="0" width="700">
      <tbody>
        <tr>
          <td height="10" width="25">
            &nbsp;</td>
          <td height="160" width="126">
            <img height="120" src="https://3bac6cafdb-custmedia.vresp.com/library/1305142154/154bc2e38d/Templates/bwlogo2.gif" style="width: 110px; height: 120px;" width="110" /></td>
          <td height="10" width="36">
            &nbsp;</td>
          <td font="helvetica" height="110" width="513">
            <h1 style="color:whitesmoke ; font-family: Helvetica,sans-serif; font-size: 30px; margin-top: 50px; margin-bottom: 40px;">
              UPCOMING EVENTS <span style="color:wheat;">June &amp; BEYOND</span></h1>
            <img height="9" src="https://3bac6cafdb-custmedia.vresp.com/library/1305142180/83bdb2a586/Templates/top_bar.gif" style="width: 518px; height: 15px;" width="518" /></td>
        </tr>
        <tr>
          <td colspan="4" height="28" width="700">
            &nbsp;</td>
        </tr>
      </tbody>
    </table>
    <td class = "upcomingEvents" valign="top" width="700">
      <table cellpadding="0" cellspacing="0" width="700">

        <!--First Event-->
        <section>
          <div class = "events">
        {% for event in upcoming_events %}
           <ul>
             <li>
               <div class = "time">

                 <h2> {{ event.UE_date }}<span> {{ event.UE_time }}</span></h2>
               </div>
               <div class = "details">
                 <!-- Event Title goes here-->
                 <h3>{{ event.UE_title }} @ {{ event.UE_location }}</h3>
                 <!-- Event Content goes here-->
                  <p>
                      {{ event.UE_content }} 
                  </p>
                  <!-- Event Content goes here-->
                   <a href="/resourcePage/">View Details</a>
               </div>
               <div style="clear: both;"></div>
            </li>
           </ul>
           {% empty %}
           <p>No Events</p>
           {% endfor %}
          </div>
        </section>
      </div>
    </div>
{% endblock %}

Writing this from django.shortcuts import render
from .models import UE

def home(request):
    upcoming_events = UE.objects.order_by('-UE_pub_date')[:5]  # Ensuring this query is correct
    context = {'upcoming_events': upcoming_events}  # Check the variable name here
    return render(request, 'webapp/home.html', context)

in the Django Shell gives the following output:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">

        <link rel="stylesheet" href="/static/css/bootstrap.min.css" type = "text/css">
        <link rel="stylesheet" href="/static/css/main.css" type = "text/css">
        <link rel="stylesheet" href="/static/js/bootstrap.min.js" type = "text/js">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/fontawesome.min.css" integrity="sha384-jLKHWM3JRmfMU0A5x5AkjWkw/EYfGUAGagvnfryNV3F9VqM98XiIH7VBGVoxVSc7" crossorigin="anonymous">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Kids in the Canyon</title>
    </head>
    <body>
        <header class="kids">
          <!--Navbar Starts-->
                <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
                        <a class="navbar-brand size" href="/home/">KITC</a>
                        <h1 class="logo" href="/home/"></h1>
                        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                          <span class="navbar-toggler-icon"></span>
                        </button>
                        <div class="collapse navbar-collapse" id="navbarNav">
                          <ul class="navbar-nav">
                            <li class="nav-item active">
                              <a class="nav-link" href="/aboutMePage/">About KITC<span class="sr-only">(current)</span></a>
                            </li>
                            <li class="nav-item">
                              <a class="nav-link" href="/resourcePage/"> Reference Materials </a>
                            </li>
                            <li class="nav-item">
                              <a class="nav-link" href="/mentorPage/"> Meet the Mentors</a>
                            </li>
                            <li class="nav-item">
                                    <a class="nav-link" href="/specialthanks/"> Special Thanks</a>
                            </li>
                            <li class="nav-item">
                              <a class="nav-link" href="/contactusPage/">Contact Us</a>
                            </li>
                            <li class="nav-item">
                              <a class="nav-link" href="/donate/"> Donate </a>
                            </li>
                          </ul>
                        </div>
                      </nav>
        <!--Navbar Ends-->
        </header>
<!--Carousel Starts-->

<div class = "centerbody">
    <div class="liner">
    <!--Carousel Starts-->
    <div class = 'dive'></div>
    <div class = float_col>
      <div id="carouselExampleFade" class="carousel slide carousel-fade span" data-ride="carousel">
      <div class="carousel-inner carouselMargin1">
        <div class="carousel-item active">
          <img src="/static/images/CarouselPictures1/canyonphoto1.jpg/" class="d-block w-100 carouselImgs" alt="...">
        </div>
        <div class="carousel-item">
          <img src="/static/images/CarouselPictures1/canyonphoto2.jpg" class="d-block w-100 carouselImgs" alt="...">
        </div>
        <div class="carousel-item">
          <img src="/static/images/CarouselPictures1/canyonphoto3.jpg/" class="d-block w-100 carouselImgs" alt="...">
        </div>
      </div>
      <a class="carousel-control-prev" href="#carouselExampleFade" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="carousel-control-next" href="#carouselExampleFade" role="button" data-slide="next">
        <span class="carousel-control-next-icon next_button" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
      </div>
    </div>

   <div class="announcements">
      <h2>Announcements</h2>
      <div class="announcement-container">

          <p>No announcements at this time.</p>

      </div>
  </div>
   <!--Carousel Ends-->

  <!--This cell contains the table for the main content area-->
  <table cellpadding="0" cellspacing="0" width="700">
      <tbody>
        <tr>
          <td height="10" width="25">
            &nbsp;</td>
          <td height="160" width="126">
            <img height="120" src="https://3bac6cafdb-custmedia.vresp.com/library/1305142154/154bc2e38d/Templates/bwlogo2.gif" style="width: 110px; height: 120px;" width="110" /></td>
          <td height="10" width="36">
            &nbsp;</td>
          <td font="helvetica" height="110" width="513">
            <h1 style="color:whitesmoke ; font-family: Helvetica,sans-serif; font-size: 30px; margin-top: 50px; margin-bottom: 40px;">
              UPCOMING EVENTS <span style="color:wheat;">June &amp; BEYOND</span></h1>
            <img height="9" src="https://3bac6cafdb-custmedia.vresp.com/library/1305142180/83bdb2a586/Templates/top_bar.gif" style="width: 518px; height: 15px;" width="518" /></td>
        </tr>
        <tr>
          <td colspan="4" height="28" width="700">
            &nbsp;</td>
        </tr>
      </tbody>
    </table>
    <td class = "upcomingEvents" valign="top" width="700">
      <table cellpadding="0" cellspacing="0" width="700">

        <!--First Event-->
        <section>
          <div class = "events">

           <ul>
             <li>
               <div class = "time">

                 <h2> June 24<span> 9am</span></h2>
               </div>
               <div class = "details">
                 <!-- Event Title goes here-->
                 <h3>Saturday Hike @ Lincoln Woods</h3>
                 <!-- Event Content goes here-->
                  <p>
                      We are meeting at Lincoln Woods. This is the first Saturday hike after you have gotten your boots, DO NOT FORGET THEM! You want to break them in and make sure they feel comfortable. For anyone looking for a ride to Lincoln Woods Steven will be at Ella Risk at 8:45am.
                  </p>
                  <!-- Event Content goes here-->
                   <a href="/resourcePage/">View Details</a>
               </div>
               <div style="clear: both;"></div>
            </li>
           </ul>

           <ul>
             <li>
               <div class = "time">

                 <h2> Sep 12 2024<span> 9am</span></h2>
               </div>
               <div class = "details">
                 <!-- Event Title goes here-->
                 <h3>Hello @ Lin</h3>
                 <!-- Event Content goes here-->
                  <p>
                      dfgdfb bdfx
                  </p>
                  <!-- Event Content goes here-->
                   <a href="/resourcePage/">View Details</a>
               </div>
               <div style="clear: both;"></div>
            </li>
           </ul>

          </div>
        </section>
      </div>
    </div>



        <footer>copywrite 2019 MySite</footer>
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        <script src="static/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
        <script src="https://kit.fontawesome.com/5f01c6fdfb.js" crossorigin="anonymous"></script>
    </body>
</html>

As you can see the page is grabbing the UE object fields fine in the shell can someone help explain why this is not rendering the objects

HTML5 Canvas Resized (downscaled) JPEG Images have grain?

I want to downscale user input images (jpeg) using HTML5 Canvas / javascript before sending them to server. The goal is to limit image resolution to 1000×1000 pixels and possibly make a thumbnail. But the output images have too much grain / looks too sharp. Looking for a way to produce good quality images.

Below is the JS I was using to downscale images (textarea having base64 string):

function ResizePic(ReqWidth, ReqHeight, ReqQuality=0.9) {
    var tmpImg12    = document.createElement('img');
    tmpImg12.src    = document.getElementById('sometextarea').value;
    origWidth       = tmpImg12.width;
    origHeight      = tmpImg12.height;
    
    if (origWidth > origHeight)     ReqHeight   = ReqWidth * (origHeight / origWidth);
    if (origHeight > origWidth)     ReqWidth        = ReqHeight * (origWidth / origHeight);
    
    var tmpCanvas   = document.createElement('canvas');
    var tmpctx12    = tmpCanvas.getContext('2d');
    console.log('Image Smoothing: ', tmpctx12.imageSmoothingEnabled);
    console.log('Image Smoothing Quality: ', tmpctx12.imageSmoothingQuality);
    
    
    tmpCanvas.width = ReqWidth;
    tmpCanvas.height    = ReqHeight;
    tmpctx12.drawImage(tmpImg12, 0, 0, ReqWidth, ReqHeight);
    
    return tmpCanvas.toDataURL('image/jpeg', ReqQuality);
}

Tried hermite_resize JS by @ViliusL as shown in here . Image quality is much better but still grainy. Seek advice to further reduce grain and produce good quality output as I got absolutely no idea about image manipulation.

function resize_this()          {
    var rdFile  = new FileReader();
    var canvas  = document.getElementById('cc');
    var ctx     = canvas.getContext('2d');
    var img     = new Image();
    var tnW     = 400;
    var tnH     = 400;
    
    rdFile.readAsDataURL(document.getElementById('file1').files[0]);
    
    rdFile.onload = function(e1)        {
        var srcData = e1.target.result;
        img.src = srcData;
    }
    
    img.onload  = function()    {
        var W = img.width;
        var H = img.height;
        
        if (W > H)      tnH = Math.round(tnW * (H / W));
        if (H > W)      tnW = Math.round(tnH * (W / H));
        
        canvas.width = W;
        canvas.height= H;
        ctx.drawImage(img, 0, 0);
        var time1 = Date.now();     
        document.getElementById('our_image').src=resample_single(canvas, tnW, tnH, true);
        document.getElementById('timer').innerHTML = Math.round(Date.now() - time1)/1000;
    }
}
function hermite_resize()       {
var canvas = document.getElementById("cc");
var ctx = canvas.getContext("2d");

var img = new Image();
img.crossOrigin = "Anonymous"; //cors support
img.onload = function(){
    var W = img.width;
    var H = img.height;
    canvas.width = W;
    canvas.height = H;
    ctx.drawImage(img, 0, 0); //draw image
    var time1 = Date.now();
    
    //resize
    document.getElementById('hermite_img').src=resample_single(canvas, 439, 222, true);
    
    document.getElementById('timer').innerHTML = Math.round(Date.now() - time1)/1000;
}
img.src = 'https://i.imgur.com/8VsK7gS.png';
}
/**
 * Hermite resize - fast image resize/resample using Hermite filter. 1 cpu version!
 * 
 * @param {HtmlElement} canvas
 * @param {int} width
 * @param {int} height
 * @param {boolean} resize_canvas if true, canvas will be resized. Optional.
 */
function resample_single(canvas, width, height, resize_canvas,ReqQuality=0.95) {
  var width_source = canvas.width;
  var height_source = canvas.height;
  width = Math.round(width);
  height = Math.round(height);

  var ratio_w = width_source / width;
  var ratio_h = height_source / height;
  var ratio_w_half = Math.ceil(ratio_w / 2);
  var ratio_h_half = Math.ceil(ratio_h / 2);

  var ctx = canvas.getContext("2d");
  var img = ctx.getImageData(0, 0, width_source, height_source);
  var img2 = ctx.createImageData(width, height);
  var data = img.data;
  var data2 = img2.data;

  for (var j = 0; j < height; j++) {
    for (var i = 0; i < width; i++) {
      var x2 = (i + j * width) * 4;
      var weight = 0;
      var weights = 0;
      var weights_alpha = 0;
      var gx_r = 0;
      var gx_g = 0;
      var gx_b = 0;
      var gx_a = 0;
      var center_y = (j + 0.5) * ratio_h;
      var yy_start = Math.floor(j * ratio_h);
      var yy_stop = Math.ceil((j + 1) * ratio_h);
      for (var yy = yy_start; yy < yy_stop; yy++) {
        var dy = Math.abs(center_y - (yy + 0.5)) / ratio_h_half;
        var center_x = (i + 0.5) * ratio_w;
        var w0 = dy * dy; //pre-calc part of w
        var xx_start = Math.floor(i * ratio_w);
        var xx_stop = Math.ceil((i + 1) * ratio_w);
        for (var xx = xx_start; xx < xx_stop; xx++) {
          var dx = Math.abs(center_x - (xx + 0.5)) / ratio_w_half;
          var w = Math.sqrt(w0 + dx * dx);
          if (w >= 1) {
            //pixel too far
            continue;
          }
          //hermite filter
          weight = 2 * w * w * w - 3 * w * w + 1;
          var pos_x = 4 * (xx + yy * width_source);
          //alpha
          gx_a += weight * data[pos_x + 3];
          weights_alpha += weight;
          //colors
          if (data[pos_x + 3] < 255)
            weight = weight * data[pos_x + 3] / 250;
          gx_r += weight * data[pos_x];
          gx_g += weight * data[pos_x + 1];
          gx_b += weight * data[pos_x + 2];
          weights += weight;
        }
      }
      data2[x2] = gx_r / weights;
      data2[x2 + 1] = gx_g / weights;
      data2[x2 + 2] = gx_b / weights;
      data2[x2 + 3] = gx_a / weights_alpha;
    }
  }
  //clear and resize canvas
  if (resize_canvas === true) {
    canvas.width = width;
    canvas.height = height;
  } else {
    ctx.clearRect(0, 0, width_source, height_source);
  }

  //draw
  ctx.putImageData(img2, 0, 0);
  return canvas.toDataURL('image/jpeg', ReqQuality);
}
    .section    {
        display:inline-block;
        position:relative;
        width:40%;
        padding:12px;
        border:1px solid lightgray;
        box-sizing:border-box;
        vertical-align:top;
    }
    canvas  {
    border:1px solid grey;
     display:none;
    }
    #timer{
  font-weight:bold;
}
<div class='section'>
    <a href="https://i.imgur.com/8VsK7gS.png">Original image</a>
    <button onclick='hermite_resize()'>Hermite Resize</button>
    <canvas id="cc"></canvas>
    <br />
    <img id='hermite_img' src=''>
</div>
<div class='section'>
    <input type='file' id='file1' onchange='resize_this()'><br>
    <img id='our_image' src=''>
</div>
<p>
    Resized in: <span id="timer">-</span> s
</p>

Is it possible to change the host for a localhost server?

Lets say I want to have a friend run my project that runs web sockets and a few other local servers on my network so me and my other friends can test my project. If the friend who hosted the web sockets had to leave, he would have to close the web sockets, and that would throw things off.

I have a few other servers running that each client is hosting separately (Vite and Express, but they don’t have any part in this), and the web pages in each server are connecting to the web sockets from that one host. So as you can see, the host disconnecting is an issue. My other servers run off of those web sockets.

Am I able to have multiple hosts (where the next host takes care of all the requests and socket messages if the current host is gone), or have something transfer the hosting to the next person (The person who connected after the host before disconnection)?

Django Choice Dropdown Not Working on Cloned Form in Formset

I am cloning my an empty form in django following guidance I’ve found elsewhere in stack overflow. The JS will append a new form as intendended however the dropdowns from a choice widget are no longer working and I can’t figure out why.

I have already validated that all of my options are there using my browser’s inspect feature. It appears to be that the javascript isn’t working with the object.

This is from the template:


<form method="post"> {% csrf_token %}
  <div id="form_set">
  {{ FightForms.management_form|materializecss }}
  {% for form in FightForms %}
  <div class="card white darken-1 col m12">
    <table class='no_error'>
      {{ form.non_field_errors }}
      <row>
          <div class="col m3">
              <div class="fieldWrapper">
                  {{ form.guild_member_id|materializecss }}
              </div>
          </div>

    
      </row>
      {% for hidden in form.hidden_fields %}
          {{ hidden }}
      {% endfor %}
  </table>
  </div>
  {% endfor %}
</div>

  <div class="col m12">
    <div>
        <input class="btn light-blue lighten-1" type="button" value="Add More" id="add_more">
    </div>
    <br>
    <button class="btn light-blue lighten-1" type="submit">Submit Guild Members</button>
  </div>

  <div id="empty_form" style="display:none">
    <div class="card white darken-1 col m12">
      <table class='no_error'>
        {{ FightForms.empty_form.non_field_errors }}
        <row>
            <div class="col m3">
                <div class="fieldWrapper">
                    {{ FightForms.empty_form.guild_member_id|materializecss }}
                </div>
            </div>
            
        </row>
        {% for hidden in form.hidden_fields %}
            {{ hidden|materializecss }}
        {% endfor %}
      </table>
    </div>
  </div>
</form>


<script>
  $('#add_more').click(function() {
      var form_idx = $('#id_form-TOTAL_FORMS').val();
      $('#form_set').append($('#empty_form').html().replace(/__prefix__/g, form_idx));
      $('#id_form-TOTAL_FORMS').val(parseInt(form_idx) + 1);
  });
</script>

Here are my header imports if it’s an issue with versioning or something…

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
    <title>League Chronicler</title>
    <link rel="shortcut icon" type="image/png" href="{% static 'img/CScroll.png' %}"/>

    <!-- CSS  -->
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="{% static 'css/chronicler.css' %}" type="text/css" media="screen,projection"/>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">


    {% block css %}
      <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
      <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    {% endblock css %}

    <!-- javascript -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

</head>

Remove the shorts tab for a youtube channel

I’ve decided to make a post because I’ve run out of ideas on a problem.

I am developing a chrome extension to remove shorts from youtube. This includes shorts sections, shorts recommender, etc.

The way the extension works is by injecting javascript code into the page like a classic extension.

I’ve made good progress in removing most of the parts with shorts, however, when I tried to remove the shorts tab in the youtube channels, I encountered a lot of problems.

1 – I first tried to take the position of the shorts button to remove it (3rd position in most cases).

  • however, a youtube channel may or may not have the shorts tab, depending on whether it has shorts or not, and may also have no videos, which removes the tab for videos and advances the shorts tab.

2 – I tried to use the section name (Shorts)

  • Except that this is impossible because youtube is available in many languages, and the name changes completely depending on the language. This would mean translating the text, which would be too slow.

3 – I’ve tried using YouTube’s api to find out whether the channel has shorts or not and use the position accordingly.

  • The problem is that there’s no difference between short videos and normal videos in the YouTube api.
"statistics": {
    "viewCount": ,
    "subscriberCount": ,
    "hiddenSubscriberCount": ,
    "videoCount":
  },

4 – I then tried to use the url to which the buttons pointed, but it’s not easy because it’s not a simple href but a redirection by the server. I didn’t succeed and it seems too slow and to heavyy.

Basically, I’d like to remove the shorts tab from youtube channels quickly and cleanly.

Thank you in advance

CSS displays wrong on iphoneX

I’m working on a portfolio project and I’m running into errors I don’t understand.

I just completed the responsive design for 480px and 768px screens. Here is the link to the site: https://tranthanhhthao.github.io/swinburne-contact/

Using the computer Chrome browser everything looks right 1. But when I use my iPhone X to view the web 2, the content of the second and third pages are pushed to the top.

Below are the screenshots.

on computer Chrome browser

on my iPhone X

Can someone please help me out… And guide me to fix this…

e.apply is not a function… how do I fix this error?

I’m learning JavaScript with KhanAcademy and I just got “e.apply is not a function” and it does not elaborate on how to fix it or anything. I’m so frustrated right now. I don’t know where else to ask this, so here I am. I can pinpoint the exact location of where the error is coming from as well. it’s the line var newTulip = new Tulip (36, 390, 100);. For some reason the code works until I add another tulip into the picture… which is literally part of the requirements to move onto the next step.

/*************
*OBJECT TYPES
**************/
/******************
*Flower Object Type
*******************/


/*****************
*Tulip Object Type
******************/

var Tulip = function(x, y, height) {
    this.x = x;
    this.y = y;
    this.height = height;
};

Tulip.prototype.draw = function() {
    noStroke();
    fill(16, 122, 12);
    rect(this.x, this.y, 10, -this.height);
    fill(255, 0, 0);
    // petals
    ellipse(this.x+5, this.y-this.height, 44, 44);
    triangle(this.x-16, this.y-this.height, 
            this.x+20, this.y-this.height,
            this.x-20, this.y-this.height-31);
    triangle(this.x-14, this.y-this.height, 
            this.x+24, this.y-this.height,
            this.x+3, this.y-this.height-39);
    triangle(this.x+-4, this.y-this.height, 
            this.x+26, this.y-this.height,
            this.x+29, this.y-this.height-36);
};

Tulip.prototype.growBy = function(amount) {
    this.height += amount;
};

/*********************
*Sunflower Object Type
**********************/
var Sunflower = function(x, y, height) {
    this.x = x;
    this.y = y;
    this.height = height;
};

Sunflower.prototype.draw = function() {
    fill(16, 122, 12);
    
    rect(this.x, this.y, 10, -this.height);
    
    // petals
    stroke(0, 0, 0);
    fill(255, 221, 0);
    ellipse(this.x-10, this.y-this.height, 20, 18);
    ellipse(this.x+5, this.y-this.height-15, 20, 18);
    ellipse(this.x+5, this.y-this.height+15, 20, 18);
    ellipse(this.x+20, this.y-this.height, 20, 18);
    fill(20, 20, 20);
    ellipse(this.x+5, this.y-this.height, 20, 20);
};

Sunflower.prototype.growBy = function(amount) {
    this.height += amount;
};

/**************
*MAIN PROGRAM
***************/

/** create object instances **/
var Tulip = new Tulip (38, 390, 150);
var newTulip = new Tulip (36, 390, 100);
var sunflower = new Sunflower(186, 390, 100);
var sunFlower = new Sunflower (263, 390, 114);


var drawScene = function() {
    background(207, 250, 255);
    Tulip.draw();
    newTulip.draw();
    sunflower.draw();
    sunFlower.draw();
};

mouseClicked = function() {
    Tulip.growBy(10);
    sunflower.growBy(20);
    drawScene();
};

drawScene();

I tried looking it up on google and turns out all kinds of different things can cause that error message to pop up… and none of them really fit my situation. I’m completely stuck here.