Replacing arrays with some modifications

I have a array as shown below:

[
{
  "id":1,
  "data":  {1: 1, 2: 0, 4: 0}
  
},
{
  "id":2,
  "data": {1: 1, 2: 0, 4: 0}
}
]

I have another array as follows:

{
  "id":1,
  "measurementID": 55163,
  "realData": [
                                    {
                                        "secondaryId": 7,
                                        "measurementID": 55163,
                                        "realDataId": 1,
                                        "active": 1
                                    },
                                    {
                                        "secondaryId": 8,
                                        "measurementID": 55163,
                                        "realDataId": 2,
                                        "active": 0
                                    }
                                ]
  
},
{
  "id":2,
  "measurementID": 55163,
  "realData": [
                 {
                    "secondaryId": 7,
                    "measurementID": 55163,
                    "realDataId": 1,
                    "active": 1
                 },
                 {
                    "secondaryId": 8,
                    "measurementID": 55163,
                    "realDataId": 2,
                    "active": 0
                 }
                                   
           ]
}
]

In this second array I have a array with name realData. I want to have this realData array in first array instead of data object. Movement will done on the basis of id. Element with a particular id will always be there in both array. I want to remove this data object from first array and move this realData array to first array with some modifications. Data object has folllowing format:

"data":  {1: 1, 2: 1, 4: 0}

Left hand side is values matches with realDataId of realData array of second array. If this id matches then need to change value of active in readData array for that particular element with right hand side value of data object. For example, in realData array with realDataId as 2, it should see 2 is present in left hand side of a property in data object in first array and in data object 2 has value of 1, then I need to replace value of active to 1 because value of 2 in data object is 1 and need to do same for other elements. In case if a certain element is not there in realData array, then I need to add a element in realDataArray for that element. For example. in Data object for “4:0” element, we can see there is no element in realData array with id 4, then I need to add the element in realData array with realData id 4. Newly added element will look as follows:

              {
                "secondaryId": 0, ---> this will be always 0, if new element is getting added.
                "measurementID": 55163, ---> value of this element need to be copied from measurementID of that particular element in realData array
                "realDataId": 4, --> realDataId need to be set from data object for element "4:0". always left hand side value
                "active": 0  --> Right hand side value of  "4:0"
             }

ı can’t get this element in python or c# code? [closed]

I’ve been trying to fix this problem for days. There is a web site. I want to log in this web site with code. c# or python.

enter image description here

There is a ul and two li. But both python and c# cannot click on this log in tab. I tried selenium, cefsharp, webBrowser. I couldn’t fix it. Here is the html code. btw when I change these tab this html class(“active”) is changing. like this
register

enter image description here

it doesn’t matter what ı use. I mean I can use python, I can use c# any library ı can learn what should ı do? is there any way to make this code?

Get all pixels within a rectangle using corner x,y coordinates

I have a 500 pixel by 500 pixel image that I am using to pull data from a 250,000 index array where each index represents 1 pixel.

The user is able to draw a rectangle at any orientation, and I am capturing the coordinates for each corner.

I am trying to capture each pixel within the rectangle to reference the data array and extract the related data.

I looked at Bresenham algorithm in Javascript and while I can get all the points between each of the coordinates using this solution, I am unable to loop through these points as the paths do not always contain the same number of pixels.

An example of the values I’m looking for using the following coordinates would be:

corner1 = [100,100]
corner2 = [100,105]
corner3 = [105,105]
corner4 = [105,100]

And the result (sort order is not important):

pixelsInRectangle = [
  [100,100],[100,101],[100,102],[100,103],[100,104],[100,105],
  [101,100],[101,101],[101,102],[101,103],[101,104],[101,105],
  [102,100],[102,101],[102,102],[102,103],[102,104],[102,105],
  [103,100],[103,101],[103,102],[103,103],[103,104],[103,105],
  [104,100],[104,101],[104,102],[104,103],[104,104],[104,105],
  [105,100],[105,101],[105,102],[105,103],[105,104],[105,105]
]

One set of coordinates I’m trying to solve for are:

corner1 = [183,194]
corner2 = [190,189]
corner3 = [186,184]
corner4 = [179,190]

Any recommendations would be greatly appreciated!

Adding a script to the `option` object in HTML [duplicate]

Kind of an HTML noob but I’ve been stuck on this issue for a while now. I am trying to add a drop-down menu to my web application. When a user selections an <option>, I would like to run a given JavaScript function. This is what I have so far:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>CesiumJS and Exyn</title>
  <script>
    function help(){
      console.log("help me please!");
    }
  </script>
