rotate the text inside the span element

I have plan to make a simple animation inside the webpage for demonstrate the motor rpm . the span element look like this

 <span id="motor"  style='font-size:100px;padding: 3%;'>&#8854;</span>

and my range slider for change the speed is

<input type="range" min="0" max="100" value="0" class="slider" id="Range0" step="5" onchange="changeSpeed(this.value);"   > 

I add the button which set the new speed for motor and its function is

 function changeSpeed(speed){
    
    setTimeout( rotate_fan ,speed );  

     
 }
 
 function rotate_fan(){
var  div = document.getElementById('motor');
        deg0=deg0+direction0*10;
    div.style.webkitTransform = 'rotate('+deg0+'deg)'; 
    div.style.mozTransform    = 'rotate('+deg0+'deg)'; 
    div.style.msTransform     = 'rotate('+deg0+'deg)'; 
    div.style.oTransform      = 'rotate('+deg0+'deg)'; 
    div.style.transform       = 'rotate('+deg0+'deg)';
    
 }

but I didn’t see any change
any tips really appreciated

what the node version is not changing in VS code??

I am trying t update my Node version globally; I have Node v17.8.0 in my local machine, but when I check the node version that I am in VS code; it is still using v14.9.0.
I have tried to re-start, but it is still not changing. What should I do to update the node version to the latest version in VS code? I am a mac user.

Something weird with webElement input value in javascript

I’m recently using javascript to find webelement and interact with websites. My goal is to make the same as selenium “sendkeys” method with javascript. And I found out something weird.

In the Youtube Website, I can use this javascript code to fill automatically the search bar and research it.

document.getElementsByTagName(“input”)[0].value = “test”;
document.getElementById(“search-icon-legacy”).click();

And it works fine! Youtube accept my terms and redirect me to the url

But on some website, it does not work, despite the fact that the keys are really in the right field, and the value seems to be correct in the html, but it does not appear in the search url, therofore, I can’t make any search. Here is my code.

document.getElementById(“text-input-what”).value = “test”;

document.getElementById(“text-input-where”).value = “test”;

document.getElementsByClassName(“yosegi-InlineWhatWhere-primaryButton”)[0].click();

Is it some security on some website? Did I make a mistake? Is there some other ways to send real keys with javascript? Thank you for any advices

Why am I getting this error after I deploy ma app?

I tried putting various combinations of meta tags, like:

<meta
  http-equiv="Content-Security-Policy"
  content="default-src; script-src-elem 'self'; font-src; 'self' data;"
/>

<meta
  http-equiv="Content-Security-Policy"
  content="default-src; script-src-elem; 'self'"
/>
<meta Content-Security-Policy: font-src *.example.com; />

but nothing seems to work. I don’t even understand this error, so how could I know what to do?!
Locally I’m not having any issue, only when I deploy. I even tried different deployment platforms, and still I get the same result. The sma e thing in incognito window. I read that the extension Grammarly can produce these errors, so I disabled it. Still, the same result.

These are the errors I’m talking about:
enter image description here

How to get selected text/divs in pdf.js?

I am using React + pdf.js. I currently render a PDF page (along w/ its text layer) as follows (this is simplified):

return (
  <>
    <canvas ref={canvasRef} width={width} height={height} />
    {textInfo ? (
      <div
        style={{ width, height }}
        className="PageText"
        dangerouslySetInnerHTML={{ __html: textInfo.html }}
      ></div>
    ) : null}
  </>
);

I’m not sure how to get the selected text. Specifically, I’d like to get the actual text divs that were selected because this would allow me to calculate x/y coordinates & width/height of the selection.

Any ideas?

I tried:

onMouseUp={(e) => {
  console.log("MOUSE UP");
  console.log(e);
}};

as prop to the div with className="PageText", but this fails b/c

  1. If the user releases the mouse outside of the bounds of the text layer it does not trigger
  2. I cannot get a list of the divs that have been highlighted

How to set access token as axios authorization header after saving token to secure storage

I understand this is a commonly asked question but I still cannot seem to figure it out.. I am making an app in React-Native using redux toolkit and axios. I would like to save the login response access and refresh tokens to expo-secure-storage and then send a GET request to the API to fetchBusiness()

In my LoginScreen I have:

  useEffect(() => {
    // If the user is authenticated
    if (auth.isAuthenticated) {
      // Save the access token and refresh token to local storage
      save("access", JSON.stringify(auth.user.access));
      save("refresh", JSON.stringify(auth.user.refresh));
      // Get the current user's business
      dispatch(fetchBusiness());
    }
  }, [auth.isAuthenticated]);

My axios setup is very simple so far:

import axios from "axios";

const api = axios.create({
  baseURL: "https://example.com",
});

export default api

