Weird behaviour in localhost:3000 after publishing the site on Github Pages?

Hey there I’ve a trouble after publishing my portfolio website online into the Github pages.
before the published it works just fine but when I publish this and then I want to update some data into website I see all the website visual-effect fully spoiled.

I also create another folder and bring the all files and code into new folder but it also look like the same. Please help me as soon as.

local host:3000
error into the “console” localhost broken img-1 , fully broken styles and fonts.

Error while trying to use the following icon from the Manifest: http://localhost:3000/portfolio/logo192.png (Download error or resource isn’t a valid image)

Here the published website link here it look like fine into github how that should be look like

Source code
on github

Thanks in Advanced

app does not connect to firebase emulators but connects to production

I have a react app connected to firebase project.

On running firebase emulators:start I get the following output.

firebase emulators:start
i  emulators: Starting emulators: auth, functions, firestore, hosting, storage
⚠  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: database, pubsub
✔  functions: Using node@16 from host.
i  firestore: Firestore Emulator logging to firestore-debug.log
i  hosting: Serving hosting files from: build
✔  hosting: Local server: http://localhost:5011
i  ui: Emulator UI logging to ui-debug.log
i  functions: Watching "/Users/{username}/{app}/functions" for Cloud Functions...
✔  functions[us-central1-addFirestoreEvents]: firestore function initialized.

┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://localhost:4000                │
└─────────────────────────────────────────────────────────────┘

┌────────────────┬────────────────┬─────────────────────────────────┐
│ Emulator       │ Host:Port      │ View in Emulator UI             │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Authentication │ localhost:9099 │ http://localhost:4000/auth      │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Functions      │ localhost:5001 │ http://localhost:4000/functions │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Firestore      │ localhost:8080 │ http://localhost:4000/firestore │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Hosting        │ localhost:5011 │ n/a                             │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Storage        │ localhost:9199 │ http://localhost:4000/storage   │
└────────────────┴────────────────┴─────────────────────────────────┘
  Emulator Hub running at localhost:4400
  Other reserved ports: 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
 
i  hosting: 127.0.0.1 - - [27/Mar/2022:11:12:53 +0000] "GET / HTTP/1.1" 200 584 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36"
i  hosting: 127.0.0.1 - - [27/Mar/2022:11:12:53 +0000] "GET /static/js/main.60d5b53b.js HTTP/1.1" 200 928509 "http://localhost:5011/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36"
i  hosting: 127.0.0.1 - - [27/Mar/2022:11:12:53 +0000] "GET /favicon.ico HTTP/1.1" 200 15406 "http://localhost:5011/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36"
i  hosting: 127.0.0.1 - - [27/Mar/2022:11:13:30 +0000] "GET /manifest.json HTTP/1.1" 200 494 "http://localhost:5011/enter" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36"
i  hosting: 127.0.0.1 - - [27/Mar/2022:11:13:30 +0000] "GET /static/js/main.60d5b53b.js.map HTTP/1.1" 200 6816096 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36"

In my index function, I initialize the app like this

let fapp
if (!getApps().length) {
  // if (window.location.hostname === 'localhost') {
  //   initializeApp({})
  // } else {
  //   fapp = initializeApp(firebaseConfig)
  // }
  fapp = initializeApp({})
}

// Auth exports
export const auth = getAuth()
connectAuthEmulator(auth, 'http://localhost:9099')

// Firestore exports
// export const db = getFirestore(fapp)
export const db = getFirestore()
connectFirestoreEmulator(db, 'localhost', 8080)

Now When I go to the hosting URL ‘https://localhost:5011″ and try to login.(signInAnonymously)
It is using the production config and not the emulator.
even the db is getting connected to production.

OS details
Mac version 12.3

node version 16.4.0
firebase cli version 10.5.0
npm version 8.3.0

Javascript/Typescript: Check if Combination of cost and value exists

If i have a list of choices that each have a cost and a value,
how can i check if a combination of choices exists, where a given value is exactly met, but a max cost is not overceeded?

Here is an example:

const VAL      = 10;
const MAX_COST = 19;