</head>
<body>
  <div id="toolbar">
    <select class="cesium-button" id="location-select">
      <option onclick="help();">Cesium COP Demo1</option>
      <option onclick="help();">Cesium COP Demo2</option>
      <option onclick="help();">Cesium COP Demo3</option>
    </select>
  </div>

</body>
</html>

When I run this on my local machine, I do not see a console output when selecting elements in the drop-down menu. Any suggestions? Thank you!

Javascript – Dynamic filtering based on multiple properties using drop-down lists

Ok, so I’m trying to create a new selection process for a simple online vehicle rental system. Been trying to figure this out for quite a while now, but somehow it’s just breaking my brain. Hopefully one of you can get me on the right track.

Starting point is a JSON data set returned from a web service, containing all information on vehicles available for rent. I have adjusted and simplified the data set I’m presenting here, but the principle I’m trying to achieve remains the same.

This is the sample data:

{"511":{"name":"Location 1","vehicles":{"115":{"type":"Car","color":"Blue","available":["Monday","Tuesday"]},"116":{"type":"Bicyle","color":"Red","available":["Monday","Saturday"]},"117":{"type":"Car","color":"Green","available":["Monday","Tuesday","Wednesday","Friday","Sunday"]}}},"512":{"name":"Location 2","vehicles":{"230":{"type":"Van","color":"Green","available":["Friday","Sunday"]},"231":{"type":"Boat","color":"Yellow","available":["Wednesday","Thursday","Saturday"]},"232":{"type":"Car","color":"Blue","available":["Monday","Tuesday"]},"233":{"type":"Bicyle","color":"Red","available":["Monday","Tuesday"]},"234":{"type":"Bicyle","color":"Green","available":["Monday","Tuesday"]},"235":{"type":"Bicyle","color":"Yellow","available":["Monday","Tuesday","Wednesday"]}}},"513":{"name":"Location 3","vehicles":{"442":{"type":"Boat","color":"Green","available":["Tuesday","Wednesday","Thursday"]},"443":{"type":"Car","color":"Yellow","available":["Saturday","Sunday"]},"444":{"type":"Bicyle","color":"Blue","available":["Monday","Tuesday"]},"445":{"type":"Car","color":"Red","available":["Monday","Tuesday"]},"446":{"type":"Bicyle","color":"Green","available":["Friday"]}}}}

So the idea is that a user should be able to select a certain vehicle based on four properties:

  • vehicle type
  • location
  • an additional property (color in this example)
  • desired time slot (day of the week in this example)

I have also created a simple example of what this selection process should look like:

https://jsfiddle.net/wxwxw/90wrqcv5/25/

So there are four dropdown menu’s. One for each of the properties. Each menu will initially be filled with alle the different possibilities for that property from the data set. Furthermore:

  • It’s up to the user to decide in which order they select properties from the dropdown menus
  • A choice made in one of the menus should filter out options in the other menus. E.g. when the user starts by selecting ‘Location 2’, they should then only be able to choose a vehicle type, color or time slot available at ‘Location 2’. If they then pick a vehicle type, they should only be able to pick a color or time slot corresponding to vehicles of that type at ‘Location 2’ etc.
  • This filtering should also apply to the menus already selected by the user. Example flow:
    • The user first selects ‘Location 2’ from the location dropdown
    • They can now pick the color ‘Green’, ‘Yellow’, ‘Blue’ or ‘Red’, because those are available at ‘Location 2’
    • The user selects ‘Yellow’ from the color dropdown
    • If the user goes back to the location dropdown, it now only shows ‘Location 2’ and ‘Location 3’, because those are the only locations with yellow vehicles (‘Location 2’ remains selected)
    • The date dropdown shows: ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Saturday’
    • The vehicle type drowndown shows: ‘Boat’, ‘Bicycle’
    • User now picks ‘Tuesday’ from the date dropdown
    • The vehicle type drowndown only shows ‘Bicycle’
  • A filter can be cleared by setting the value of the dropdown menu back to the initial option ‘Pick one…’

So far I’ve only been able to create a selection system with a fixed order / dependency. But I’m really struggling to create something that is more dynamic as described above.

I feel like there must be an elegant solution to this. Something that can also be easily expanded with additional properties. But I haven’t been able to think of it. So any pointers would be greatly appreciated 🙂

remark-prism doesn’t convert to HTML with classnames