And my asyncthunk for fetching the business:

export const fetchBusiness = createAsyncThunk(
  "business/fetchBusiness",
  async (_, { rejectWithValue }) => {
    try {
      const response = await api.get("/api/businesses/");
      return response.data;
    } catch (err) {
      return rejectWithValue(err.response.data);
    }
  }
);

Lastly, the secure-store docs recommended this setup:

async function save(key, value) {
  await SecureStore.setItemAsync(key, value);
}

async function getValueFor(key) {
  let result = await SecureStore.getItemAsync(key);
  if (result) {
    return result;
  } else {
    return null;
  }
}

I have tried to use an axios interceptor but it says the value is undefined. I have also tried adding the header directly to the asyncthunk with same result. It seems my understanding of async functions and promises is not as good as it could be – even after reading up on it. The token is not saved before the request is made.

How can I do this? Thanks for the help in advance.

code gives an error after await is entered

I’m trying to make the program click onto a point on my screen needs the await to account for loading time but gives me VM9753:10 Uncaught ReferenceError: $ is not defined when ever it is run

code:

const sleep = ms => new Promise(r => setTimeout(r, ms));

// Click some buttons to start the quiz
$(".level_img").click();
$(".chipDesign.archivo-regular").click();
await sleep(5000);
$(".mat-button-wrapper").click();
await sleep(5000);
$(".mat-card.categories.catLength2.categories-0").click();

How to pass boolean value from one component to another in react?

In useState default value set to false and send it to login component. But login component is not getting the value(user, setUser).

import Login from "../Routes/Login";

const useAuth = () => {
  const [user, setUser] = useState(false);
  return (
    <div>
      <Login user={user} setUser={setUser}></Login>
    </div>
  )
}
export default useAuth;

When I am clicking on Login button it’s causing an error called “Uncaught TypeError: setUser is not a function”. When login button is clicked I want to change the value of “user” false to true.

const Login = ({ user, setUser }) => {
  
  console.log(user);

  return (
    <div>
      <button onClick={() => { setUser(true) }}>Login</button>
    </div>
  );
}
export default Login;

How to validate whether the password containing the registered phone number

I have a little problem on how to validate whether the password containing the registered phone number using angular as front end and ASP.NET MVC as backend.

Appreciate all of your help, if any of you have the idea on how to code on validate whether the password containing the registered phone number.

Currently, my regex of validation password is as below, not including phone number validation.

 /^(?=.*d)(?=.*[a-z])(?=.*[A-Z])(?=.*[$@!*&])[da-zA-Z$@!*&]{8,20}$/

Why is webpack processing my node_modules folder?

… despite my configuration file telling it not to. It is a simple file only handling a few file types as seen below. I am using webpack 5.7.0, the current latest version.

const css = {
  test: /.css$/i,
  use: ['style-loader', 'css-loader']
};

const jsx = {
  test: /.jsx?/,
  exclude: /node_modules/,
  use: {
    loader: 'babel-loader',
    options: {
      presets: ['@babel/preset-env', '@babel/preset-react']
    }
  }
};

const file_types = {
  rules: [
    css,
    jsx
  ]
};

const entry = '/Users/c/top/frame/index.jsx';

const output = {
  filename: 'bundle.js',
  path: '/Users/c/top/frame-server/dist'
};

const stats = { warnings: false };

const config_obj = {
  stats:          stats,
  entry:          entry,
  output:         output,
  module:         file_types
};

module.exports = (env) => {
  return config_obj;
};

Is getElementById or getElementsByClassName[0] faster?

Is it faster to use getElementById

document.getElementById('foo').style.visibility = 'visible';

or getElementByClassName[0]

document.getElementsByClassName('foo')[0].style.visibility = 'visible';

I have read that too many IDs can hamper performance, which is why I am trying to shy away from IDs. But if it is faster to use an ID for a quick JavaScript lookup, I will gladly do so.

Showing a button that pushes all other elements to the side (CSS Transition)

Basically, I’m having cards that have a height set by the flex behaviour. I’d like to add a button from the side that is only shown when the card is hovered so the button would come out from the right side of the container with a transition and start expanding and pushing all other content to the left until it finishes expanding. Therefore, I’ve looked for hours and I tried many things out and I couldn’t find a solution. Could someone please help me out on this? here is my code, I’m using Bootstrap 5. Here is the UI I created

Here is my code . I’m using VueJS and my data is coming from an API.