let choices = [
    [{cost: 10, val: 3}, {cost:8, val: 2}, {cost: 6, val:  1}], // From every line, only one can be chosen
    [{cost: 10, val: 3}, {cost:4, val: 3}, {cost: 6, val:  3}],
    [{cost: 7, val: 5}, {cost:4, val: 3}, {cost: 11, val:  3}],
    [{cost:4, val: 3}, {cost: 11, val:  3}, {cost: 1, val: 1},],
];

In this example the anwser would be yes, because {cost: 10, val: 3}, {cost:4, val: 3}, {cost:4, val: 3}, {cost: 1, val: 1} can be chosen, adding up to a total cost of 19 and having a combined value of exactly 10.

In the real usecase there will be up to 3000 choices that have to be made, so bruteforcing is not viable.

Sorry for my bad English.

Why are functions run in the module script file not in the window object?

The script file embedded directly in the HTML file, the functions contained in the window object. We can check with the following code.

    for(let i in window)
    {
        if ((typeof window[i]).toString() === "function" && !window[i].toString().includes("[native code]"))
        {
            console.log(i);
            console.log(window[i]);
            console.log("nn");
        }
    }

enter image description here

But when I run a function indirectly by importing it from module why isn’t it in there?
This is my file structure.

 1. index.html
 2. script.js
 3. moduleScript.js
 4. ModuleScript
    - moduleScript01.js
    - moduleScript02.js

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Event Listener</title>
    <script src="moduleScript.js" type="module"></script>s
    <script src="script.js"></script>
</head>
<body>
    <script type="module" defer>
        import * as moduleScript from "./moduleScript.js";
        
        console.log(moduleScript.moduleScript01.Level01(1,2));
        console.log(moduleScript.moduleScript02.Level02(1,2, 3));
        console.log("nn");
        
        for(let i in window)
        {
            if ((typeof window[i]).toString() === "function" && !window[i].toString().includes("[native code]"))
            {
                console.log(i);
                console.log(window[i]);
                console.log("nn");
            }
        }
        
        
    </script>
</body>
</html>

script.js

function Level01 (a, b)
{
    return a + b;
}

function Level02 (a, b, c)
{
    return Level01(a,b) - c;
}

function Level03 (a, b)
{
    return  Level02(a,b, 1) * 5;
}

function print ()
{
    console.log("Hello world");
}

moduleScript.js

export * as moduleScript01 from "./ModuleScript/moduleScript01.js";
export * as moduleScript02 from "./ModuleScript/moduleScript02.js";

moduleScript01.js

function Level01 (a, b)
{
    return a + b;
}

export
{
    Level01
}

moduleScript02

function Level02 (a, b, c)
{
    return Level01(a,b) - c;
}

export
{
    Level02
}

Add image/button to React bootstrap table cell based on value of cell

I have a bootstrap table with these columns: name, expDate, stoplight. The value in the stoplight column is based on the date in the expDate column. If the expDate is within 7 days of today it’s red, between 7 and 21 days it’s Yellow, and otherwise Green, see logic below. If all I want is to display the words, Red, Yellow, Green it works fine. The part where I’m getting stuck is I want to display a ‘stoplight’, a red or yellow or green circle/button in the column. I have a working css but I cannot figure out how to apply a custom format to a specific cell. Any help is appreciated.

    <BootstrapTable
      keyField="street"
      columns={columns}
      data={rows}
      hover
      rowEvents={tableRowEvents}
      bordered={true}
      rowStyle={rowStyle}
    />

const Stoplight = (daysToExpDate) => { 
      if (daysToExpDate <= 7) {
        return "Red"; 
      } else if (daysToExpDate > 30) {
        return "Green"; 
      } else {
        return "Yellow"; 
      }
    };

And here is my rudimentary css that works by itself but not in the table.

.redlight {
  border-radius: 50%;
  color: red;
  background-color: red;
}
.greenlight {
  border-radius: 50%;
  color: green;
  background-color: green;
}
.yellowlight {
  border-radius: 50%;
  color: yellow;
  background-color: yellow;
}

This row style highlights the entire row, not just the cell in question.

const rowStyle = (row, rowIndex) => {
    const style = {};
    if (row.stoplight === "Red") {
      style.backgroundColor = "Red";
    } else if (row.stoplight === "Green") {
      style.backgroundColor = "Green";
    } else {
      style.backgroundColor = "Yellow";
    }

    if (rowIndex > 2) {
      style.fontWeight = "normal";
      style.color = "black";
    }

    return style;
  };

