How to migrate Bootstrap 4 to Bootstrap 5 in existing projects

Bootstrap 5 introduced so many breaking changes, including a lot of names for classes. I have Angular project where I used Bootstrap 4 classes in more than 10k places. It is impossible to go and manually change each class to reflect Bootstrap 5 names.

Is there some command or CLI tool that can do migration from Bootstrap 4 to Bootstrap 5 and change everything needed?

List dictionary in Python to group by in key’s value

I have this list dictionary in python

accidents_dict = [{'date': 'new Date (2017,1,1)', 'Fall': 5}, 
{'date': 'new Date (2017,1,1)', 'Vehicular Accident': 127}, 
{'date': 'new Date (2017,1,1)', 'Medical': 129}, 
{'date': 'new Date (2017,1,1)', 'OB': 10}, 
{'date': 'new Date (2017,1,1)', 'Mauling': 9}, 
{'date': 'new Date (2017,2,1)', 'Fall': 7}, 
{'date': 'new Date (2017,2,1)', 'Vehicular Accident': 113}, 
{'date': 'new Date (2017,2,1)', 'Mauling': 5}, 
{'date': 'new Date (2017,2,1)', 'OB': 9}, 
{'date': 'new Date (2017,2,1)', 'Medical': 79}, 
{'date': 'new Date (2017,3,1)', 'Medical': 112}, 
{'date': 'new Date (2017,3,1)', 'Mauling': 5}, 
{'date': 'new Date (2017,3,1)', 'OB': 11}, 
{'date': 'new Date (2017,3,1)', 'Vehicular Accident': 119}, {'date': 'new Date (2017,3,1)', 'Fall': 8}]

My desired output is to group them by date and to remove the single quote in the date value. This is my desired output:

accidents_dict =[{
      "date": new Date(2017, 1, 1),
      "Vehicular Accident": 127,
      "Medical': 129,
      "OB": 10,
      "Mauling": 9
    }, {
      "date": new Date(2017, 2, 1),
      "Fall": 7,
      "Vehicular Accident': 113,
      "Mauling": 5,
      "OB": 9,
      "Medical": 79
    }, {
      "date": new Date(2017, 3, 1),
      "Medical": 112,
      "Mauling": 5,
      "OB": 11,
      "Vehicular Accident": 119,
      "Fall": 8
    }]

I tried this:

from itertools import groupby
from operator import itemgetter

for key, value in groupby(accidents_dict, key = itemgetter('date')):
  print(key)

  for k in value:
    print(k)

This was the result:

new Date (2017,1,1)
{'date': 'new Date (2017,1,1)', 'Fall': 5}
{'date': 'new Date (2017,1,1)', 'Vehicular Accident': 127}
{'date': 'new Date (2017,1,1)', 'Medical': 129}
{'date': 'new Date (2017,1,1)', 'OB': 10}
{'date': 'new Date (2017,1,1)', 'Mauling': 9}
new Date (2017,2,1)
{'date': 'new Date (2017,2,1)', 'Fall': 7}
{'date': 'new Date (2017,2,1)', 'Vehicular Accident': 113}
{'date': 'new Date (2017,2,1)', 'Mauling': 5}
{'date': 'new Date (2017,2,1)', 'OB': 9}
{'date': 'new Date (2017,2,1)', 'Medical': 79}
new Date (2017,3,1)
{'date': 'new Date (2017,3,1)', 'Medical': 112}
{'date': 'new Date (2017,3,1)', 'Mauling': 5}
{'date': 'new Date (2017,3,1)', 'OB': 11}
{'date': 'new Date (2017,3,1)', 'Vehicular Accident': 119}
{'date': 'new Date (2017,3,1)', 'Fall': 8}

I tried to iterate the list dictionary and get the value of accident key, but no luck. I also tried replace(“””,”) in date value but still, it outputs a string. Hope you can help me. Thanks a lot.

JS / HTML / CSS navbar for phone size / unable to click for page titles to show

I want to make a dropdown with the different website pages on when max-width of 960px is reached, I have made the button, added the styles, also the JS I have linked it to the HTML ( src=”app.js” “in the body tag)

Please see the JS code used for the interactive bar

const menu = document.querySelector('#mobile-menu');
const menuLinks = document.querySelector('.navbar__menu');

menu.addEventListener('click', function() {
    menu.classList.toggle('is-active');
    menuLinks.classList.toggle('active');
});

HTML CODE

CSS CODE – toggle bar

How to enable li focus in AngularJS while reusing a nav component?

I am designing a vertical navbar where the user clicks on the list item link and it will route to another component and at the same time change it to gray. I am currently re-using the gallery vertical nav component on each of the arts/nature/animals component.

