Saving a PDF Document generated in js.PDF to a Django Project Directory

I currently create a PDF in Django using js.PDF that gets download to wherever the web browser directs it to on my local computer. I would like to instead have it saved in a directory in my Django project that is hosted in Pythonanywhere.(i.e. /home/abraner/ABS/absdatabase/pdfs) Below is my current JavaScript code.

Any suggestions would be appreciated.


async function generatePDF(){
    document.getElementById("downloadButton").innerHTML = "Currently downloading, please wait";
        var downloading = document.getElementById("whatToPrint");
        var doc = new jsPDF('1', 'pt');
            await html2canvas(downloading, {
            allowTaint: true,
            useCORS: true,
            width: 798
            }).then((canvas) => {
            doc.addImage(canvas.toDataURL("image/png"), 'PNG', 5, 5, 585, 800);
            })
            doc.save("Document.pdf");
    window.location.replace('../emailproposal');
}

Puppeteer-shart error : Javascript is disabled

When launching a new page with puppeteer-sharp:

var page = await browser.NewPageAsync();
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36");
headers.Add("upgrade-insecure-requests", "1");
headers.Add("accept", "text/html,application/xhtml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
headers.Add("accept-encoding", "gzip, deflate, br");
headers.Add("accept-language", "en-US,en;q=0.9,en;q=0.8");
await page.SetExtraHttpHeadersAsync(headers);
await page.GoToAsync(fullUrl);

It throws error:

Javascript is disabled or blocked by an extension (ad blockers for example)
Your browser does not support cookies
Please make sure that Javascript and cookies are enabled on your browser and that you are not blocking them from loading.

Could not locate any reference to enable JavaScript/Cookies on it’s site.
Any idea how to handle the situation?

How to store states in React JS using useReducer?

I have a component ( let’s call it a grandparent component ) , by default it has an input box , ( > ) arrow and an add button , whenever I click on Add button , a new input box will get generated.Now let’s come to main part whenever I click on ( > ) button a new component should open up and in that also a default input box,(> will be present with a same add button , if I add something in it and click on (>) button a new component should open up and same an input box , (>) icon and add button

So now the thing is , its forming a tree structure:

const finalStructure = {
    "category": {
      "agriculture" : ["5 hectares" , "10 hectates" , "15 hectares"],
      "automobile" : ["bus" , "car" , "truck"],
      "farming": ["wheat" , "rice" , "maida"]
    }, 
    "product": {
      "face": "white-toned",
      "skin": "healthy"
    }
  };

See carefully here “category ” is the first value I enter in grandparent component and [ “agricluture ” , “automobile” , “automotive” ] are the three options I enter in parent component and then the correspondin values to agriculture is what I entered in child component.

Now the question is:
How do I maintain a relation between these 3 components [ grandparent , parent and child ]
Till now I tried to use stated and assign empty objects to input value but the thing how to store the values so that if I refer that in future , the values remain retained.

How to insert spans around every word where existing spans exist within each word

Given an HTML element tangled with miscellaneous internal spans, can I insert/wrap spans around each individual word, even though existing spans ‘disturb’ a search using innerHTML; only a search of innerText will reveal the matches.

   // eg:    
<span id="parent">
  <span id="oldSpan1">Hardware:</span> <br> 
  the 
  <span id="child1">kicka</span>ble, 
  <span id="child2">throwa</span>ble, 
  <span id="child3">puncha</span>ble 
  components 
  of 
  a 
  <span  id="oldSpan2">computer</span>!
</span>

   // I want the result to be:
<span id="parent">
  <span id="word1"><span id="oldSpan1">Hardware:</span></span> <br> 
  <span id="word2">the</span> 
  <span id="word3"><span id="child1">kicka</span>ble</span>, 
  <span id="word4"><span id="child2">throwa</span>ble</span>, 
  <span id="word5"><span id="child3">puncha</span>ble</span> 
  <span id="word6">components</span> 
  <span id="word7">of</span> 
  <span id="word8">a</span> 
  <span id="word9"><span id="oldSpan2">computer</span></span>!
</span>    

(Please note that my actual task involves a string of non-Latin characters, so using a better regex to identify word boundaries will not help)

The only algorithm I could think of is very complicated involving manipulating the HTML String based on parsing the innerText with a regex (unrecommended by the Pundits) and I suspect there is a much more professional way using text nodes.

function createWordSpans ( parent ){
  const wordBoundary_rx = /b/g
  const tagSplitter_rx. = /(<.*?>|[^<]+)s*/g
  const textString = parent.innerText
  const textArray  = textString.match( wordBoundary_rx )
  let hTMLString   = parent.innerHTML
  const hTMLArray  = hTMLString.match( tagSplitter_rx )
  for ( const word of textArray ){
    
  }
}
#child1 {
  color: green;
}

#child2 {
  color: orange;
}