how to convert binary to string (big endian) format

ı have a tcp socket and ı try to get binary data from there and convert it to string by node js

here is my code

const Net = require('net');
const port = 4000;
const host = '0.0.0.0';

const client = new Net.Socket();
client.connect({ port: port, host: host }), function() {
    console.log('TCP connection established with the server.');

    client.write('Hello, server.');
};
client.on('data', function(chunk) {
    console.log(chunk);
    
    client.end();
});

client.on('end', function() {
    console.log('Requested an end to the TCP connection');
}); 

and the output is

<Buffer 82 44 53 53 76 57 37 56 4c 6d 62 ed 14 00 00 00 00 00 00 00 00 00 00 00 00 4c 05 e5 58 00 00 00 00 e1 8f 80>

requestFullscreen() not working with modifier keys inside keyup event

I want to toggle fullscreen on an element, but the requestFullscreen() function isn’t working, despite the fact it is called while responding to user interaction (MDN).
I can’t find out why it doesn’t work with Modifier Keys (MDN).

Here’s the snippet from my fiddle:

document.addEventListener("keyup", (e) => {
  e.preventDefault();
  if (document.fullscreenElement)
    return document.exitFullscreen()
  document.body.firstElementChild.requestFullscreen();  // Fails on CTRL, SHIFT, ALT ...
});

I also don’t understand how it does work if you press a mouse button or any other key press between each toggle with CTRL, SHIFT, or ALT keys. For example, this would work: Left Mouse Click, Shift, Shift, Left Mouse Click, Shift, Shift…

I need this to work for my Chrome Extension, so maybe there is a workaround? Thanks.

Requesting text from a table row using jquery returns ”

I started using jQuery around a week ago and i wanted to do something like a search from an existing table.
when calling .text() from any row it shows and empty string ” making it impossible to compare searched string to the existing ones in the table.

HTML:

<tbody id="test">
    <tr>
        <td>example</td>
        <td>1</td>
    </tr>
    <tr>
        <td>example</td>
        <td>2</td>
    </tr>   
    <tr>
        <td>example</td>
        <td>3</td>
    </tr>   
    <tr>
        <td>example</td>
        <td>4</td>
    </tr>
</tbody>

jQuery:

`$(document).ready(() => {
    $('#test tr').filter(() => {
        console.log($(this).text())
    });
}):`

This returns 4 instances of ”

How do I find and implement the most efficient pathway from a list of stations in graph theory?

Really need help here. I am building an app in react-native that shows which bus to catch after choosing starting station and ending station.

I have a list of bus data with its routes(stations). In JSON format to be precise.

It really gets hard when it comes to finding the best pathway to get to the ending station. In which station to drop and change the bus. So many possibilities.