However the behaviour is not expected when the user is routed to another component, I have to click the same list item link then it will be set to focus. I tried this on a normal html/css. It works perfectly but it does not work in Angular.

Could someone help me with this?

enter image description here

gallery.component.html

<nav>
    <ul>
        <li tabIndex="1"><a routerLink="/arts">Arts</a></li>
    </ul>

    <ul>
        <li tabIndex="1"><a routerLink="/nature">Nature</a></li>
    </ul>

    <ul>
        <li tabIndex="1"><a routerLink="/animals">Animals</a></li>
    </ul>
</nav>

gallery.component.css

ul {
    list-style: none;
}

li {
    padding: 10px;
    border: 1px solid #d1d1d1;
}

/* handles when user is focusing on a menu */
li a:focus {
   background-color: #8a8a8a !important;
   color: white;
}

How to remove cache storage for every newly generated Angular production builds?

I have project running, for which I have to generate and deploy the production build everyday.
but whenever I add or upgrade to a new build, my index.html is not updated, it still tries to fetch older build files e.g. runtime.xyz123.js or polyfills-es5.abcd1234.js" , since these files don’t exist anymore in build, the page goes blank, as browser is unable to find these files inside latest build.

Workaround

  1. If I manually delete cache from history, or run the project on Incognito, it works fine.
  2. If I only enters my local server e.g. http://192.168.0.164/ It works properly, but with my base href(declared while creating builds) e.g. http://192.168.0.164/angular/ it tries to fetch old build files and the webpage goes blank.

enter image description here

index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Angular Web</title>
  <meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0">
  <meta http-equiv="expires" content="0">
  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <base href="/angular/">

<link rel="stylesheet" href="styles.230892a2ce1e2d0e9693.css"></head>
<body>
  <script src="assets/js/moment.js"></script>
  <script src="assets/js/moment-timezone.js"></script>
  <app-root></app-root>
<script src="runtime.71f44460add81ff0fb1e.js" defer></script><script src="polyfills-es5.950ea5f001d77cff122d.js" nomodule defer></script><script src="polyfills.05dd00906ab9ae4ef80e.js" defer></script><script src="main.5f0ba541bbf69328189e.js" defer></script></body>
</html>

Angular version –

enter image description here

I use below build command to generated build –

ng build –prod –output-hashing all –base-href /angular/

Please let me know, If there is something I can do to resolve this cache issue.

Thanks in Advance !

How to change Botton tab bar Background Color in React Native?

I’m using @react-navigation/bottom-tabs Package. But I don’t know how to change background color of the tab bar. Here is my Code.

import React from "react";
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import Home from "./TabScreen/Home";
import Category from "./TabScreen/Category";
import Search from "./TabScreen/Search";
import Profile from "./TabScreen/Profile";
import Colors from "../../../Style_Sheet/Colors";

const Tab = createBottomTabNavigator();

const Tabs =()=>{
  return(
    <Tab.Navigator tabBarPosition="bottom" barStyle={{ backgroundColor: '#0000' }}>
      <Tab.Screen name="Home" component={Home} options={{headerTitle:"Explore",headerTintColor:Colors.white,}}/>
      <Tab.Screen name="Category" component={Category} />
      <Tab.Screen name="Search" component={Search} />
      <Tab.Screen name="Profile" component={Profile} />

    </Tab.Navigator>
  )
}
export default Tabs;

I am adding under then Tab.Navigator tag but it’s not working.

javascript function returns null in nodejss express [duplicate]

I have the following function that does not return a value, my code is as follows

    const getExpenseID = async () => {
        try {
        let newExpenseID=""
       await Expenserequest.findMax(function(err,foundMax){
        if (!err){
            if (foundMax){
                    newExpenseID=parseInt(foundMax.expenseID)+1
               
              }else{
    
                newExpenseID =100
                }
                }else{
    
                console.log(err)
    
            }
         
          })
    
          console.log("found expense id in function",newExpenseID)
    
          return newExpenseID
        
    } catch (error) {
      console.log(error);
    }
  }

when i call the function above it returns newExpenseId is blank

Track users browser activity against specified web application

I want to track users’ real-time interaction against the specific site(web app) page and scrap the data he/she views and extract it.

Note: The application is not owned by us so we can’t use google analytics or other libraries similar to it.

Is this possible to implement? and what is the best way to do this?
Any existing tools which we can use to support this requirement??
Any available browser extension or can we develop such an extension? (Note: We can install the extension on our user’s browser)

A similar question is also raised on StackOverflow Tracking user activity with Chrome extension but no answers against the same

How to extend the response of an api in react by adding a new property based on a condition?

