Sending an IG Message when Someone Follows My Page

I’m trying to create a bot that will send my new followers a message on Instagram when they follow me. I’m using Facebook’s graph API and webhook to enable this. I want to know if this is possible as I’m having issues with the webhook. The workflow is
1. a webhook on my page that will listen to any new follow requests
2. grab that follower’s information
3. send that follower a message.

Currently, my Instagram account is linked with a FB page and I’ve been able to add webhooks to that page. However, I don’t know how I can add a webhook to listen to my IG follower information that is linked to my FB page.

Return a boolean depending on if a string contains all the characters of another string [duplicate]

Say you have two strings and you want to see if str2 contains all the needed characters to make up str1.
str1 = ‘elephant’
str2 = ‘eluhrtphnat’
Function should return false, since the str2 is missing the second e.

I understand you can use the Includes() function, however this will not work for words, like elephant, where there are 2 e’s.

How to properly update a prop used as an initial value?

I’m wondering if I’m doing this the best way possible; I’ve built a component which accepts a list of items as a prop, but then I need to mutate that list internally in the component, so I followed the VueJs docs to provide the prop value as a data property’s initial value, and then using the data property when I need to make any changes to the data.

export default {
  props: {
    items: {
        type: Array,
        default: () => {
            return []
        }
    }
  },
  data() {
    return {
        itemList: this.items
    }
  }
}

I noticed however that this causes the itemList property to stick to the initial value, and won’t update if the parent component provides a new items value to this component, this makes sense as the component was already rendered and thus it doesn’t need to reevaluate all it’s data properties; so to fix this I added a watcher to watch for any changes on items:

watch: {
   items() {
        this.itemList = this.items;
    }
}

I found this other question which had a similar issue and the accepted answer did just what I just did here; however I’d like to know if this is an expected and reliable method of fixing this issue or if there are other ways to do this?

why “.length” is acting differently in the similar cases in javaScript?

Here the length is declared before the for loop and the function is giving the correct answer.
The console: []

function dropElements(arr, func) {
let len = arr.length;

  for(let i=0; i<len; i++){
    if(!func(arr[0])){
      arr.shift();
    }
  }

  return arr;
}

console.log(dropElements([1, 2, 3, 4], function(n) {return n > 5;}));

Now the length is used directy in the for loop and the function is leaving behind two elements of the array.
The console: [3,4]

function dropElements(arr, func) {

  for(let i=0; i<arr.length; i++){
    if(!func(arr[0])){
      arr.shift();
    }
  }

  return arr;
}

console.log(dropElements([1, 2, 3, 4], function(n) {return n > 5;}));

Javascript not rounding properly

I made a simple number guessing game in javascript which goes from 1 to 100.
My problem is that everything works, except when I type a decimal number from 100 to 101. I want my code to give me the “Please enter a number from 1 to 100” message then, but it doesn’t.
How do I get Javascript to round this properly?

let randomNumber = Math.floor(Math.random() * 100); // Random number

function guess() {
  let inp = document.getElementById("number").value; // Reading input
  let inpRounded = Math.floor(inp);

  // Random number is higher
  if (inpRounded < randomNumber && inpRounded >= 1 && inpRounded <= 100) {
    document.getElementById("result").innerHTML = "Higher";
  }
  // Random number is lower
  else if (inpRounded > randomNumber && inpRounded >= 1 && inpRounded <= 100) {
    document.getElementById("result").innerHTML = "Lower";
    // Input matches random number 
  } else if (inpRounded == randomNumber && inpRounded >= 1 && inpRounded <= 100) {
    document.getElementById("result").innerHTML = "You won!";
  }
  // Input is weird
  else if (inpRounded == null) {
    document.getElementById("result").innerHTML = "Please enter a valid number";
  }
  // Input is lower than 1 or higher than 100
  else if (inpRounded < 1 || inpRounded > 100) {
    document.getElementById("result").innerHTML = "Please enter a number from 1 to 100";
  }
  // Other issue
  else {
    document.getElementById("result").innerHTML = "Error"
  }
}
<h2>Enter a number from 1 to 100</h2>
<input type="number" placeholder="Type your guess here" id="number">
<input type="button" value="Go!" onclick="guess()">
<p id="result"></p>

How to pass Data From React Router through props? I am unable to do it

Hey I am Practicing a contact List in React
The problem i am facing I am unable to pass props in react router with route it work fine but when i Try to render it through React Router i got nothing

   function App(){
const[contactdata,setcontactdata]=useState(GetLocaldata());
  return (
 
 <div className="ui container App">
{/* <Header/>
<AddContact  AddChangeHandler={AddChangeHandler} />
<Contactlists Contact={contactdata} deletehandler={deletehandler} /> */}

<Router>
<Header/>
<Routes>
<Route path="/" render=
{(props)=><Contactlists {...props} 
Contact={contactdata} deletehandler={deletehandler} /> }
/>
<Route path="/add" render=
{(props)=><AddContact {...props}  AddChangeHandler={AddChangeHandler}/>} />
<Route path="/de" element={<ContactDetail/>} />
 </Routes>
 </Router>
   </div>
   );

 
}

