button click to display consecutive dates stops working on same two dates (forward and back)

I have been front-end developing in js for about 3 1/2 years now and can usually find the answer to my problem fairly quickly, most of the time through StackOverflow. Not so this time. I have a date (not typed as date though) bar div that responds to fwd and back button clicks to change the date (day, month, day number) by one day. The buttons/dates work fine until I get to Sunday, October 9th, or Sunday, May 1. At that point, the button click does not even enter the function so I might see why the same dates cause a problem which seems odd. The click still enters the listener, though, as there is a counter there that works but will not enter the function as it has for the dates after May 1 and before October 9. Does this problem seem familiar to anyone… barring that, is there a plugin that works with the date object to display it as it is changed by the user?

Looking for the best way to connect to the Twitter API via JS from WordPress

I have tried looking for a good and secure way to work with the Twitter API from a WordPress site, without a plugin. I want to make an API call to the Twitter API with my Bearer token via Javascript, and then just use the data I get back, to display on the front-end.

When looking around it seems like it would be possible to have a define(‘key’,’token) in wp-config.php and then via wp_enqueue_scripts access it in a JS-file. But then it says other places that it would be unsecured storing secure data in wp-config.php.

So I’m very confused on which approach to take from here,
Hope you guys can help!

  • Jiffy

JavaScript I want to navigate to another page

I need to know what to do exactly.
I’m editing a template and I want to add some items in the nav-bar to redirect me to an outer page.
it works fine the full size page but in mobile size it don’t it only move me in the same page.
this is the function that responsible for the operation:

var OnePageNavigation = function() {
    var navToggler = $('.site-menu-toggle');
    $("body").on("click", ".main-menu li a[href^='#'], .smoothscroll[href^='#'], .site-mobile-menu .site-nav-wrap li a", function(e) {
      e.preventDefault();

      var hash = this.hash;

      $('html, body').animate({
        'scrollTop': $(hash).offset().top
      }, 600, 'easeInOutExpo', function(){
        window.location.hash = hash;
      });

    });
  };

and this is the template: https://technext.github.io/banker/index.html
this is the source: https://github.com/technext/banker

what can I add to the function or the code to allow me to navigate to outer pages?

Sorry if my explanation was bad my English is not the best

Truffle test not changing/saving smart contract variables

Hi whenever I test in truffle and I call a function that should change a variables value inside the contract and then try and access this value, the value does not change. Below I have code to try and debug this issue for another project. The function works perfectly in remix

On my end I call increaseIterator() and then console.log the value and it is still 0. In remix the value would increase to 1. Please help

Test:

const Test = artifacts.require("testing");
const { expectRevert } = require("@openzeppelin/test-helpers");
const { web3 } = require("@openzeppelin/test-helpers/src/setup");

contract('testing', (accounts) => {
    let testing
    beforeEach (async() => {
        testing = await Test.new();
        await web3.eth.sendTransaction({from: accounts[0], to: accounts[1], value: 1000})
    })

    it('should increase', async() => {
        const beforeIncrease = await testing.returnIterator();
        console.log("before increase: " + beforeIncrease);

        testing.send.increaseIterator();

        const afterIncrease = await testing.returnIterator();
        console.log("after increase: " + afterIncrease);
    })
})

Smart contract:

pragma solidity 0.8.14;

contract testing {
uint iterator;

constructor () {
    iterator = 0;
}

function increaseIterator() public {
    iterator++;
}

function returnIterator() public view returns (uint) {
    return iterator;
}
}

Chat app with Node.JS in Fedora Linux (in MobaXTerm). Server.js & Client.js are connected but messaging failed

I want to create a terminal chat application in Node.JS. I use MobaXTerm (WSL-Fedora).
The problem is that the server and client can connect to each other, but I can’t send a message from one side to the other.

Can somebody help me?

Thanks in advance!

//client.js
const net = require('net');
const client = net.createConnection({ port: 8124 }, () => {
  // 'connect' listener.
  console.log('connected to server!');
  client.write('world!rn');
});
client.on('end', () => {
  console.log('disconnected from server');
});

process.stdin.setEncoding('utf8');
process.stdin.on('readable',
function() {
var chunk = process.stdin.read();
if (chunk !== null) {
process.stdout.write(chunk);
}
}
);

//server.js
const net = require('net');
const server = net.createServer((c) => {
  // 'connection' listener.
  console.log('client connected');
  c.on('end', () => {
    console.log('client disconnected');
  });
  c.write('hellorn');
  c.pipe(c);
});
server.on('error', (err) => {
  throw err;
});
server.listen(8124, () => {
  console.log('server bound');
});


process.stdin.setEncoding('utf8');
process.stdin.on('readable',
function() {
var chunk = process.stdin.read();
if (chunk !== null) {
process.stdout.write(chunk);
}
}
);

How to pass parent value to child on first render and change parent component value from Child?

So what i’m trying to do is pass a number to the child component, which will only be passed on the first render. After that i’m trying to change the current value and pass the value from the child, back to the parent component. However i’m not able to pass price to child, as i’m receving undefined.

Not sure how I can pass the data in this context, any ideas?

function Parent(props, {price}) {
        const [amount, setAmount] = React.useState("200");
    
        function handleChange (newValue) {
          setValue(newValue);
        }
    
        // We pass a callback to Child
        return <Child price={amount} value={value} onChange={handleChange} />;
    }
    
    
function Child (props, {price}) {
        const [amount, setAmount] = React.useState("");
            
        function handleChange(event) {
              setAmount(event.target.value)
    
              // Here, we invoke the callback with the new value
              props.onChange(event.target.value);
        }
    
       useEffect(() => {
        setAmount(price) //Pass value from parent if it has one
      }, [])
          
      return <input value={props.value} onChange={handleChange} />
   }