<template>
<div class="d-flex col-12 flex-column bd-highlight mb-3">
  <div class=" d-flex border border-dark col-12 flex-column" v-for="(question,index) in questions" :key="question +  index">
    <div class="d-flex col-12 justify-content-between">
      <div>
        <span class="text-wrap text-break">{{question.description}}</span>
      </div>
      <div class="d-flex">
      <span :class="question.complexity.toLowerCase() === 'easy' ? 'badge bg-success align-self-start' : question.complexity.toLowerCase() === 'medium' ? 'badge bg-warning  align-self-start' : 'badge bg-danger align-self-start' ">{{question.complexity}}</span>
      </div>
    </div>
    <div class="d-flex flex-wrap">
    <div class="p-2" v-for="(tag,index1) in question.tags" :key ="tag + index1">
      <span class="badge bg-dark text-white"><i :class="'devicon-'+tag.nom.toLowerCase()+'-plain'"></i>  {{tag.nom}}</span>
    </div>
    <div  class="align-items-center d-flex w-100 justify-content-end">
      <span> 
      <i class="fas fa-stopwatch"></i> {{question.duree}} secs </span></div>
    </div>
  </div>
</div>
</template>

Here is my UI

Expected Result ( Buttons should be with the same size )

How to link to a file one level above the current one

In CSS I know that I can reference/link to another file using either of the following:
photo.jpg or ./photo.jpg for a file in the same location as the one I am working in, and photo-folder/images/photo.jpg or ./photo-folder/images/photo.jpg to link a file in one or more directories below/inside the parent directory of the one I am working in.

I also know the same idea applies in HTML like ./[href] or [href].

But I am wondering, let’s say the positions of the files in my example are reversed, that is, I want to link to a photo in a directory which is the direct/indirect parent of the file I’m working in. How would I call that file without using the full drive address such as C:/Users/Username/Code/etc/photo.jpg, while my working file is C:/Users/Username/Code/etc/code/file.css…

How is it done in these languages: HTML, CSS, JS, Python? (You are welcome to answer for other languages, I might need it later! :D)

Side question: is there any technical difference between ./file and file, and would it be preferable to stick to one format over the other (e.g. to prevent problems, for readability, etc)? Though I have never run into any problems using either, or even combining both in the same project…

Chart.Js array into labels

I am trying to echo a variable that contains the last 30 days into tha label of a chart. I don’t know what I’m missing.

> $today     = new DateTime(); 
$begin     = $today->sub(new DateInterval('P30D')); 
$end       = new DateTime();
$end       = $end->modify('+1 day'); 
$interval  = new DateInterval('P1D'); 
$daterange = new DatePeriod($begin, $interval, $end); 
foreach ($daterange as $date) { 
    $d[] = $date->format("M j"); 
}
$labels = "'".implode("','",$d)."'";

The line from chart config

 labels: [<? echo $labels; ?>],

This is the output: ‘Feb 24′,’Feb 25′,’Feb 26′,’Feb 27′,’Feb 28′,’Mar 1′,’Mar 2′,’Mar 3′,’Mar 4′,’Mar 5′,’Mar 6′,’Mar 7′,’Mar 8′,’Mar 9′,’Mar 10′,’Mar 11′,’Mar 12′,’Mar 13′,’Mar 14′,’Mar 15′,’Mar 16′,’Mar 17′,’Mar 18′,’Mar 19′,’Mar 20′,’Mar 21′,’Mar 22′,’Mar 23′,’Mar 24′,’Mar 25′,’Mar 26’

I thought this was the correct version.

Thanks in advance

How to wait for results from multiple async methods wrapped in a for loop?

I’m developing a search algorithm which searches through 3 databases and prints out the results. The general structure of the code looks something like this:

for(type in ["player", "team", "event"]){
   this.searchService.getSearchResult(type).toPromise()
   .then(search_result => {
      if(type == "player"){
        this.player_search_results_full = this.getPlayerSearchResults(search_result, search_string);
      }
      if(type == "team"){
        this.team_search_results_full = this.getTeamSearchResults(search_result, search_string);
      }
      if(type == "event"){
        this.event_search_results_full = this.getEventSearchResults(search_result, search_string);
      }
   })
}
// this.getFinalDisplayResults()

getFinalDisplayResults(){
  // Do some actions on <type>_search_results_full lists
}

Those <type>_search_results_full will be a list that contains the full list of matches for the search_string. I’d like to then wait for all of those lists to be populated, then run them through another method getFinalDisplayResults which chooses a total of X number of results to display from those full lists.

The issue I’m facing is that this.getFinalDisplayResults() executes before those <type>_search_results_full lists are full. I tried putting everything in the for loop in a separate method getFullResults() and then doing something like this:

async getFinalDisplayResults(){
  await getFullResults()
  // Do something
}

But that seems to not work, as adding some logs shows that the for-loop in getFullResults() finishes without the lists being populated.

I don’t have a strong understanding of toPromise() and asynchronous methods, so I’m sure I’m just approaching this incorrectly. Can someone help me understand what I should be doing instead?