In which way can i pass through a method call in JavaScript class

Assume we have some classes A and B:

Class A {
    constructor(a) {
       this.a = a;
    };
    showInfo() {
        console.log(this.a)
    };
};

Class B {
    constructor(b) {
        this.b = b;
    };
    printText() {
        console.log('its B!');
    };
};

Then we create an instance of B like this:

const objB = new B(
    new A(3)
);
  1. So now we have objB with its own method inside – printText, and we surely can call it.
    But what if i want somehow when calling not existing method in objB to make it pass through to encapsulated A class in there and look for invoking this method on him, like this: objB.showInfo() – to give me 3 here ?

  2. Same story, but at this time i want when calling not existing method on A to make it pass through to B outside (like that printText)?

P.S. Don’t wanna use super() and inheritance, just composition and wrapping objects, hope you’ve got the point.

JavaScript array performance drop at 13k-16k elements

I am doing some performance testing regarding creating and editing performance of arrays and noticed that there are some weird characteristics around arrays with about 13k-16k elements.

The below graphs show the time per element it takes to create an array and read from it (in this case summing the numbers in it). capacity and push relate to the way the array was created:

  • capacity: const arr = new Array(length) and then arr[i] = data
  • push: const arr = []; and then arr.push(data)

Time for creation of array based on length
Time for operations on array based on length

As you can see, in both cases, the creation of an array and reading from it, there is a performance reduction of about 2-3 times compared to the performance per element at 1k less elements.
When creating an array using the push method, this jump happens a bit earlier compared to creating it with the correct capacity beforehand. I assume that this is happening because, when pushing to an array that is already at max capacity, more than the actually needed extra capacity is added (to avoid having to add new capacity again soon) and the threshold for the slower performance path is hit earlier.

If you want to see the code or test it yourself: github

My question, why is the performance dropping at around 13k-16k?

To me it seems that larger arrays are treated differently in v8 starting at around 13k-16k elements to improve performance for them, but the cut-off point (at least in my code) is slightly too early so the performance drops before the optimizations bring any benefit.

You can see the performance improvements going down after about 500 elements and picking up again after the drop.

Sadly I can’t find any information about that.

Also, if you happen to have any idea why there are those spikes at the end of creating with capacity and summing with push, feel free to let me know 🙂

i have a form to input data in and i want the data to appear at another page from local storage

my problem is I console log the local storage and the inputs appear fine but I can’t see them on the other page although at local storage they are stored fine

the form :

  <form id="formID">
    <div class="Contact__Card">
      <div class="Input__Container">
        <label for="foodName" class="Label" >Food</label>
        <input
          name="foodName"
          class="Input"
          type="text"
          placeholder="What would you like to add?"
          id="foodName"
          required
        />
      </div>

  <div class="input__Container">
    <label for="foodType">Choose Food type:</label>
<select class="Input" id="foodType" name="foodlist">
  <option value="Fruit and vegetables">Fruit and vegetables</option>
  <option value="Starchy food">Starchy food</option>
  <option value="Dairy">Dairy</option>
  <option value="Protein">Protein</option>
  <option value="Fat">Fat</option>
</select></div>

      <div class="Input__Container">
        <label for="price" class="Label">price</label>
        <input type="text" min="1" step="any"  class="Input" id="foodPrice" required/>

        
      </div>
      <br>
      <div class="Input__Container">
       
        <input type="submit" value="Submit"  class="Input"/>

        
      </div>
  
      
      
    </div>
  </form>

the js file of the form page :

"use strict";

var allFood = [];
function food(foodName, foodType, price) {
  this.foodName = foodName;
  this.foodType = foodType;
  this.price = price;
  allFood.push(this);
}
food.prototype.fID = function () {
  this.id = Math.floor(1111 + Math.random() * 9999);
};

const formEl = document.getElementById("formID");
formEl.addEventListener("submit", handleSubmit);

function handleSubmit(event) {
  event.preventDefault();

  let foodName = event.target.foodName.value;
  let foodType = event.target.foodType.value;
  let price = event.target.foodPrice.value;

  const newFood = new food(foodName, foodType, price);

  newFood.fID();

  saveData();
}

function saveData() {
  let stringifiedData = JSON.stringify(allFood);
  localStorage.setItem("Food", stringifiedData);
}

the table of the other page i want the data to apear in :

<table id="fTable">

    <tr id="hdrTable">

    </tr>


</table>

the js file of the output page is the issue from the get data function ?:

"use strict";

const fdTable = document.getElementById('fTable');
const tableHead = document.getElementById('hdrTable');
var allFood = [];