I want to call an API and extend the response by adding a new ‘category’ prop to each
categories [‘thirds’, ‘fifths’, ‘magic’]

  • if the id is divisible by 3 => thirds
  • if the id is divisible by 5 => fifths
  • if the id is divisibly by 3 and 5 => magic

The url is https://jsonplaceholder.typicode.com/posts

How do i do that?

async function getData() {
    const response = await fetch("https://jsonplaceholder.typicode.com/posts");
    const data = await response.json();
  }

{contacts.map((contact) => (
             {contact.id}
              {contact.userId}
            {contact.title}
              {contact.body}
           
            ))}

Fabric js can objects delimitate the selection box?

I am creating a drawing program with fabric js and I have noticed that the selection area is related to the start and end of the biggest line point , meaning if I make a horizontal or vertical line I will get a small selection box , if I do a diagonal line the selection box will be a square.
My question is , is there a way to calculate a bounding box of these object to change the selection box like those you see on drawing svg layer software like krita or a selection tool like the laso tool from photoshop. Something that does not show such huge selection box on diagonal or figure drawings

how po print number after a delay in js

It’s beginner’s question. I’m trying to understand setTimeout. I want to print each number after a delay of 2 seconds. However, I can only delay the whole function, not the numbers. Can anyone tell me how to do it?

function print() {
  for (let i = 10; i >= 0; i--) {
    console.log(i);
  }
}

setTimeout(print, 2000);

How to display the Phaser Game Screen only in a Route React?

I want that my game screen only been displayed in ‘/game’ route, but when I give the boot with method “new Phaser.Game(config)” he start shows in every route ‘/home’, default rote ‘/’, ‘/error’, ‘/game’ and etc.

game.js

import Phaser from 'phaser';
import LoadScene from './scenes/LoadScene.js';
import MenuScene from './scenes/MenuScene.js';

export const config = {
  type: Phaser.AUTO,
  width: 800,
  height: 600,
  scene: [ MenuScene, LoadScene]
};

const game = new Phaser.Game(config);

gamepage.js

import config from '../../phaser/game.js';
import React from 'react';

export default class GamePage extends React.Component {
    render() {
        return <>
            <Game />
        </>;
    }
}

routes.js

import React from 'react';
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import ErrorPage from '../pages/error/index.js';
import Home from '../pages/home/index.js';
import GamePage from '../pages/game/index.js';

export default class Rotas extends React.Component {
    render() {
        return <>
            <Router>
                <Routes>
                    <Route path="/" element={<Home />} />
                    <Route path="/game" elememnt={<GamePage />} />
                    <Route path="*" element={<ErrorPage />} />
                </Routes>
            </Router>
        </>
    };
}

How to use Props to jQuery in React component

I hope you understand this simple example.

I tried to change the background color of my HTML element on first render by handling it in React Component with a bit help of jQuery.

This is the code inside my React Component (the props is passed from state of Parent Component):

class QuoteBox extends React.Component {
  constructor(props) {
    super(props)
  }
  
  
  componentDidMount() {
    $('#root').css('background-color', this.props.color); 
    $('#text').css('color', this.props.color);
    $('#author').css('color', this.props.color);
  }

  render() {   
    return (
      <div>
          <div id="quote-box" className="quote-box">
            <div className="quote">
              <span id="text" class="quote-text">{this.props.quote}</span>
            </div>
            <div id="author" className="quote-author">
              <span>- {this.props.author}</span>
            </div>
      </div>
    )
  }

The code inside componentDidMount() seem doesn’t recognize the this.props.color. But if change to $('#root').css('background-color', 'green'); it’s immediately change the background to green on first render.

But in render() it recognize another props.

So what did I do wrong? Is there a way to target HTML element using jQuery inside React?

what is error create-react-app Unexpected error. Please report it as a bug:

what is showing error showing on reactjs Aborting installation. Unexpected error. Please report it as a bug:?

Aborting installation.
    Unexpected error. Please report it as a bug:
    Error: spawn UNKNOWN
        at ChildProcess.spawn (node:internal/child_process:412:11)
        at Object.spawn (node:child_process:698:9)
        at spawn (D:ankitnode_modulescross-spawnindex.js:12:24)
        at D:ankitnode_modulescreate-react-appcreateReactApp.js:390:19
        at new Promise (<anonymous>)
        at install (D:ankitnode_modulescreate-react-appcreateReactApp.js:341:10)
        at D:ankitnode_modulescreate-react-appcreateReactApp.js:468:16
        at processTicksAndRejections (node:internal/process/task_queues:96:5) {
      errno: -4094,
      code: 'UNKNOWN',
      syscall: 'spawn'
    }
    
    Deleting generated file... package.json
    Deleting react-app/ from D:ankit
    Done.