I wanted to convert markdown to syntax highlighted HTML with remark and remark-prism. But it doesn’t work.

code:

import {remark} from "remark";
import prism from "remark-prism";
import html from "remark-html";

const text = '```javascriptnconsole.log("Hello, world");n```';
remark()
  .use(prism)
  .use(html)
  .process(text, (_, {value}) => console.log(value));

result:

<div>
  <pre>
    <code>
      <span>console</span>
      <span>.</span>
      <span>log</span>
      <span>(</span>
      <span>"Hello, world"</span>
      <span>)</span>
      <span>;</span>
    </code>
  </pre>
</div>

It looks good. But it doesn’t contain classnames.

I wanted just like:

<div class="remark-highlight">
  <pre class="language-javascript">
    <code>
      <span class="token console class-name">console</span>
      <span class="token punctuation">.</span>
      <span class="token method function property-access">log</span>
      <span class="token punctuation">(</span>
      <span class="token string">"Hello World"</span>
      <span class="token punctuation">)</span>
      <span class="token punctuation">;</span>
    </code>
  </pre>
</div>

Pass variables to Function()

I wish to use the Function javascript feature instead of “eval”, for implementing the ability to use comparison operators inside a filtering input field.

function test(){
 let x = 5, y = 10, operator = '>';
 return Function("return x" + operator + "y")(x, y);
}

console.log(test());

The code above throws an error, x, y appear undefined in the Function.

So how can I pass external variables to Function?

Javascript Error when Generating PDF with multiple images using jsPDF and html2canvas

I’m trying to generate a PDF file with multiple images using html2canvas (to take screenshots) and jsPDF (to create the PDF document). But I’m getting a javascript error from html2canvas library when already taking a lot of screenshots (around 40+). But less than that, it works fine. Error encountered below:

Javascript error

Main JS Code below:

    var url = document.location.toString();
    var target = url.split('#');

    var images = [];

    $('html,body').scrollTop(0);
    var imagePromiseArray = [];
    var doc = new jsPDF('p', 'pt', 'a4', true);

    var subMenuSeqNo = 1;
    $(".to_image").each(function () {
        var id = $(this).attr("id");
        var href = "#" + $(this).attr("id");
        var tabSeqNo = 0;

        tabSeqNo = $(this).attr("data-tabSeqNo");

        $('a[href="' + href + '"]').tab('show');

        var sectionTab = '.sectionTab_' + tabSeqNo;

        $(sectionTab).each(function () {
            var subMenuHref = $(this).attr("href");

            $('a[href="' + subMenuHref + '"]').tab('show');
            console.log('CALL GETSCREENSHOT' + subMenuSeqNo);
            var image = getSectionLowQualityScreenshot($(".page"), subMenuSeqNo);
            subMenuSeqNo++;
            imagePromiseArray.push(image);

            $.when(image).done(function (image) {
                console.log('SCREENSHOT  TAKEN' + image.tabSeqNo);
                images.push(image);
                
            }).fail(function () { console.log('IMAGE FAIL'); });;
        });
    });
    console.log('SCREENSHOT DONE' + subMenuSeqNo);
    $.when.apply($, imagePromiseArray).done(function () {

        images.sort(function (a, b) {
            return a.tabSeqNo - b.tabSeqNo;
        });

        for (let index = 0; index < images.length; index++) {
            console.log('CALL ADDIMAGE' + subMenuSeqNo);
            const element = images[index];
            if (index != 0) { doc.addPage(); }
            doc.addImage(element.bytes, 'JPEG', 20, 20, 550, 425, '', 'FAST');
        }

        var binary = doc.output();
        var reqData = btoa(binary);
        doc_check_obj.checklistFile = reqData;
        $('a[href="#' + target[1] + '"]').tab('show');
        $.LoadingOverlay('hide');
        console.log('CALLL SAVE');
        
    }).fail(function () { console.log('FAIL'); });

getSectionLowQualityScreenshot Function Code below:

function getSectionLowQualityScreenshot(sectionDiv, tabSeqNo) {
    console.log('INSIDE' + tabSeqNo);
    var promise = jQuery.Deferred();
    var imageBytes;
    html2canvas($(sectionDiv[0]), {
        onrendered: function (canvas) {
            var imageObj = {};
            console.log('RENDER' + tabSeqNo + canvas);
            imageBytes = canvas.toDataURL("image/jpeg", 0.01);
            imageObj.tabSeqNo = tabSeqNo;
            imageObj.bytes = imageBytes;
            imageObj.width = $(sectionDiv).offsetWidth;
            imageObj.height = $(sectionDiv).offsetHeight;
            promise.resolve(imageObj);
            console.log('RESOLVE' + tabSeqNo);
        }
    });
    console.log('RETURN' + tabSeqNo);
    return promise;
}