An example:

   "11100060": {
    "end_time_at_start_point": "21:56",
    "station_list": [
        {
            "station_name": "65-р дэлгүүр",
            "station_id": "000000067",
            "longitude": 106.79329,
            "station_seq": 1,
            "exist_bus": "N",
            "latitude": 47.92013
        },
        {
            "station_name": "Толгойт Шөнийн дэлгүүр",
            "station_id": "000000069",
            "longitude": 106.7881,
            "station_seq": 2,
            "exist_bus": "Y",
            "latitude": 47.91983
        },
        {
            "station_name": "ТОЛГОЙТЫН ЭЦЭС",
            "station_id": "000000071",
            "longitude": 106.78174,
            "station_seq": 3,
            "exist_bus": "N",
            "latitude": 47.91878
        },
        {
            "station_name": "Цэргийн хотхон",
            "station_id": "000000072",
            "longitude": 106.7824,
            "station_seq": 4,
            "exist_bus": "N",
            "latitude": 47.91277
        },
        {
            "station_name": "Нефть хотхон",
            "station_id": "000000024",
            "longitude": 106.78749,
            "station_seq": 5,
            "exist_bus": "N",
            "latitude": 47.91047
        },
        {
            "station_name": "10 буудал",
            "station_id": "000000022",
            "longitude": 106.79976,
            "station_seq": 6,
            "exist_bus": "Y",
            "latitude": 47.90955
        },
        {
            "station_name": "5 Шар",
            "station_id": "000000020",
            "longitude": 106.81484,
            "station_seq": 7,
            "exist_bus": "N",
            "latitude": 47.90965
        },
        {
            "station_name": "Монгол хюндэй киа компани",
            "station_id": "000000018",
            "longitude": 106.82659,
            "station_seq": 8,
            "exist_bus": "N",
            "latitude": 47.91061
        },
        {
            "station_name": "32-р байр",
            "station_id": "000000011",
            "longitude": 106.83359,
            "station_seq": 9,
            "exist_bus": "N",
            "latitude": 47.91113
        },
        {
            "station_name": "Хар хорин",
            "station_id": "000000009",
            "longitude": 106.84054,
            "station_seq": 10,
            "exist_bus": "N",
            "latitude": 47.91166
        },
        {
            "station_name": "Цамбагарав",
            "station_id": "000000006",
            "longitude": 106.84736,
            "station_seq": 11,
            "exist_bus": "N",
            "latitude": 47.9122
        },
        {
            "station_name": "Саппоро",
            "station_id": "000000004",
            "longitude": 106.85283,
            "station_seq": 12,
            "exist_bus": "N",
            "latitude": 47.91256
        },
        {
            "station_name": "3-р эмнэлэг",
            "station_id": "000000147",
            "longitude": 106.86022,
            "station_seq": 13,
            "exist_bus": "N",
            "latitude": 47.91305
        },
        {
            "station_name": "10-р хороолол",
            "station_id": "000000149",
            "longitude": 106.86824,
            "station_seq": 14,
            "exist_bus": "Y",
            "latitude": 47.91361
        },
        {
            "station_name": "25-р Эмийн сан",
            "station_id": "000000151",
            "longitude": 106.87949,
            "station_seq": 15,
            "exist_bus": "N",
            "latitude": 47.91437
        },
        {
            "station_name": "Богд ар хороолол",
            "station_id": "000001403",
            "longitude": 106.88384,
            "station_seq": 16,
            "exist_bus": "N",
            "latitude": 47.91128
        },
        {
            "station_name": "Вокзал",
            "station_id": "000000671",
            "longitude": 106.8851,
            "station_seq": 17,
            "exist_bus": "N",
            "latitude": 47.90904
        },
        {
            "station_name": "Барс худалдааны төв",
            "station_id": "000000180",
            "longitude": 106.89058,
            "station_seq": 18,
            "exist_bus": "Y",
            "latitude": 47.90896
        },
        {
            "station_name": "Монгол эм импекс",
            "station_id": "000001408",
            "longitude": 106.90107,
            "station_seq": 19,
            "exist_bus": "Y",
            "latitude": 47.90843
        },
        {
            "station_name": "Жигүүр гранд",
            "station_id": "000000284",
            "longitude": 106.90996,
            "station_seq": 20,
            "exist_bus": "Y",
            "latitude": 47.90814
        },
        {
            "station_name": "Соёлж худалдааны төв",
            "station_id": "000000312",
            "longitude": 106.92907,
            "station_seq": 21,
            "exist_bus": "N",
            "latitude": 47.90809
        },
        {
            "station_name": "Говь хангай",
            "station_id": "000001409",
            "longitude": 106.9388,
            "station_seq": 22,
            "exist_bus": "Y",
            "latitude": 47.90795
        },
        {
            "station_name": "Нарантуул зах",
            "station_id": "000000408",
            "longitude": 106.95281,
            "station_seq": 23,
            "exist_bus": "Y",
            "latitude": 47.90782
        },
        {
            "station_name": "Ахмадын хороолол",
            "station_id": "000000410",
            "longitude": 106.96013,
            "station_seq": 24,
            "exist_bus": "N",
            "latitude": 47.90784
        },
        {
            "station_name": "БЗД 13-р хороо",
            "station_id": "000000411",
            "longitude": 106.96828,
            "station_seq": 25,
            "exist_bus": "N",
            "latitude": 47.90771
        },
        {
            "station_name": "Номин худалдааны төв",
            "station_id": "000001161",
            "longitude": 106.97534,
            "station_seq": 26,
            "exist_bus": "N",
            "latitude": 47.91058
        },
        {
            "station_name": "Чулуун овоо",
            "station_id": "000000381",
            "longitude": 106.98419,
            "station_seq": 27,
            "exist_bus": "Y",
            "latitude": 47.91229
        },
        {
            "station_name": "Шөнийн дэлгүүр",
            "station_id": "000000383",
            "longitude": 106.98935,
            "station_seq": 28,
            "exist_bus": "Y",
            "latitude": 47.91256
        },
        {
            "station_name": "Хууль сахиулах их сургууль",
            "station_id": "000000385",
            "longitude": 106.99747,
            "station_seq": 29,
            "exist_bus": "N",
            "latitude": 47.91299
        },
        {
            "station_name": "Ботаник",
            "station_id": "000000579",
            "longitude": 107.00088,
            "station_seq": 30,
            "exist_bus": "N",
            "latitude": 47.91286
        }
    ],
    "result_code": "001",
    "line_name": "Ч:6 (65-р дэлгүүр-Ботаник)",
    "line_id": "11100060",
    "weekday_interval": 3,
    "start_time_at_end_point": "06:25",
    "holiday_interval": 5,
    "start_time_at_start_point": "06:30",
    "line_type": "",
    "end_time_at_end_point": "23:11"
},