#child3 {
  color: red;
}
    <span id="parent">
      <span id="oldSpan1">Hardware:</span> <br> 
      the 
      <span id="child1">kicka</span>ble, 
      <span id="child2">throwa</span>ble, 
      <span id="child3">puncha</span>ble 
      components 
      of 
      a 
      <span  id="oldSpan2">computer</span>!
    </span>

Rails 7 using custom js in specific pages

Having adapted the hotwire mechanism for rails 7, problems arise for custom JS that are dependency-less. in this case, a JS that is not mapped to a given source.

Added to importmap.rb:

pin_all_from "app/javascript/plugin", under: "plugin"

which does render

    <script type="importmap" data-turbo-track="reload">{
  "imports": {
    "application": "/assets/application-37f365cbecf1fa2810a8303f4b6571676fa1f9c56c248528bc14ddb857531b95.js",
    "@hotwired/turbo-rails": "/assets/turbo.min-e5023178542f05fc063cd1dc5865457259cc01f3fba76a28454060d33de6f429.js",
    "@hotwired/stimulus": "/assets/stimulus.min-900648768bd96f3faeba359cf33c1bd01ca424ca4d2d05f36a5d8345112ae93c.js",
    "@hotwired/stimulus-loading": "/assets/stimulus-loading-1fc59770fb1654500044afd3f5f6d7d00800e5be36746d55b94a2963a7a228aa.js",
    "controllers/application": "/assets/controllers/application-368d98631bccbf2349e0d4f8269afb3fe9625118341966de054759d96ea86c7e.js",
    "controllers/hello_controller": "/assets/controllers/hello_controller-549135e8e7c683a538c3d6d517339ba470fcfb79d62f738a0a089ba41851a554.js",
    "controllers": "/assets/controllers/index-2db729dddcc5b979110e98de4b6720f83f91a123172e87281d5a58410fc43806.js",
    "plugin/auto-complete": "/assets/plugin/auto-complete-813c8033519c4886434d3f867f4159971e0d46aca097d6706580f5042f78d4ec.js"
  }

Also note that I made the mistake of running ./bin/rails javascript:install:esbuild
which leads to unnecessary pollution of the header and do not know how to un-do this (indictions not provided with the gem)

<script type="esms-options">{"nonce":null}</script>
<script src="/assets/es-module-shims.min-b8099fffdbd758070d4801321d43b389c5b6174a50782f9f4cb57061533b7ac2.js" async="async" data-turbo-track="reload"></script>

could this be a factor in impeding the eventual loading of the script?

Apparently, a declaration is required to have it load: <%= javascript_import_module_tag "plugin" %>. While the preference is to load it on the action that requires it, this was added to the application.html.erb file.

To no avail.
The script runs only if the raw script is included in the action’s view.

Is there a more succinct manner to load such a script as necessary?

JS ругается на консту

Как вы могли понять, JS ругается на константу. Делаю бота для сервера в Дискорде.

const config = require("./config.json");
const client = new Discord.Client("GUILDS");

client.login(config.BOT_TOKEN);
var prefix = "!";

client.on("message", function(message){
    if (message.author.bot) return;
    if (!message.content.startWith(prefix)) return;

    const commandBody = message.content.slice(prefix.length);
    const args = commandBody.split(' ');
    const command = args.shift().toLowerCase();

    if (command === "ping"){
        const timeTaken = Date.now() - message.createdTimestamp;
        message.reply(`Понг! Задержка бота: ${timeTaken} милисекунд.`)
    }
})

WebSocket deployed on AKS fails to connect

We have created a websocket server using golang and was tested locally and on docker. We have deployed the server on Azure Kubernetes Services and since then it refuses to create a connection. We are using Azure Free Subscription. Here is what we have done.

Deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: overseerservice-deployment
  labels:
    app: dexam-overseer
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dexam-overseer
  template:
    metadata:
      labels:
        app: dexam-overseer
    spec:
      containers:
        - name: dexam-overseer
          image: eyadzz/dexam_overseer_service:latest
          ports:
            - containerPort: 9999
          env:
            - name: RABBITMQ_HOST
              value: rabbitmq-service
            - name: RABBITMQ_PORT
              value: :5672

---

apiVersion: v1
kind: Service
metadata:
  name: overseer-service
spec:
  selector:
    app: dexam-overseer
  type: LoadBalancer
  ports:
    - port: 9999
      protocol: TCP
      targetPort: 9999
      nodePort: 30008

Js connection code:

let socket = new WebSocket("ws://20.106.105.25:9999/ws");
    console.log("Attempting Connection...");

    socket.onopen = () => {
        console.log("Successfully Connected");
        socket.send(("1").toString())

    };


    socket.onclose = event => {
        console.log("Socket Closed Connection: ", event);
        socket.send("Client Closed!")
    };

    socket.onerror = error => {
        console.log("Socket Error: ", error);
    };

Error message:

enter image description here

How to configure React package.json file to use different .env files for different builds with dotenv

I am using dotenv with create-react-app. I have three different .env files in my root directory.
I have
.env
.env.develop
.env.stage

I want the variables in these file to map as described below

.env                   -> production site

.env.develop           -> local development

.env.stage             -> stage site

I am guessing that I have to make some changes to the scripts object in the package.json file but I am not sure of what to exactly do.

My current package.json is as follows

{
  "name": "web_app",
  "version": "0.1.0",
  "private": true,
  "homepage": "",
  "devDependencies": {... },
  "dependencies": {... },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

So I would like to know how to tell react to use the correct .env file for each environment.

Thanks in advance to anyone who can help

Calling array object inside function not working in Svelte

I have an array :

let x = '';
let elements = [
            { icon:"Home",name:'Home',page:'Page1' },
            { icon:'Cube',name:'New',page:'Page2' }];

I am looping in it:

{#each elements as { icon, name, page }, i}
                        
                        <a on:click={() => { x = {page} }}
                            class="w-full flex items-center pl-6 p-2 my-2 transition-colors duration-200 justify-start border-l-4 
                                " href="#" >{/each}

This function here does not work: on:click={() => { rightPage = {page} }}

If I replace the {page} with string it works! Can someone tell me why?
Thank you

i want to replace the text with quotes in a string with a special character and push the values in to array replaced in to a array

input : note_description = 'test @8:57am', patient_id = '009876', note_updated_by = '1009876549087', note_update_date = '2022-07-13 09:45:49' where note_id = '639'

output1 : note_description = ?, patient_id = ?, note_updated_by = ? , note_update_date = ? where note_id = ?

output2 : ['test @8:57am' , '009876' ,'1009876549087' , '2022-07-13 09:45:49' , '639' ]

i want to replace the text with quotes in a string with a special character and push the values in to array replaced in to a array

(JS) Is there a better function that I can use instead of onclick?

I want to make a selection tree and I’m currently using a function (OnClick) Is there a better way to get the result I want with less JS functions? The goal is to have the A B buttons open the ABC and A1B1C1 buttons and the following buttons open the forms, but when I click the A B buttons again, everything at the bottom disappears and only what I need is opened. I attach my code. I what I did wrong so after first click nothing happens?

  function stage1() {
    var x = document.getElementById("first-class");
    var y = document.getElementById("second-class");
    var z = document.getElementById("all-forms");
    if (x.style.display === "none") {
      x.style.display = "block";
      y.style.display = "none";
      z.style.display = "none";
    } else {
      x.style.display = "none";
      y.style.display = "none";
      z.style.display = "none";
    }
  }
  function stage2() {
    var x = document.getElementById("second-class");
    var y = document.getElementById("first-class");
    var z = document.getElementById("all-forms");
    if (x.style.display === "none") {
      x.style.display = "block";
      y.style.display = "none";
      z.style.display = "none";
    } else {
      x.style.display = "none";
      y.style.display = "none";
      z.style.display = "none";
    }
  }
  function forma1() {
    var x = document.getElementById("forma1");
    var z = document.getElementById("forma2");
    var c = document.getElementById("forma3");
    var v = document.getElementById("forma4");
    var b = document.getElementById("forma5");
    var n = document.getElementById("forma6");
    var m = document.getElementById("all-forms");
    if (x.style.display === "none") {
      x.style.display = "block";
      z.style.display = "none";
      c.style.display = "none";
      v.style.display = "none";
      b.style.display = "none";
      n.style.display = "none";
      m.style.display = "block";
    } else {
      x.style.display = "none";
      z.style.display = "none";
      c.style.display = "none";
      v.style.display = "none";
      b.style.display = "none";
      n.style.display = "none";
      m.style.display = "none";
    }
  }
  function forma2() {
    var x = document.getElementById("forma1");
    var z = document.getElementById("forma2");
    var c = document.getElementById("forma3");
    var v = document.getElementById("forma4");
    var b = document.getElementById("forma5");
    var n = document.getElementById("forma6");
    var m = document.getElementById("all-forms");
    if (z.style.display === "none") {
      x.style.display = "none";
      z.style.display = "block";
      c.style.display = "none";
      v.style.display = "none";
      b.style.display = "none";
      n.style.display = "none";
      m.style.display = "block";
    } else {
      x.style.display = "none";
      z.style.display = "none";
      c.style.display = "none";
      v.style.display = "none";
      b.style.display = "none";
      n.style.display = "none";
      m.style.display = "none";
    }
  }
  function forma3() {
    var x = document.getElementById("forma1");
    var z = document.getElementById("forma2");
    var c = document.getElementById("forma3");
    var v = document.getElementById("forma4");
    var b = document.getElementById("forma5");
    var n = document.getElementById("forma6");
    var m = document.getElementById("all-forms");
    if (c.style.display === "none") {
      x.style.display = "none";
      z.style.display = "none";
      c.style.display = "block";
      v.style.display = "none";
      b.style.display = "none";
      n.style.display = "none";
      m.style.display = "block";
    } else {
      x.style.display = "none";
      z.style.display = "none";
      c.style.display = "none";
      v.style.display = "none";
      b.style.display = "none";
      n.style.display = "none";
      m.style.display = "none";
    }
  }
  function forma4() {
    var x = document.getElementById("forma1");
    var z = document.getElementById("forma2");
    var c = document.getElementById("forma3");
    var v = document.getElementById("forma4");
    var b = document.getElementById("forma5");
    var n = document.getElementById("forma6");
    var m = document.getElementById("all-forms");
    if (v.style.display === "none") {
      x.style.display = "none";
      z.style.display = "none";
      c.style.display = "none";
      v.style.display = "block";
      b.style.display = "none";
      n.style.display = "none";
      m.style.display = "block";
    } else {
      x.style.display = "none";
      z.style.display = "none";
      c.style.display = "none";
      v.style.display = "none";
      b.style.display = "none";
      n.style.display = "none";
      m.style.display = "none";
    }
  }
  function forma5() {
    var x = document.getElementById("forma1");
    var z = document.getElementById("forma2");
    var c = document.getElementById("forma3");
    var v = document.getElementById("forma4");
    var b = document.getElementById("forma5");
    var n = document.getElementById("forma6");
    var m = document.getElementById("all-forms");
    if (b.style.display === "none") {
      x.style.display = "none";
      z.style.display = "none";
      c.style.display = "none";
      v.style.display = "none";
      b.style.display = "block";
      n.style.display = "none";
      m.style.display = "block";
    } else {
      x.style.display = "none";
      z.style.display = "none";
      c.style.display = "none";
      v.style.display = "none";
      b.style.display = "none";
      n.style.display = "none";
      m.style.display = "none";
    }
  }
  function forma6() {
    var x = document.getElementById("forma1");
    var z = document.getElementById("forma2");
    var c = document.getElementById("forma3");
    var v = document.getElementById("forma4");
    var b = document.getElementById("forma5");
    var n = document.getElementById("forma6");
    var m = document.getElementById("all-forms");
    if (n.style.display === "none") {
      x.style.display = "none";
      z.style.display = "none";
      c.style.display = "none";
      v.style.display = "none";
      b.style.display = "none";
      n.style.display = "block";
      m.style.display = "block";
    } else {
      x.style.display = "none";
      z.style.display = "none";
      c.style.display = "none";
      v.style.display = "none";
      b.style.display = "none";
      n.style.display = "none";
      m.style.display = "none";
    }
  }
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  body {
    font-family: sans-serif;
  }
  h1 {
    font-size: 25px;
  }
  .tree-box{
    width: 600px;
    height: fit-content;
    text-align: center;
    border: 1px solid #1B57A6;
  
  }
  #first-class, #second-class
  {
    margin-top: 50px;
    border-top: 1px solid #1B57A6;
    border-bottom: 1px solid #1B57A6; 
    padding: 10px 0px;
  }
  
  .btnas{
    font-family: "Open Sans", Sans-serif;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.2px;
    background-color: #1B57A6;
    border-color: #1B57A6;
    border-radius: 30px 30px 30px 30px;
    padding: 18px 26px 18px 26px;
    color: white;
  }
  .btnas-katilas{
    font-family: "Open Sans", Sans-serif;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.2px;
    background-color: white;
    border-color: #1B57A6;
    border-radius: 30px 30px 30px 30px;
    padding: 18px 26px 18px 26px;
    color: #1B57A6;
  }
  .btnas:hover, .btnas:focus, .btnas-katilas:hover, .btnas-katilas:focus, .active {
    box-shadow: rgb(38, 57, 77) 0px 15px 30px -10px;
  }
  .tree-form{
    padding-top: 20px;
  }
  #first-class {
  display: none;
  }
  #second-class{
    display: none;
    }
    #forma1, #forma2, #forma3, #forma4, #forma5, #forma6 {
      display: none;
        }
