As the title says: any suggestions? or am I forced to work with a book for each in hand to make the translations on the fly?
Category: javascript
Category Added in a WPeMatico Campaign
How to merge multiple images using javascript
How to merge images using javascript than have over 5 images ?
I am merging multiple images using javascript using canvas and composite function.
The script can be applied when images is below or equal to 5. But when it is more than 5 images, the script fail.
The script is volatile because sometimes it is not draw / merge all images. Sometimes only draw 1 image.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Merge Images using Composite</title>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// Adjust the canvas size as per the image dimensions
canvas.width = 800; // Example width
canvas.height = 600; // Example height
const images = [
'image1.png',
'image2.png',
'image3.png',
'image4.png',
'image5.png'
];
function loadImages(sources, callback) {
let loadedImages = 0;
const imageElements = [];
sources.forEach((src, index) => {
const img = new Image();
img.src = src;
img.onload = () => {
loadedImages++;
imageElements[index] = img;
if (loadedImages === sources.length) {
callback(imageElements);
}
};
});
}
function mergeImages(images) {
images.forEach((img, index) => {
// Optional: adjust the position and size of each image if necessary
ctx.globalCompositeOperation = 'source-over';
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
});
}
loadImages(images, mergeImages);
</script>
</body>
</html>
Incompatible wire encryption levels requested on client and server firebird 5.0 + node
I have been having this issue with my project.
I’m currently using react + node and decided to use firebird. Everything works fine until i have to call the database function, then i receive the following error: “Incompatible wire encryption levels requested on client and server”
I already tried disabling, enabling and changing the firebird.conf file, but nothing works
Here’s my database.js code:
~~~const options = {~~~
~~~ host: 'localhost',~~~
~~~ port: 3050,~~~
~~~ database: './MEUBANCO.FDB',~~~
~~~user: 'SYSDBA',~~~
~~~ password: 'masterkey',~~~
~~~wireCrypt: 'Disabled' // Desativar criptografia~~~
~~~};~~~
I tried changing #AuthClient to srp and #WireCrypt to enabled/disabled on the firebird.conf file
Airtable API request (with Axios) into HTML datalist? [duplicate]
I am trying to get a list of items from an Airtable base and load it into an HTML datalist so a user typing in a text input has a list of options to choose from. I am using Axios to retrieve the data from Airtable (it is the only method I’ve tried so far that has actually worked).
Here’s what I have right now.
HTML:
<body>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.16.2/axios.min.js"></script>
<div>
<form action="/form-handling-page" method="post">
<datalist id="members"></datalist>
<input type="text" id="name" list="members"/>
<script>
const key = "API-KEY";
const url = "https://api.airtable.com/v0/BASE-ID/TABLE-NAME?PARAMS"
var names = Array();
axios.get(url, {
headers: { Authorization: "Bearer " + key }
}).then(function(response) {
for (let record of response.data.records) {
names.push(record.fields.FIELD);
console.log(names); // an array full with what you would expect it to have
}
});
console.log(names); // logs an empty array
mems = document.getElementById("members");
for(var name in names) {
var opt = document.createElement("option");
opt.value = name;
mems.appendChild(opt);
}
</script>
</form>
</div>
</body>
I don’t really understand how names can be populated inside the .then(...) segment, but then suddenly become empty outside. The datalist is also empty each time. This is my first time doing more than just a static site. Ideally, I just need a way to actually populate names with the elements in the array, and the datalist part should be relatively straightforward.
Thanks in advance!
Paged.js no working anymore – “PagedPolyfill is not defined”
I’m using Paged.js to format and print an HTML-based document as a PDF. It was working fine until today, but now I’m getting the following errors in the browser console:
javascript
Uncaught SyntaxError: Cannot use import statement outside a module (at paged.js:1:1)
Uncaught ReferenceError: PagedPolyfill is not defined
Here’s how I was loading the library:
html
<script src="https://unpkg.com/pagedjs/dist/paged.polyfill.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
if (typeof Paged !== "undefined") {
Paged.polyfill();
} else {
console.error("Paged.js did not load correctly.");
}
});
</script>
My HTML file is opened directly from the desktop (without a local server), so I need a solution that works in this context.
What I’ve tried:
- Checking if paged.polyfill.js is accessible via the URL – it loads fine.
- Testing in different browsers (Chrome, Edge, Firefox) – same issue.
- Attempting to use a locally downloaded version of the script – still no luck.
Has anyone else encountered this issue recently? Is there a workaround or an alternative way to integrate Paged.js in a standalone HTML file?
Thanks in advance!
How to persist the section in firebase authentication in the web?
import { initializeApp } from 'firebase/app';
import { getAuth, browserSessionPersistence, connectAuthEmulator } from 'firebase/auth';
import { getFirestore, connectFirestoreEmulator } from 'firebase/firestore';
import { connectFunctionsEmulator, getFunctions } from 'firebase/functions';
import { connectStorageEmulator, getStorage } from 'firebase/storage';
import { emulators, functions as functionsConfig } from '@/../../firebase.json';
const firebaseConfig = {
apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
storageBucket: import.meta.env.VITE_FIREBASE_STORAGE_BUCKET,
messagingSenderId: import.meta.env.VITE_FIREBASE_MESSAGING_SENDER_ID,
appId: import.meta.env.VITE_FIREBASE_APP_ID,
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
auth.setPersistence(browserSessionPersistence);
export { auth };
export const firestore = getFirestore(app);
I’m trying to persist the section of the user logged in to Firebase, but when I reload the page, the user is logged out (session ends) and returns to the login screen, but according to the documentation the browserSessionPersistence does exactly what I need:
Indicates that the state will only be kept in the current session or tab and will be deleted when the tab or window in which the user authenticated is closed. Applies only to web apps.
Then, when I reload the page, I should still be on the “Once logged in” screen, but it goes back to the login screen. How can this be resolved?
HTTP Error 405: GET Request Instead of POST in C#/.NET Web App with AWS SNS and DynamoDB Integration
I have a C#/.NET web app hosted on AWS. I am trying to add a feature where a customer enters their phone number and a code to receive a free product is sent to it. I’m using AWS SNS and DynamoDB. I am testing it on a localhost. The code I have written is below.
[HttpPost] // Ensures this action is for POST requests**
[Route("Home/FreeCoffee")]
public async Task<IActionResult> FreeCoffee([FromBody] PhoneNumberRequest request)
{
if (string.IsNullOrEmpty(request.PhoneNumber))
{
return BadRequest(new { message = "Phone number is required." });
}
string dateKey = DateTime.UtcNow.ToString("yyyy-MM-dd") + "_Free1";
// Check if the offer already exists for this user today
var existingOffer = await _db.LoadAsync<OfferCode>(request.PhoneNumber, dateKey);
if (existingOffer != null)
{
return Ok(new { message = $"Offer already issued: {existingOffer.Code}" });
}
// Generate new offer code
var newCode = GenerateOfferCode();
var offer = new OfferCode
{
PhoneNumber = request.PhoneNumber,
OfferDateOfferType = dateKey,
Code = newCode,
OfferType = "Free1",
Used = false,
ExpirationDate = DateTimeOffset.UtcNow.AddHours(24).ToUnixTimeSeconds() // Expires in 24 hours
};
// Save to DynamoDB
await _db.SaveAsync(offer);
// Send SMS via SNS
var message = $"Your offer code is: {newCode}. Use it before midnight!";
await _snsClient.PublishAsync(new PublishRequest
{
Message = message,
PhoneNumber = request.PhoneNumber
});
return Ok(new { message = $"Offer sent to {request.PhoneNumber}" });
}
document.getElementById("codeForm").addEventListener("submit", async function (event) {
event.preventDefault(); // Prevent form from making a GET request
const phoneNumber = document.getElementById("phoneNumber").value;
if (!phoneNumber) {
alert("Phone number is required!");
return;
}
try {
const response = await fetch('/Home/FreeCoffee', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ phoneNumber: phoneNumber })
});
if (!response.ok) {
const result = await response.json();
alert("Error: " + result.message);
} else {
const result = await response.json();
alert("Offer sent to: " + phoneNumber);
}
} catch (error) {
alert("Error: " + error.message);
}
});
The error I am getting is HTTP error 405. I have checked the developer tools network tab and found this:
Request Method: GET
Status Code:
405 Method Not Allowed
Remote Address:
[::1]:5043
Referrer Policy:
strict-origin-when-cross-origin
allow: POST
content-length: 0
date: Wed, 19 Mar 2025 23:25:07 GMT
server: Kestrel
If I am understanding this correctly, I am using a GET request but a POST request is expected. I have been trying to remedy this, without success. Can anyone see what I am doing wrong? I would appreciate any help.
Stack Overflow is a technical high-DA forum posting site [duplicate]
m trying to remove the button from the search form in Olivero theme in Drupal (10.4.3)
I’m using exposed form in a block to power the search. I’d like to simply remove the button.
It currently looks like this, I’d like for it to look like this.
I’m not sure where to find the code to remove the button. Any assistance would be great! Thank you!
How to replace string in 2nd occurrence with javascript? [duplicate]
Lets say my example string looks like this:
[TABS]
[SLIDE_HEADER]Title[/SLIDE_HEADER]
[SLIDE]
[CODE]
Link1
Link2
Link3
[/CODE]
[/SLIDE]
[SLIDE_HEADER][COLOR=rgb(65, 168, 95)]Title[/COLOR][/SLIDE_HEADER]
[SLIDE]
[CODE]
Link1
Link2
Link3
Link4
[/CODE]
[/SLIDE][/TABS]
I want to replace the 2nd [/CODE] with Link5n[/CODE] how can I do this? cause my script is replacing the first [/CODE] which I don’t want it to happen
const str = `[TABS]
[SLIDE_HEADER]Title[/SLIDE_HEADER]
[SLIDE]
[CODE]
Link1
Link2
Link3
[/CODE]
[/SLIDE]
[SLIDE_HEADER][COLOR=rgb(65, 168, 95)]Title[/COLOR][/SLIDE_HEADER]
[SLIDE]
[CODE]
Link1
Link2
Link3
Link4
[/CODE]
[/SLIDE][/TABS]`;
const result = str.replace('[/CODE]','Link5n[/CODE]')
console.log(result)
Need this 10k followers
Need this 10k followers
Need have this followers, Just a need followers…! so_ha_g______72?igsh=eTc1YmczNW01b3l0
Need this 10k followers
Need have this followers, Just a need followers…! so_ha_g______72?igsh=eTc1YmczNW01b3l0
Need this 10k followers
Need have this followers, Just a need followers…! so_ha_g______72?igsh=eTc1YmczNW01b3l0
Unresolved function or method on() and say() in WebStorm with tmi.js
i am currently developing a twitch bot and use the tmi.js module in node.js
const tmi = require('tmi.js');
Then i used the code from the documentation like this:
const client = new tmi.Client({
identity: {
username: 'twitch_user',
password: 'twitch_oauth'
},
channels: [ 'twitch_channel' ]
});
And finally a test like this:
client.on('message', (ch, tags, message, self) => {
if (self) return;
client.say(ch, 'This is a test');
});
It all works, but WebStorm gives me the following message:
Unresolved function or method on()
Unresolved function or method say()
The functions/methods definetly exist and are working. I think the problem here might be how these methods are created in tmi.js and they could be created dynamically.
So, is there a way to tell WebStorm that this exists or something like that?
Thanks!
How to generate a Cartesian coordinate grid?
I want to generate a coordinate grid that looks like this (except it doesn’t need the points joining):
However, my output is this. Although it goes from -6 to 6, it doesn’t put the axes in the plus shape, which I’m aiming for.
How can I correct it? I’m using react-chartjs-2 (Chart.js) but I am open to any library.
Code:
import React from "react";
import { Scatter } from "react-chartjs-2";
import {
Chart as ChartJS,
LinearScale,
PointElement,
Tooltip,
Legend
} from "chart.js";
ChartJS.register(LinearScale, PointElement, Tooltip, Legend);
const data1 = {
datasets: [
{
label: "Sample Data",
data: [
{ x: -5, y: -5 },
{ x: -3, y: -2 },
{ x: -1, y: -1 },
{ x: 0, y: 0 },
{ x: 2, y: 3 },
{ x: 4, y: 5 }
],
backgroundColor: "red",
pointRadius: 5
}
]
};
const options = {
responsive: true,
maintainAspectRatio: false,
scales: {
x: {
type: "linear",
position: "bottom",
min: -6,
max: 6,
grid: {
color: "gray",
drawTicks: false,
drawBorder: true,
lineWidth: 2
},
ticks: {
stepSize: 1,
color: "black"
},
border: {
display: true,
color: "black"
}
},
y: {
min: -6,
max: 6,
grid: {
color: "gray",
drawTicks: false,
drawBorder: true,
lineWidth: 2
},
ticks: {
stepSize: 1,
color: "black"
},
border: {
display: true,
color: "black"
}
}
},
plugins: {
legend: {
display: false
}
}
};
Render the element:
<div style={{ width: "500px", height: "500px" }}><Scatter data={data1} options={options} /></div>;
Is there a ready-made browser player that can join fragmented mp4 files on the fly?
I have several fmp4 files (recorded with Mediamtx). The files are large. Is there a ready-made js library that can seamlessly play these files with a working seeking function? My attempts to make an hls playlist were unsuccessful because the segments were huge and took a long time to load with the client player. So far, the only solution is manual substitution of fragments in ‘mediasource’, but I hope to find a ready or semi-ready solution.
Unable to redirect JavaScript URL via browser extension from certain website due to CSP
I am unable to redirect JavaScript URLs via browser extension from a certain domain due to its CSP put in place from the html file which requests the target JavaScript URL. I have also tried using modifyHeader rule action types to remove X-Frame-Options and Content-Security-Policy headers but it’s of no use. I am targeting 2 websites and my redirects do work for one of them which I assume to not use CSP.
My manifest.json file. targetA is the website which I’m able to redirect a specific JavaScript URL and targetB is the one I’m unable to:
{
"manifest_version": 3,
"name": "non-declarative-net-request",
"version": "1.0.0",
"permissions": [
"activeTab",
"declarativeNetRequest",
"declarativeNetRequestWithHostAccess",
"nativeMessaging",
"webRequest",
"webRequestBlocking"
],
"host_permissions": [
"<all_urls>"
],
"background": {
"scripts": [
"background.js"
]
},
"content_scripts": [
{
"matches": [
"*://*.targetA.com/*",
"*://targetB.org/*"
],
"js": [
"src/main/js/index.js"
]
}
],
"declarative_net_request": {
"rule_resources": [
{
"id": "ruleset_1",
"enabled": true,
"path": "rules.json"
}
]
}
}
My rules.json file:
[
{
"id": 1,
"priority": 1,
"action": {
"type": "modifyHeaders",
"responseHeaders": [
{
"header": "X-Frame-Options",
"operation": "remove"
},
{
"header": "Content-Security-Policy",
"operation": "remove"
}
]
},
"condition": {
"urlFilter": "*://targetB.org/*",
"resourceTypes": [
"main_frame",
"sub_frame",
"object",
"script",
"xmlhttprequest",
"csp_report",
"other"
]
}
},
{
"id": 2,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"urlFilter": "http://127.0.0.1:3600/targetA/target.js",
}
},
"condition": {
"urlFilter": "https://www.targetA.com/target.js",
"resourceTypes": [
"script"
]
}
},
{
"id": 3,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"url": "http://127.0.0.1:3600/targetB/target.js"
}
},
"condition": {
"urlFilter": "https://targetB.org/target.js",
"resourceTypes": [
"script"
]
}
}
]
I also tried to test different values for the rules’ priority‘s but that didn’t work either.
StaleElementReferenceException – Page randomly scrolls back up?
url: https://www.wunderground.com/history/monthly/at/vienna/LOWW/date/2025-1
It seems like I’m getting this exception because for some reason at a random point whilst iterating through the table the page scrolls back up so the table is not in the DOM anymore and so the table element can’t be found.
Any advice on how to avoid this? Thanks
code
element = driver2.find_element(By.XPATH, '//*[@id="inner-content"]/div[2]/div[1]/div[5]/div[1]/div/lib-city-history-observation/div/div[2]/table')
driver2.execute_script('arguments[0].scrollIntoView()', element)
t = driver2.find_element(By.XPATH, '//*[@id="inner-content"]/div[2]/div[1]/div[5]/div[1]/div/lib-city-history-observation/div/div[2]/table/tbody/tr/td[1]/table')
rows = t.find_elements(By.XPATH, './/tr')
for row in rows:
days = row.find_element(By.XPATH, './/td').text
print(days)
data.append({'days':days})
error
StaleElementReferenceException Traceback (most recent call last)
Cell In[14], line 32
26 data = []
31 for row in rows:
---> 32 days = row.find_element(By.XPATH, './/td').text
33 driver2.execute_script('arguments[0].scrollIntoView()', element)
34 print(days)

