I have a few functions and variables in one script, that’re not used in the script itself, but used elsewhere (in other scripts, or embedded in on* event attributes).
How do I tell ESLint not to report those as “defined but never used”?
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
I have a few functions and variables in one script, that’re not used in the script itself, but used elsewhere (in other scripts, or embedded in on* event attributes).
How do I tell ESLint not to report those as “defined but never used”?
I am using react-pdf and react-pdf/renderer in nextjs after creating the file and adding the code it works perfectly but when I make the production build it continues to make the build and never stops.
here is the code
import React from 'react';
import { Page, Text, View, Document, StyleSheet } from '@react-pdf/renderer';
const PDFGenerator = () => {
const styles = StyleSheet.create({
page: {
flexDirection: 'row',
backgroundColor: '#E4E4E4'
},
section: {
margin: 10,
padding: 10,
flexGrow: 1
}
});
return (
<Document>
<Page size="A4" style={styles.page}>
<View style={styles.section}>
<Text>Section #1</Text>
</View>
<View style={styles.section}>
<Text>Section #2</Text>
</View>
</Page>
</Document>
);
}
export default PDFGenerator;
and here I am using it
<PDFDownloadLink
document={<PDFGenerator/>}
fileName="recipe.pdf"
className="button-background w-full text-center text-color py-2 px-4
rounded mt-10">
{({blob, url, loading, error}) => (loading
? 'Loading document...'
: 'Download PDF')}
</PDFDownloadLink>
I am working on a Ruby on Rails project and using the Simple Form gem for my forms. I have a form where I need to change the collection of a select field based on the user’s previous answer to another field.
For example, if the user selects “Category A” in the first field, the second field should show options only related to “Category A” and if the user selects “Category B”, the second field should show options only related to “Category B”.
How can I achieve this functionality using Ruby on Rails and Simple Form gem?
<% if @property.ubicacion == 'Panama' %>
<div class="col-md-4"><%= f.input :localizacion, collection: ['Costa del Este' ] %></div>
<% elsif @property.ubicacion == 'Playas'%>
<div class="col-md-4"><%= f.input :localizacion, collection: ['Corronado' ] %></div>
<% else %>
<div class="col-md-4"><%= f.input :localizacion, collection: ['' ] %></div>
<% end %>
Problem in horizontal alignement of months in react-datepicker. Below image
shows 4 months in each row. Also, the months seems to be out of the allocaoted
width 309px. Trying to fit the months boxes within the allocated space having
3 months in a single row.
Library in used: react-datepicker;
Picture One
code
.react-datepicker__month-container {
float: left;
display: flex;
flex-direction: column;
width: 309px !important;
}
.react-datepicker__month-wrapper{
display: flex;
flex-direction: row;
}
.react-datepicker__month {
// margin: 4rem;
text-align: center;
display: flex;
flex-direction: column;
margin:auto;
padding-top: 10px;
}
.react-datepicker__month .react-datepicker__month-text,
.react-datepicker__month .react-datepicker__quarter-text {
// width: 4rem;
// margin: 2px;
text-align: left;
padding:0.6rem 2.4rem;
font-size: 14px;
}
Picture 2: : Though fits into the box, however, the alignment of months is not correct.
The requirement is to have
JAN FEB MAR
APR MAY JUN
...
After doing few tweaks, I can get this. I’d appreciate your help on this.
.react-datepicker__month-wrapper{
display: flex;
flex-direction: column; //-->updated
}
.react-datepicker__month {
// margin: 4rem;
text-align: center;
display: flex;
flex-direction: row; //-->Updated
margin:auto;
padding-top: 10px;
}
I have a large geo database of places of interest (POIs) and I am using MapboxGL to display it to the user. Based on the user input (filter and map location) I need to query the database and dynamically display the results to the user.
At the moment, I am using map.on('load',...) to add a source map.addSource(sourceId, ..)
Every time the user pans, zooms or filters the map I try to update the points on the map based on the data I receive from the query:
const source = map.getSource(sourceId) as GeoJSONSource;
if (source) {
source.setData({ type: 'FeatureCollection', features: features });
}
The load from the database is quick (and it is debounced) but it comes back with lots of points which results in a lag. This is because Mapbox computes every point each time setData is called which will result in a large CPU usage.
I tried to debounce the above method but since there might be a lot of points involved, there is still a big lag once the setData is called.
Note: I have two layers that cluster and display points. However, if I remove them the performance is comparable. They are are not the bottleneck and neither is the db query.
Is it possible to only append the data to the source rather than set it every time? Is there a better solution to dynamically visualise the points to the user?
Thanks!
I have a problem on filtering in React and MUI.
My problem if I add a row first and then filter after that, filter doesn’t work anymore.
Meanwhile if I don’t add a row and filter immediately it works.
CODESANDBOX —–> CODESANDBOX
const operatorFunctions = new Map([
[
"equals",
(dataValue, value) => dataValue?.toLowerCase() === value?.toLowerCase()
],
[
"starts_with",
(dataValue, value) =>
dataValue?.toLowerCase().startsWith(value?.toLowerCase())
]
]);
export const customFilter = (filter, data) => {
if (!data) return [];
return data.filter((row) =>
filter.every(({ value = "", operator = "", columns = "" }) => {
if (!value) return true;
if (!operatorFunctions.has(operator)) return false;
return operatorFunctions.get(operator)(row[columns]?.toString(), value);
})
);
};
I am implementing a simple react page with a counter counting down from 10 to 00.
I know that I can just use an if statement to do my code, but I was wondering, for efficiency, whether or not I can use multiple conditions in the same line for a ternary statement.
I tried searching this up, but no one on StackOverflow has asked this question. I’m not sure if it’s because it is so mindnumpingly dumb or if it’s just not good practice.
This is the code that I have thus far.
useEffect(()=>{
const timer = setInterval(() => {
count > 0 && setCount((data) => data - 1);
}, 1000);
// count < 0 && alert("done")
return () => clearInterval(timer);
},[count])
return (
<>
<Half className='left-side'>
<Wrap>
<p>{count.toString().padStart(2, '0')}</p>
<StyledButton onClick={plusBtnHandler}>+</StyledButton>
{/* <button onClick={minusBtnHandler}>-</button> */}
<StyledButton onClick={resetBtnHandler}>Reset</StyledButton>
<StyledButton onClick={stopBtnHandler}></StyledButton>
</Wrap>
</Half>
<Half className='right-side'>
<h1>Hello</h1>
</Half>
</>
)
I have a Bootstrap that I use to setup my camera
import Phaser from 'phaser'
export default class Bootstrap extends Phaser.Scene {
private camera: Phaser.Cameras.Scene2D.Camera | null = null
private zoomLevel: number = 1
constructor() {
super('Bootstrap')
}
private resizeCamera() {
// Responsively set camera size to window size
const width = window.innerWidth;
const height = window.innerHeight;
this.zoomLevel = (width > 600) ? 1.5 : 1;
this.cameras.main.zoom = this.zoomLevel
this.cameras.main.setSize(width, height);
this.cameras.main.setScroll(0, 0);
}
create() {
this.camera = this.cameras.main;
this.resizeCamera();
this.scale.on('resize', this.resizeCamera, this)
// launch GameScene and pass in the camera
this.scene.launch('GameScene', {
existingCamera: this.camera,
});
}
}
I am using this.scene.launch to run GameScene in parallel with Bootstrap
I am attempting to use the camera from Bootstrap in GameScene
import Phaser from 'phaser'
export default class GameScene extends Phaser.Scene {
private player: Phaser.Physics.Arcade.Sprite | null = null;
private camera: Phaser.Cameras.Scene2D.Camera | null = null
constructor() {
super('GameScene')
}
init(data: any) {
this.camera = data.existingCamera;
}
create() {
// Create player sprite and add physics
this.player = this.physics.add.sprite(1200, 1200, 'adam', 18)
this.camera?.setBounds(0, 0, 2400, 2400);
this.camera?.startFollow(this.player, true);
}
}
I am using the init function to get the camera from Bootstrap and use it for the camera in GameScene. I can console.log the this.camera in my create function and see that the scene parent is Bootstrap, but I don’t see the my camera following my player. What am I doing wrong?
I am trying to stream a video through php
And play the video via
<video width="100%" height="100%" src='streamvideo.php'>
</video>
The video is controlled by
range: bytes= 1000000 - 2000000
And increase it by a certain amount from the
bytes
include in header sent by the video
The video sends to php
With sending in the header as an example
range: bytes=2000000-
Which I noticed from this process is that
If I submit the broadcast to a specific place, it is not loaded in the video
The video is being uploaded
From the beginning to the beginning of the time you choose to present
How can I download only the part I selected from the video
iam trying to add to response header
Accept-Ranges: bytes
Content-Type: application/octet-stream
Content-Range: bytes startBytes-endBytes/videoSize
but still download video from beginning
like this:
const o = {
value: 'value',
label: 'label'
}
o === 'value' // true, direct access it return 'value'
o.label === 'label' // true
o.value === 'value' // true
rewriting o.toString does not satisfy me because i want it to work not only in console.log but anywhere.
I have 40 hours of video presentations to get through for my job. I want to speed up the playback rate of the presentations so I can save 20 hours of my life (and probably waste it doing something else ;).
I tried entering document.querySelector('video').playbackRate = 2.0; into the javascript console of my browser (Chrome), but it didn’t work. After playing around for about 5 minutes, I came to the horrifying discovery that the ‘video presentations’ were actually a massive jumble of HTML presentations with multiple embedded videos per ‘video presentation’. It seems like an auto playing power point presentation.
Is there a way to make the entire presentation run at double speed?
The only other solution I can think of is to “lie” to the webpage/HTML and make it “think” that time is moving twice as fast as it actually is. Is there a way to “overclock” a browser tab so that I can experience a webpage at double speed? (I put several words in double quotes, because I don’t know the specific/correct word).
I tried entering document.querySelector('video').playbackRate = 2.0; into the javascript console of my browser (Chrome), but it didn’t work.
const ethers = require("ethers");
const fs = require("fs-extra");
async function main() {
// http://127.0.0.1:7545
// Compile in our code
// Compile them seperately
const provider = new ethers.JsonRpcProvider("http://127.0.0.1:7545");
const wallet = new ethers.Wallet(
"0x578f756dd1e637bb78dff004cff8517f384f3be491cce3147e4a4f53bcbb8396",
provider
);
const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8");
const binary = fs.readFileSync("SimpleStorage_sol_SimpleStorage.bin", "utf8");
const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
console.log("Deploying, please wait...");
const contract = await contractFactory.deploy();
console.log(contract);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
The Error is:
JsonRpcProvider failed to `startup; retry in 1s
Error: connect ECONNREFUSED 127.0.0.1:7545
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
errno: -111,
code: ‘ECONNREFUSED’,
syscall: ‘connect’,
address: ‘127.0.0.1’,
port: 7545
I thought maybe port 7545 was closed so I ran the netstat command and it seems to be open and listening. I’m a little lost. Any help is much appreciated!
an error with the date selection. When I select a day in the calendar, the month is recorded and I cannot select more than 12. For example, I select January 12, but December 1 comes on the date. Help me please.
I think the whole problem is that I create a date and I need to make a date instance
function nextmonths() {
var start_multi = new Date(document.getElementById("date__start").value);
var next_date_unformatted = start_multi;
var next_date_formatted;
var next_date;
next_date = new Date(next_date_unformatted);
console.log(next_date)
next_date_formatted = next_date.toLocaleDateString()
document.getElementById("date__end").value = next_date_formatted;
dateSelected.innerHTML = 'С' + ' ' + start_multi + ' ' + 'по' + ' ' + next_date_formatted;
}
<link href="https://github.com/t1m0n/air-datepicker/blob/v3/dist/air-datepicker.css" rel="stylesheet" />
<script src="https://github.com/t1m0n/air-datepicker/blob/v3/dist/air-datepicker.js"></script>
<div class=" d-flex flex-column ">
<label for="" class=" insurance__program-label mb-lg-1 mb-1">Дата начала страховки:</label>
<input type="text" id="date__start" class="dates__form insurance__program-aria" placeholder="06.01.2023">
</div>
<div class="d-flex flex-column mt-lg-2 ">
<label for="" class="mt-lg-2 mt-3 insurance__program-label mb-lg-1 mb-1">Дата окончания страховки:</label>
<input type="text" id="date__end" class="dates__form insurance__program-aria" placeholder="12.06.2023">
</div>
I executed tsc and hoped it could be packaged in the dist directory, but nothing happened after execution.
Execute modemon and the program runs normally.
The following is the main information, please check
Contains package.json, tsconfgi, and basic file directories
I developed an application with nodejs, using ts and express, but there is no output when using tsc packaging. Help me
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "dist/app.js",
"scripts": {
"server": "nodemon",
"start": "node dist/app.js",
"dev": "nodemon src/app.ts",
"prebuild": "tslint -c tslint.json -p tsconfig.json --fix",
"build": "tsc",
"tsc": "tsc",
"build3": "webpack --config webpack.config.js",
"depend": "cmd.exe /c 'npx dependency-cruiser --format json > dependencies.json'"
},
"author": "",
"dependencies": {
"@babel/core": "^7.17.8",
"@babel/node": "^7.20.0",
"@types/jest": "^29.2.0",
"axios": "^0.21.1",
"babel-loader": "8.2.4",
"eslint": "^8.13.0",
"express": "^4.17.3",
"iconv-lite": "^0.6.3",
"json-loader": "^0.5.7",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"node-tesr": "0.0.9",
"puppeteer": "^13.7.0",
"sqlite3": "^5.1.2",
"ts-node": "^10.9.1"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "7.16.7",
"@babel/plugin-proposal-decorators": "7.17.8",
"@babel/preset-env": "7.16.11",
"@ffprobe-installer/ffprobe": "^1.4.1",
"@types/node": "^18.15.3",
"body-parser": "^1.20.0",
"cheerio": "^1.0.0-rc.10",
"cross-env": "7.0.3",
"dependency-cruiser": "^12.10.1",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-webpack-plugin": "^3.1.1",
"file-loader": "6.2.0",
"get-video-duration": "^4.0.0",
"log4js": "^6.4.6",
"node-ffprobe": "^3.0.0",
"request": "^2.88.2",
"tesseract.js": "^2.1.5",
"ts-loader": "^9.4.2",
"tsconfig-paths": "^4.1.2",
"tslint": "^6.1.3",
"typescript": "^4.9.5",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^5.76.1",
"webpack-cli": "^5.0.1"
}
}
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "dist",
"rootDir": ".",
"baseUrl": ".",
"paths": {
"@src/*": [
"./src/*"
],
"@base/*": [
"./*"
],
},
"lib": [
"es6",
"DOM"
],
"moduleResolution": "node",
"strict": false,
"sourceMap": true,
"skipLibCheck": true,
"allowJs": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": false,
"noImplicitAny": false,
"noEmit": true,
"experimentalDecorators": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": false,
"noImplicitUseStrict": true,
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
],
}
Project Directory
-server(root)
--src
---pages
----common
app.ts
--dist
--package.json
--tsconfig.json
I find a strange code from a opensource library, it has a video tag in an html page.
and a “timeupdate” listener added to video tag in javascript.
It has a formula I guess to control the frequence updating video progress bar, which I really dont’ understand how it work. maybe it’s a bug?
Math.abs(video.currentTime – lastTime) % video.duration >= 1
var lastTime - 0;
video.addEventListener("timeupdate", function (e) {
e.stopPropagation(),
Math.abs(video.currentTime - lastTime) % video.duration >= 1
&&
(updateProgressBar(),
(lastTime = 1e3 * video.currentTime))
}
trigger timeupdate every 100ms, its output:
timeupdate currentTime:0.10000000149011612, lastTime:0, duration:20, res:0.10000000149011612
timeupdate currentTime:0.20000000298023224, lastTime:0, duration:20, res:0.20000000298023224
timeupdate currentTime:0.30000001192092896, lastTime:0, duration:20, res:0.30000001192092896
timeupdate currentTime:0.4000000059604645, lastTime:0, duration:20, res:0.4000000059604645
timeupdate currentTime:0.5, lastTime:0, duration:20, res:0.5
timeupdate currentTime:0.6000000238418579, lastTime:00, duration:20, res:0.6000000238418579
timeupdate currentTime:0.699999988079071, lastTime:00, duration:20, res:0.699999988079071
timeupdate currentTime:0.800000011920929, lastTime:00, duration:20, res:0.800000011920929
timeupdate currentTime:0.8999999761581421, lastTime:00, duration:20, res:0.8999999761581421
timeupdate currentTime:1, lastTime:0, duration:20, res:1
timeupdate currentTime:1.100000023841858, lastTime:1000 duration:20, res:18.899999976158142
timeupdate currentTime:1.2000000476837158, lastTime:1100.000023841858, duration:20, res:18.800023794174194
timeupdate currentTime:1.2999999523162842, lastTime:1200.0000476837158, duration:20, res:18.700047731399536
timeupdate currentTime:1.399999976158142, lastTime:1299.9999523162842, duration:20, res:18.599952340126038