function food(foodName, foodType, price) {
  this.foodName = foodName;
  this.foodType = foodType;
  this.price = price;
  allFood.push(this);
}
food.prototype.fID = function () {
  this.id = Math.floor(1111 + Math.random() * 9999);
};

table();

function table() {
  let headerID = document.createElement("th");
  headerID.textContent = "ID";

  let headerName = document.createElement("th");
  headerName.textContent = "Food Name";

  let headerType = document.createElement("th");
  headerType.textContent = "Type of Food";

  let headerPrice = document.createElement("th");
  headerPrice.textContent = "price";

  hdrTable.appendChild(headerID);
  hdrTable.appendChild(headerName);
  hdrTable.appendChild(headerType);
  hdrTable.appendChild(headerPrice);
}

food.prototype.Render = function () {
  let row = document.createElement("tr");
  let id = document.createElement("td");
  let name = document.createElement("td");
  let type = document.createElement("td");
  let price = document.createElement("td");

  id.textContent = this.id;
  name.textContent = this.foodName;
  type.textContent = this.foodType;
  price.textContent = this.price;

  row.appendChild(id);
  row.appendChild(name);
  row.appendChild(type);
  row.appendChild(price);

  fTable.appendChild(row);

};
getData();

function getData(){
  let retrivedData = localStorage.getItem("stringifiedData");
  let parsedData = JSON.parse(retrivedData);
  if(parsedData!=null){
  for (let i = 0; i < parsedData.length; i++) {
    let newFoodOP = new food(
      parsedData[i].foodName,
      parsedData[i].foodType,
      parsedData[i].price
    );
   
  }
}
for (let i = 0; i < allFood.length; i++) {
  allFood[i].Render();
}
    console.log(allFood);
}

Forward request to other server in NodeJS

hey uh how would I forward a request to another server using NodeJS? for example, example.com will have html that will allow you to chose between server1 and server2, how would I make it so the http req gets forwarded to server2 (which has a public IP from AWS), without changing the url in the bar?

(so it would be realistically server2.example.com and it would connect to server2)

Change bot avatar only in specific guilds

I’m trying to make a multi-guild bot and I’m struggling with making a command that changes the bot avatar only for the guild where the command was executed!

I tried to make a DISCORD API call to change the bot user avatar but I ended by changing the avatar for all guilds.

Clear content for filtered data

I managed to create script to delete rows when it is filtered but not managed to create clear content function when its filtered. Code as below:

var sheet = SpreadsheetApp.getActive().getSheetByName('data');
var lastRow = sheet.getLastRow()
var lastColumn = sheet.getLastColumn()

function deleterow_d3() {
  var RANGE = sheet.getRange(1, 1, lastRow, lastColumn)
  var rangeVals = RANGE.getValues();
  if (sheet.getFilter() != null) {
    sheet.getFilter().remove()
  }

  var filteredRange = RANGE.createFilter()
  var millis_per_day = 1000 * 60 * 60 * 72; // 3 days
  var today = new Date();
  var criteria = SpreadsheetApp.newFilterCriteria().whenDateEqualTo(new Date(today.getTime() - millis_per_day)).setHiddenValues(['']).build();
  sheet.getFilter().setColumnFilterCriteria(5, criteria); // which column to filter from, criteria is the date
  var deletedrows = lastRow - 3
  sheet.deleteRows(2, deletedrows) // to delete rows
  sheet.getFilter().remove()
}

Data is filtered by date then all content within the filter is removed. Instead deleting the rows, i want to clear the content only.

Getting values inside an object

I am trying to get the values inside the [Objects] inside the “args” key for object which looks like {“hex”: “0x32”, “type”: “BigNumber”} for:

{“address”: “0x707f11ccd0931c3d2592A11c3947Cd3560eF1aA9”, “args”: [“0x3eB308804Ee86754e2833ac921E601Ce009C3930”, [Object], [Object]], “blockHash”: “0x85949a8acba7dec8148052c537bcb710b974dc56af21331f07bbe003b25153be”, “blockNumber”: 2701, “data”: “0x0000000000000000000000003eb308804ee86754e2833ac921e601ce009c393000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000f4240”, “decode”: [Function anonymous], “event”: “addedToMarketplace”, “eventSignature”: “addedToMarketplace(address,uint256,uint256)”, “getBlock”: [Function anonymous], “getTransaction”: [Function anonymous], “getTransactionReceipt”: [Function anonymous], “logIndex”: 2, “removeListener”: [Function anonymous], “removed”: false, “topics”: [“0x2f1972ee5bc3aa9e4cb02f9f12cc6573417e6f7b8dbb8eee7b44f79e7fee251c”], “transactionHash”: “0xf9e281c8b0fed15c26e850e897657b7cd48272aefe111e93ae8107b0c3bbb286”, “transactionIndex”: 0}

Is there a way to get the hex values and convert it to decimal value?

I already tried:

object.args[1].hex

object.args[1][“hex”]

object[“args”][1][“hex”]