<!DOCTYPE html>
<html lang="en">
  <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="stylesheet" href="styles.css" />
    <title>responsive navbar</title>
  </head>
  <body>
    <div id="tree-box">
      <div class="tree-box">
        <div>
          <h1>Į kokią šildymo sistemą norite atsinaujinti?</h1>
          <button class="btnas-katilas" onclick="stage1()">Dujinis katilas</button>
          <button class="btnas" onclick="stage2()">Šilumos siurblys</button>
      </div>
        <div id="first-class">
          <h1>Pasirinkite šildomą plotą kv.m</h1>
          <button class="btnas" onclick="forma1()">50-140 m2</button>
          <button class="btnas" onclick="forma2()">140-200 m2</button>
          <button class="btnas" onclick="forma3()">200-300+ m2</button>
        </div>
        <div id="second-class">
          <h1>Pasirinkite šildomą plotą kv.m</h1>
          <button class="btnas" onclick="forma4()">50-140 m2asa</button>
          <button class="btnas" onclick="forma5()">140-200 m2as</button>
          <button class="btnas" onclick="forma6()">200-300+ m2as</button>
        </div>
        <div>
          <div class="tree-form" id="all-forms">
            <div id="forma1">
              <h1>forma1</h1>
              <form>
                <label for="labas">labas</label>
                <input>
                <label for="labas">Krabas</label>
                <input>
              </form>
            </div>
            <div id="forma2">
              <h1>forma 2</h1>
              <form>
                <label for="labas">labas</label>
                <input>
                <label for="labas">Krabas</label>
                <input>
              </form>
            </div>
              <div id="forma3">
              <h1>forma 3</h1>
              <form>
                <label for="labas">labas</label>
                <input>
                <label for="labas">Krabas</label>
                <input>
              </form>
            </div>
              <div id="forma4">
              <h1>forma 4</h1>
              <form>
                <label for="labas">labas</label>
                <input>
                <label for="labas">Krabas</label>
                <input>
              </form>
            </div>
              <div id="forma5">
              <h1>forma 5</h1>
              <form>
                <label for="labas">labas</label>
                <input>
                <label for="labas">Krabas</label>
                <input>
              </form>
            </div>
              <div id="forma6">
              <h1>forma 6</h1>
              <form>
                <label for="labas">labas</label>
                <input>
                <label for="labas">Krabas</label>
                <input>
              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </body>

  <script src="script.js"></script>