Invalid hook call – Use NextJs Image/Link Component in own React Component Library

I am working on a react components library to use in a NextJS project. For some of the components I want to use the Image or Link component from NextJS. This causes the following error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

I am bundling my components with Rollup.

rollup.config.js

import typescript from 'rollup-plugin-typescript2';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import packageJson from './package.json';
import postcss from 'rollup-plugin-postcss';

export default {
  input: 'src/index.ts',
  output: [
    {
      file: packageJson.main,
      format: 'cjs',
      sourcemap: true,
    },
    {
      file: packageJson.module,
      format: 'esm',
      sourcemap: true,
    },
  ],
  plugins: [
    peerDepsExternal(),
    resolve(),
    commonjs(),
    typescript({
      tscConfig: './tsconfig.json',
      exclude: ['**/*.stories.tsx', '**/*.test.tsx'],
      declarationDir: 'dist',
      declaration: true,
    }),
    postcss({
      extract: false,
      modules: true,
      use: ['sass'],
    }),
  ],
};

Thanks in advance!

How to make variables accessible across multiple get requests in express? And is there a better way to code this?

I have the following get request where I call a bunch of data and pass it through to my EJS view.

router.get('/currentrentals', ensureAuthenticated,  async (req, res) => {

const companies = await Company.getCompanies();
const barges = await Barge.getBarges();
const parishes = await Parish.getParishes();
const states = await State.getStates();
const pickupdropoff = await PickupDropoff.getPickupDropoff();
var notifications = await Notification.getNotifications();
JSON.stringify(barges);
JSON.stringify(companies);
JSON.stringify(parishes);
JSON.stringify(states);
JSON.stringify(pickupdropoff);
JSON.stringify(notifications);
var notifications =  await notifications.sort((a, b) => b.id - a.id).slice(0,3);

res.render('currentrentals', {
    name: req.user.name, companies: companies, barges: barges, parishes: parishes, states: states, pickupdropoff : pickupdropoff, notifications : notifications
});
}
);

Two questions:

  1. I have multiple get requests that requires the same information. Is there a way to make this data available across the entirety of my site, so I don’t have to rewrite this for each get path?

  2. Is there a more succinct way to write the existing code I have? Perhaps looping through them or something of the sort? Simply for learning purposes.

The code currently works as-is.

Thanks!

Javascript – Find a specfic property in object by value which is a list of strings

I have to find a property in array of objects by value which is a list of strings.

For example I have someting like this:

const colors ={
colors-1: [{color: 'blue'}], 
colors-2: [{color: 'gray'}, {color: 'red'}], 
colors-3: [{color: 'white'}]
}

And I want to get for example property colors-2 by string which is inside array value.

Something like this:

findPropertyByValue(colors, 'red')

And output:

'colors-2'

Could You show me how to achieve this?
Thank You.