React Text Fade in/out on click

I am using React. When a button is clicked, the text changes. I would like to have the current text fade out and then the new text fade in when the button is clicked.

I tried implementing solutions from other stack overflow posts, but to no avail.

Here is the codepen https://codepen.io/Jamece/pen/PoObBEN

const duration =1000;

//creating main React component with state being random numbers that will be an index for the quotes and color array.
class QuoteMachine extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      randomIndexQuote: 0,
      randomIndexColor: 0,
      fadeTransition: null,
      fadeState: "fade-in"
    };
    this.handleClick = this.handleClick.bind(this);
  }

  //upon click, a random number will be generates and state will be updated

  handleClick() {
    const timeout = setTimeout(() => {
      this.setState({
        randomIndexQuote: Math.floor(Math.random() * quotes.length),
        randomIndexColor: Math.floor(Math.random() * colors.length),
        fadeTransition: null,
        fadeState: 'fade-in'
      });
    }, duration);

    clearTimeout(this.state.fadeTransition);

    this.setState({
      fadeState: "fade-out",
      fadeTransition: timeout
    });
  }

  render() {
    //variables holding state index
    const quoteOutput = quotes[this.state.randomIndexQuote].quote;
    const authorOutput = quotes[this.state.randomIndexQuote].author;
    //variables for random color styles
    const textStyle = {
      color: colors[this.state.randomIndexColor],
      transition: "all 2s ease"
    };
    const backgroundStyle = {
      backgroundColor: colors[this.state.randomIndexColor],
      transition: "all 2s ease"
    };

    return (
      <div className="container-fluid px-0">
        <div
          className="d-flex justify-content-center align-items-center main"
          id="quote-box"
          style={backgroundStyle}
        >
          <div className="white-box">
            <div
              className={"fade-wrapper ${this.state.fadeState}"}
              style={{ transitionDuration: "${duration}ms" }}
            >
              <p id="text" style={textStyle} className="text-center">
                "{quoteOutput}"
              </p>
              <p id="author" style={textStyle} className="text-end">
                {authorOutput}
              </p>
            </div>

CSS

.fade-wrapper {
  transition: opacity ease-in-out;
}
.fade-out {
  opacity: 0;
}
.fade-in {
  opacity: 1;
}

Thank you.

Iterating over Map object

I’m new to javascript and I’m trying to understand how to use the Map feature.
I have an array of numbers, and if the value is 0, I want the key of the object to be false, and for any other value; true.

Here is my attempt:

const array1 = [1,0,1,0,1,-1];


const mapExample = new Map(); 
for (values of array1 )
 {
     if (array1[values]) !== 0) {
        mapExample.set(true, values)
     } else {
        mapExample.set(false, values)
     }
  }

My output:

 [ true, 1 ]
 [ false, 0 ]
 

This is want be what but my code does not finish the map for the rest of the array (there should be 4 more outputs) and I’m pretty stumped on what went wrong.

Counting Checkboxes in an external Javascript file

I’m having difficulty with a HTML file – I have a simple checkbox form and all I would like to do is count the number of check boxes checked when the form is submitted and then perform a really easy calculation to display on the screen.

I have a second JavaScript file that I’m assuming needs a function() that the HTML form triggers with an onclick=”function()”? But here is where I’m having difficulty, I can’t seem to crack it.

Any help would be greatly appreciated! Here is the JS file –

var express = require('express');
var bodyParse = require('body-parser');
var app = express();

app.use(express.static('public_html'));
app.use(bodyParse.urlencoded({
  extended: false
}));

app.post('/order', function(req, res) {

  let pizzaOptions = 0;
  let totalPizzaOptions = 0.5 * pizzaOptions;

  res.write('<html><head>');
  res.write("<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css' integrity='sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk' crossorigin='anonymous'></head>");
  res.write('<body> <div class="container">');
  res.write("<h1 class='text-left'>ORDER CONFIRMATION</h1>");
  res.write("<h2 class='text-left'>Pizza Cost</h2>");

  res.write('<div class="container">');
  res.write('<div class="row">');
  res.write('<div class="col">');
  res.write(`<p>You requested ${pizzaOptions} optional extras.</p>`);
  res.write(`<p>They cost $0.50 each which brings your total to ${totalPizzaOptions}</p>`);

  res.write('</div>');
  res.write('</div>');
  res.write('</div>');

  src = "https://code.jquery.com/jquery-3.5.1.slim.min.js"
  integrity = "sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
  crossorigin = "anonymous"
  src = "https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
  integrity = "sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
  crossorigin = "anonymous"
  src = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"
  integrity = "sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
  crossorigin = "anonymous"
  res.write('</body></html>');
  res.send();
});

app.listen(3000, function() {
  console.log("Web server running at: http://localhost:3000");
  console.log("Type Ctrl+C to shut down the web server");
});
<!doctype html>
<html lang="en">

<head>
  <title>Pizza Order</title>
  <meta charset="utf-8">
  <meta name="Jacob" content="">
  <meta name="description" content="Express Sqlite3 Demo">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Latest compiled and minified CSS -->
  <!-- CSS only -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
</head>

<body>
  <div class="container">
    <form action="/order" method="post" name="main" id="main">
      <div class="form-group row">
        <label class="col-form-label col-sm-2 text-sm-right" for="pizzaOptions">Special requests:</label>
        <div class="col-sm-10 my-auto">

          <div class="form-check form-check-inline">
            <input class="form-check-input" type="checkbox" name="pizzaOptions1" value="Extra Cheese" id="pizzaOptions1">
            <label class="form-check-label" for="pizzaOptions1">
                            Extra Cheese</label>
          </div>

          <div class="form-check form-check-inline">
            <input class="form-check-input" type="checkbox" name="pizzaOptions2" value="Roasted Garlic" id="pizzaOptions2">
            <label class="form-check-label" for="pizzaOptions2">
                            Roasted Garlic</label>
          </div>

          <div class="form-check form-check-inline">
            <input class="form-check-input" type="checkbox" name="pizzaOptions3" value="Thick Crust" id="pizzaOptions3">
            <label class="form-check-label" for="pizzaOptions3">
                            Thick Crust</label>
          </div>

          <div class="form-check form-check-inline">
            <input class="form-check-input" type="checkbox" name="pizzaOptions4" value="No Chilli" id="pizzaOptions4">
            <label class="form-check-label" for="pizzaOptions4">
                            No Chilli</label>
          </div>
        </div>

        <div class="form-group row ">
          <div class="col-sm mx-auto d-flex justify-content-center ">
            <button type="submit" class="btn btn-primary">Submit</button>
          </div>
        </div>
    </form>
    </div>

    <!-- jQuery library -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
    <script type="text/javascript" src="9.3.js"></script>
</body>

</html>

How do I create a simple price changer page with HTML and JS?

My idea is to have a menu on one page and a price changer on the other page, so in theory i would have a drop down list where for example I would select an item such as “burger” which would then show with the price from another page and let me change the value by typing new price and hitting submit. So far i figured how to transfer the item to the drop down list but not the price nor change it.

input value to website and retrieve value do this multiple times [closed]

(im using macos with apple chip)

is there a way through coding to (1) enter this website,(2) input values from list in csv or other, (3) pressing the website button, (4) then retrieving the results to another file or somewhere else.

website: https://itbi.prefeitura.sp.gov.br/valorreferencia/tvm/frm_tvm_consulta_valor.aspx

input value = 077 371 002 02

*date value = 02022022

Ionic Vue datalist for autocomplete

I am trying to bind a datalist to ion-input. Is there a way to do this? I tried inside the ion-item and outside. The datalist does not show. This is comparable to jQuery autocomplete. The datalist would be dynamic but need to get a static list working first. Thanks.

<ion-item >
  <ion-input list="exampleList" id="fullName" inputmode="text" />
</ion-item>
<datalist style = "border:1px solid red; height: 200px;" id="exampleList">
    <option value="George Gibson"></option>
    <option value="Gerald Gibson"></option>
    <option value="Lisa Smith"></option>
    <option value="Lisa Gordon"></option>
    <option value="Nacy Maez"></option>
</datalist>

How can I show a hidden message when typing a specific word on a website [closed]

So I’m trying to have some fun while making a non profit website.
I want to use an easter egg which I knew from 2015 but I could’t find it but maybe you can help me.

So the idea is that when you’re on the website and you type a specific word (not even in an input field), something happens. Like a word pops up in the middle of the screen.

Is there someone who knows what this is called or who knows how to program it?