How to turn off ‘expo-barcode-scanner’ completely upon scan?

I’ve found a couple of similar questions to this one, but it seems people are just disabling the render, which doesn’t actually turn off the camera and leads to high power consumption. I want to completely turn off the camera after a QR code scan.

If anyone knows how to do this could you write up a quick example that just has a button that completely turns off and on the camera associated with ‘expo-barcode-scanner’? I don’t have issues catching the barcode scan event.

Handle checkboxes with useState object

I have some checkboxes displayed using .map function which is retrieving the data from a JSON file.

What i have achieved so far, is to store the clicked checkbox into the state (which is an object). But after I click another checkbox, it removes the previous one and store the latest..

I basically want to store all the checked ones, and if you remove them to remove it from the state.

Here’s my handleCheck function:

const handleCheckInput = (
      e: React.ChangeEvent<HTMLInputElement>,
      key: number,
      questionId: number,
   ) => {
      let newTickArray = [...tick];
      newTickArray[key] = !tick[key];
      setTick(newTickArray);
      setValues({ ...values, [questionId]: e.target.value });
   };

Any help will be appreciated

Cross-Origin request blocked with socket.io v4

I keep getting the following error: ‘Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3000/socket.io/?EIO=3&transport=polling&t=O3eMu4n.’

I’ve looked through numerous posts on Stack Overflow trying to get this to work but still I run into issues. I’m using the latest version of socket.io, I tried doing this first on my server side: f

That didn’t work so I tried this (as per https://socket.io/docs/v4/handling-cors/):
enter image description here

Which causes this error:
Warning: To load an ES module, set “type”: “module” in the package.json or use the .mjs extension.
(Use node --trace-warnings ... to show where the warning was created)

I don’t know how to fix this. Please help.

How to select child node of parent element and get position of caret relative to parent node?

I’ve been trying to figure out a simple issue, but it is very confusing for me. I’ve been trying to get the position of the caret in a contentEditable div react:

var selObj = window.getSelection();
var carotPosition = selObj.anchorOffset;

I immediately figured out that we have a problem f there was a nested <b> tag and the caret was inside it.

If the text is

This is my new paragraph<b>and this is inside bold</b>

THen if my caret is at ‘h’ then it would return 24 but if it was on the letter ‘a’ from and, inside the bold tag it would return 1. This is a problem I am trying to overcome. How do I get the caret position of relative to the parent element, or how do I programatically select the same position in the childNode.

This is what I’ve figured out until now:

var selObj = window.getSelection();
const oRange = selObj.getRangeAt(0); 
const oRect = oRange.getBoundingClientRect();

//How do I approach this? 

Can a cloud function safely execute async work after it has returned its promise?

Can a cloud function safely execute async work after it has returned its promise? Consider the following pattern:

exports.deleteUser = functions.auth.user().onDelete(async (user) => {
    const uid = user.uid;

    asyncTask1(uid);
    asyncTask2(uid); // don't wait for the last task to finish
    asyncTask3(uid); // just attempt them all and handle
    asyncTask4(uid); // the failures individually later
    return Promise.resolve(uid);
});

async function asyncTask1(uid) {
    try {
        await someAsyncWork();
        return Promise.resolve(true);
    } catch (error) {
        throw new functions.https.HttpsError("unknown", "Task 1 failed.", error);
    }
}

Should this pattern be avoided in Cloud Functions? My concern is that the instance that was initialized to execute this call could be deallocated before the tasks have a chance to finish since the function that initialized the instance returned a promise almost immediately after being called. Or will the server keep this instance alive to let the async work finish even though the main function has already terminated?

Variable out of scope (probably) – undefined

So this piece of code is returning description of word in json from https://sjp.pl/ webiste, word which user provied before in request json body

And problem is that i want to send back var ‘desc’ in res.send but its undefined. How I can access that and send it?


const item = [];
var desc;

app.post('/test', (req, res) => {
    const { word } = req.body;

    if(!word) {
        res.status(418).send({error: 'no word provided'})
    }

    console.log(word)

    axios(`https://sjp.pl/${word}`).then(res => {

        const html = res.data
        const $ = cheerio.load(html)

        $('p').each(function() {
            item.push($(this).text())
        })

        desc = item[3]

        console.log(desc) // working until here
    })

    console.log(desc) // undefined here

    res.send({
        description: `${desc}`
    })
})

Props not accessible in Vue created hook when passing with Inertia js

I’ve got an Inertiajs app in which I call a component with the following link:

<Link href="/explore-data"
  class="rounded-lg bg-blue-500 hover:bg-blue-200 text-white text-md font-semibold tracking-wide p-2" 
  :data="{ selectedIds: selectedIds }">
  Proceed 
</Link>

Then, in my web.php file I pass it to the next component as a prop as follows:

Route::get('/explore-data', function (IlluminateHttpRequest $request) {

    return Inertia::render('ExploreData', [
        'cities' => AppModelsCity::all(),
        'selectedIds' => $request->selectedIds
    ]);
});

In my ExploreData component, I try to access the selectedIds prop in my created hook, but printing it out shows me that it’s null. What is strange is that this only happens on my server, when I do this on localhost it works fine. Here is how I declare the prop and try to call it in the ExploreData component:

export default {

    props: {
        selectedIds: Object,
        cities: Object
    },

    ...

   created() {
        let t = this

        console.log('Selected IDS: ')
        console.log(this.selectedIds) // this gives me NULL on server, but not on localhost

        this.selectedIds.forEach(function(item) {
           // do something with my selectedIds
        })
       ....

Does someone know what could be happening here and how to fix it?