</html>

Weird Promise behavior in Jest when tests rely on the Firestore emulator

While using the Google Cloud’s Firestore Emulator, I’m calling the following method:

db.runTransaction(async () => 100)

This dummy call works when executed using node, but fails when executed using jest inside a test function. When running it from Jest, the runTransaction method throws:

Error: You must return a Promise in your transaction()-callback.

referencing node_modules/@google-cloud/firestore/build/src/transaction.js:362:27

That file has the following snippet of code, which is causing the failure:

async runTransaction(updateFunction, options) {
  // ...
  const promise = updateFunction(this);
  if (!(promise instanceof Promise)) {
    throw new Error('You must return a Promise in your transaction()-callback.');
  }
  // ...
}

In other words, when running in Jest, the library considers async () => 100 function not to return a promise.

I changed the library code to add some debug messages:

async runTransaction(updateFunction, options) {
  // ...
  const promise = updateFunction(this);
  if (!(promise instanceof Promise)) {
    // *** Added these debug messages ***
    console.log(updateFunction);
    console.log(promise);
    console.log(promise instanceof Promise);

    throw new Error('You must return a Promise in your transaction()-callback.');
  }
  // ...
}

And getting the following:

[AsyncFunction (anonymous)]
Promise { 100 }
false

I’m a bit at a loss here as to why Jest would cause such behavior. This test passes as expected within jest:

test('promise', () => {
  const fn = async () => 100;
  const res = fn();
  expect(res instanceof Promise).toEqual(true);
}

Any suggestions on how to approach this head-scratcher?

How to catch the element inside the template in Angularjs?

I have component in Angularjs:

angular.module('myApp', [])
.component('foo', {
  template: 'in foo! <div ng-ref="bar">im bar!!</div>',
  controller: function FooController() {
   console.log({ bar: this.bar });
  }
});

And I want to get the dom element of the div in foo component. just like elementRef do in Angular.

I try to use ng-ref but bar is undefined. maybe I use it wrong but I not sure. I also don’t want to use querySelecor or document.getById, just by angularjs way.

plnkr

How to save the HTML form data to a .txt file on server [duplicate]

I want to save the HTML form data to a .txt file on the server.
I tried to use HTML+PHP, but nothing happened.


Code part:
HTML:


<form action="?survey.php" method="post">
    Your E-mail address: <input type="text" id="emails" placeholder="Enter your E-mail address" required email-address><br />
    <input type="submit" value="提交">
</form>

PHP:

<?php
$file_emails = "emails.txt";
$line = 0;
$fp = fopen($file_emails , 'r') or die("open file failure!");
if($fp)
{
    while(stream_get_line($fp,8192,"n"))
    {
        $line++;
    }
    fclose($fp);
}
$line++;
$string_emails = "Respondent "+$line+":"+$_POST["emails"]+"rn";
file_put_contents($file_emails,$string_emails);
?>  

A-Frame AR: Is there a way to place the 3D Object directly on top of the marker once detected?

I’m working on a project for an exhibition and I’m trying to use the AR experience on top of some paintings.

I tried to use a-image and a-nft but I have a lot of issues on place the AR object exactly on top of the illustration. Not sure if it’s actually feasible but it would be great to have it at least that is more or less on top.

Is there any snippet with JS that can help to achieve this?

Thank you so much in advance