function evaluateFunction({ a: 3, b: 7, c: 5 }, n => n * 2);
/* Returns:
{
a: 6,
b: 14,
c: 10
}
*/
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
function evaluateFunction({ a: 3, b: 7, c: 5 }, n => n * 2);
/* Returns:
{
a: 6,
b: 14,
c: 10
}
*/
Some sites (notably twitter) like to set overflow:hidden, typically on either body or html, particularly when they pop up a modal window. With a chrome extension, I’ve set it to scroll as !important, but … after a delay, it changes. Is there a way (short of turning off javascript entirely) to keep the overflow attribute where I set it?
I’m making a infographic slider and I have buttons when clicked that reveal text. When I go to the next slider and then hit the previous button and go back my toggles reveal the text and then bounce back to be invisible.
Here is some of the code… I’m not sure if I should be resetting the css or Javascript div where each button is held? Please tell me how I can fix the toggle issue.
$( "#point1" ).click(function() {
$( "#timeline1" ).toggle( "slow", function() {
// Animation complete.
});
});
$( "#point2" ).click(function() {
$( "#timeline2" ).toggle( "slow", function() {
// Animation complete.
});
});
$( "#point3" ).click(function() {
$( "#timeline3" ).toggle( "slow", function() {
// Animation complete.
});
});
$( "#point4" ).click(function() {
$( "#timeline4" ).toggle( "slow", function() {
// Animation complete.
});
});
$( "#point5" ).click(function() {
$( "#timeline5" ).toggle( "slow", function() {
// Animation complete.
});
});
#point1 {
position: absolute;
top: 20%;
left: 8%;
transform: translate(-50%, -50%);
width: 45px;
cursor: pointer;
}
<img src="img/SVG/point1.svg" alt="fact" id="point1" class="point"/>
<img src="img/SVG/point2.svg" alt="fact" id="point2" class="point"/>
<img src="img/SVG/point3.svg" alt="fact" id="point3"class="point" />
<img src="img/SVG/point4.svg" alt="fact" id="point4"class="point" />
<img src="img/SVG/point5.svg" alt="fact" id="point5" class="point"/>
consts and requirements
require('dotenv').config();
const OpenAI = require('openai-api');
// Load your key from an environment variable or secret management service
// (do not include your key directly in your code)
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
const openai = new OpenAI(OPENAI_API_KEY);
const Discord = require('discord.js');
const TOKEN = process.env.TOKEN;
const { Client, Intents } = require('discord.js');
const bot = new Discord.Client({ intents: [Intents.FLAGS.GUILDS] });
const prefix = 'w!';
*on ready*
bot.on('ready', async() => {
console.log(`${bot.user.tag} is online!`);
bot.user.setActivity('with the code', {type: 'PLAYING'});
});
this is the one being the problem, it won’t detect sent messages I’ve tried a few different ways but nothing, got nothing to do with the server permissions I’m testing on a blank server and node is up to date
bot.on('messageCreate', message => {
if (message.content === 'ping') {
message.channel.send('pong');
}
});
In Profile Section of the user the password field is not mandatory however I set a function which calls the password validation.
Password and Confirm Password Field
<input type="password" id="password" name="password" class="form-control" onfocus="submission()">
<input type="password" id="cpassword" name="password_confirmation" class="form-control" onfocus="submission()">
Submission JS Function
function submission() {
$(':input[type="submit"]').prop('disabled', true);
$('input[type="password"]').keyup(function() {
if(passwordValidation()) {
$(':input[type="submit"]').prop('disabled', false);
}
});
}
Password Validation Function
function passwordValidation() {
$('input[type=password]').keyup(function() {
var pswd = $(this).val();
if (pswd != '') {
var x = document.getElementById("password").value;
var y = document.getElementById("cpassword").value;
if ( pswd.length < 8 ) {
$('#length').removeClass('valid').addClass('invalid');
} else {
$('#length').removeClass('invalid').addClass('valid');
}
//validate letter
if ( pswd.match(/[A-z]/) ) {
$('#letter').removeClass('invalid').addClass('valid');
} else {
$('#letter').removeClass('valid').addClass('invalid');
}
//validate capital letter
if ( pswd.match(/[A-Z]/) ) {
$('#capital').removeClass('invalid').addClass('valid');
} else {
$('#capital').removeClass('valid').addClass('invalid');
}
//validate number
if ( pswd.match(/d/) ) {
$('#number').removeClass('invalid').addClass('valid');
} else {
$('#number').removeClass('valid').addClass('invalid');
}
//validate symbol
if ( pswd.match(/[!@#$%^&*]/) ) {
$('#symbol').removeClass('invalid').addClass('valid');
} else {
$('#symbol').removeClass('valid').addClass('invalid');
}
//validate symbol
if ( x == y && x != "" && y != "" ) {
$('#confirm').removeClass('invalid').addClass('valid');
} else {
$('#confirm').removeClass('valid').addClass('invalid');
}
return true;
} else {
return false
}
}).focus(function() {
$('#pswd_info').show();
}).focusout(function() {
$('#pswd_info').hide();
});
//return true;
}
The return of passwordValidation() is allows undefined not getting any false or true result. I tried multiple ways but no luck of success, anyone can help telling me what’s wrong with the code.
We are building a Google Data Studio Community Visualization and need to draw geographic features on a base map. The Google Data Studio default map component does not support geographic data for example Geojson. To build this feature, I tried Openlayers and Leaflet. Both of them work fine on local env but not Production environment. The error is
Refused to load the image 'https://a.tile.openstreetmap.org/13/4093/2723.png' because it violates the following Content Security Policy directive
I found this post by Community Visualization. It seems loading external image, in this case the base map tile, is not a feature of Community Visualization. So, is there anyway to implement a map to Community Visualization?
I am attempting to set up an API that pulls from an Azure DB.
I have a function queryDatabase() that sends a select query to an Azure SQL Database. It sends the query request and then returns a Promise waiting on the response from the database:
function queryDatabase(){
const request = new Request(
`select * from [dbo].[table1];`,
(err, rowCount) => {
if (err) {
console.error(err.message);
}
}
);
return new Promise((resolve,reject)=>{
const result = [];
request.on("row", (columns) => {
const entry = {};
columns.forEach((column) => {
entry[column.metadata.colName] = column.value;
});
result.push(entry);
});
request.on('done',()=>resolve(result)); // resolve the promise with the result rows.
request.on('error',error=>reject(error));// some error happened, reject the promise
connection.execSql(request);
});
}
Then for usage I have a router listening on /data which is supposed to call the queryDatabase() method and wait for the Promise to be fulfilled. Once it’s fulfilled it should respond with the data in a JSON format, however the Promise from queryDatabase() never seems to be fulfilled, nor errored, as the page is stuck on loading:
router.get("/data", cors(), function (req, res) {
queryDatabase().then(rows=>{
res.type('application/json');
res.send(JSON.stringify(rows));
})
.catch(error=>{
res.status(500);
res.render('error, ', {error: error});
});
});
Any help on why it’s not working correctly would be amazing, cheers
I’ve built a Slack-style avatar image upload and crop feature, and I can’t get the cropped image to save without corruption. The original file upload, using the same endpoint and method, works just fine. It’s the cropped copy, created manually from a Blob, that is always corrupt.
Steps are pretty simple:
In Step 1, the file is uploaded when the file input changes. File is sent to a streaming endpoint which uploads the file to an s3 bucket.
<button type="button">Upload</button>
<input
type="file"
accept="image/*"
onChange={onFileChange}
/>
...
const onFileChange = async e => {
e.preventDefault();
let uploadedFile = e.target.files[0];
await onSave(uploadedFile);
};
The uploadedFile var is the File object returned from the input control. This works great! No issues, yet.
In Step 3, once you’ve selected an area of the image, a Blob is produced by react-image-crop.
const getCroppedImage = (source, config) => {
const canvas = document.createElement("canvas");
const scaleX = source.naturalWidth / source.width;
const scaleY = source.naturalHeight / source.height;
canvas.width = config.width;
canvas.height = config.height;
const ctx = canvas.getContext("2d");
ctx.drawImage(
source,
config.x * scaleX,
config.y * scaleY,
config.width * scaleX,
config.height * scaleY,
0,
0,
config.width,
config.height
);
let mimeType = mime.lookup(userProfile.image_file.split(".").at(-1));
return new Promise((resolve, reject) => {
canvas.toBlob(blob => {
if (!blob) {
reject(new Error("Canvas is empty"));
return;
}
resolve(blob); //***THIS BLOB...
}, mimeType);
});
};
This Blob is valid, because I display the selected area on the screen before saving:
const AvatarPreview = () => {
if (activeAvatar) {
return <ImageCropper imageToCrop={activeAvatar} onImageCropped={onImageCropped} />;
}
return <Icon icon="bi:person" />;
};
I stuff the Blob produced by react-image-crop, into a File object because that’s what my code expects, just like Step 1.
const onImageCropped = croppedBlob => { //***IS PASSED IN HERE
let croppedImg = URL.createObjectURL(croppedBlob);
setActiveAvatar(croppedImg);
const reader = new FileReader();
reader.readAsDataURL(croppedBlob);
reader.addEventListener("load", () => {
let { result } = reader;
let resultMimeType = result.split(";")[0].split(":")[1];
let croppedFile = new File([result], userProfile.image_file, { type: resultMimeType }); //***NEW File object, from Blob
setCroppedAvatar(croppedFile);
}, false);
};
<button type="button" onClick={() => onSave(croppedAvatar)}>Save</button>
The “result” in the FileReader load above is the base64 image data:
'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAAHRyWFlaAAABZAAAABRnWFlaAAABeAAAABRiWFlaAAABjAAAABRyVFJDAAABoAAAAChnVFJDAAABoAAAAChiVFJDAAABoAAAACh3dHB0AAAByAAAABRjcHJ0AAAB3AAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAFgAAAAcAHMAUgBHAEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA…QCMFWeFZ9u3fPsWY3hh9uVHWllbSwtGASrIOQc1t6rt0OBqG6x7aVfdY859pnIwfDDhCfpwBUyaSus4VZO+susGGM60zrB1TuEjx5Ov76FBKUgNTltIQlP4UpQghKQMAAAADHApt6lv1x1HeHrzdny9KkJbDrpHLhQhKNx91EJBJ9SSaQkLS+4HTwvalKvmQMZ/PFa8hBCRntnirYUDqVYtEWlQ8JYJSrv8vnTy6W2h5/qBYmCgqbcmtgLSMg+YUyYD4aUUqTlJ4I+td+FLethRhai0sgoUOCg+hFPBwcxjruUie1k/VDOmenKkIcS2iJCzyeAAmvF7qjqFzVWurzfHV7jJluKBJ/hBwP6VL1u+KvqlD0lL0VeLt+2rZLjmO25MyqSwNuPK7nKh8l7vlioFejqU8tx453EnIPcmrWrvW5VFf6zK0GifTWs1n6TRoUrIaDZBSeDSVUzyMTY7gBIORR/EcXwTnFEozfc0xVwOYT/2Q=='
The new File object seems legit to me:
I then send the image through the endpoint again, and it’s uploaded. It appears in the bucket, and the file size seems legit (not 0KB like a broken stream would indicate.)
However, upon downloading and attempting to open the file, it’s corrupt. I guess I’m missing an option somewhere…some little tweak that would make this work? Is the File object not formed correctly? How do I troubleshoot this further?
Hi guys after a function call and its eventual callback I have to change the webview url but the error prints that this.webview is undefined, this is my code.
Into the function onMessage after I use postMessage from html I have to change the URL of the webview.
Help me and I will never stop thanking you
export default class WevViewApp extends Component {
constructor( props ) {
super( props );
this.webView = null;
}
onMessage( event ) {
if(registerToken){
//change url of my webview
}
}
render() {
return (
<View style={{flex: 1}}>
<WebView
ref={( webView ) => this.webView = webView}
style={{flex: 1}}
source={{uri: 'https://url.com/test123'}}
javaScriptEnabled={true}
injectedJavaScript={myInjectedJs}
onMessage={this.onMessage}
/>
</View>
);
}
}
I’m in the middle of migrating an old codebase of AngularJS from hundreds of <script> tags to es modules (The only reason I mention that, is because it might give some insights into why I’m getting this odd behavior).
I found out that in the old codebase (and in every other place in StackOverflow), given an ng-click with $event, a jQuery.Event is being injected into the callback:
<button ng-click="doX($event)">Click me</button>
$scope.doX = ($event) => {
console.log($event); // $event: jQuery.Event
};
But, in the new codebase (which I’m using Vite), I’m getting $event: PointerEvent instead.
What’s the explanation for this? does it check a global variable declaration to decide whether to wrap the original event with a jQuery?
So I have a full featured Vue 3 app that I need to embed on random page somewhere, but I don’t want to use an iframe for various reasons so I’m looking to achieve this using Shadow DOM and Custom Element.
The way I thought it would work:
dist folderconstructordist/index.html… except it doesn’t. Everything technically works but the Vue app doesn’t render at all.
What am I missing?
My attempt: https://stackblitz.com/edit/javascript-7trm5i?devtoolsheight=33&file=index.html
Could anyone help me understand why I am getting this PageIndex out of range error? This script was able to finish if I took the measure out. So I think sth. was wrong at commands.measure. I saw ERROR: Could not add meta data to the HAR, miss page 0 Is it because Sitespeed.io can only measure right after navigate?
[2022-02-01 22:44:44] INFO: Versions OS: linux 5.10.76-linuxkit nodejs: v14.17.6 sitespeed.io: 19.4.2 browsertime: 14.2.1 coach: 6.4.3
[2022-02-01 22:44:45] INFO: Running tests using Chrome - 1 iteration(s)
[2022-02-01 22:44:45] INFO: Navigating to url https://test.salesforce.com/ iteration 1
[2022-02-01 22:45:15] INFO: ***Logging in...***
[2022-02-01 22:45:15] INFO: Navigating to url https://qasvetlana2--lexcall.lightning.force.com/lightning/o/Account/list?filterName=AllAccounts iteration 1
[2022-02-01 22:45:33] INFO: ***Locating the first professional account...***
[2022-02-01 22:45:35] INFO: ***Click record a call button
[2022-02-01 22:45:35] INFO: Start to measure
[2022-02-01 22:45:53] ERROR: Could not add meta data to the HAR, miss page 0
[2022-02-01 22:45:53] INFO: https://qasvetlana2--lexcall.lightning.force.com/lightning/r/Account/00146000006dwxdAAA/view TTFB: 269ms, firstPaint: 305ms, firstVisualChange: 0ms, FCP: 392ms, DOMContentLoaded: 385ms, LCP: 18.00s, CLS: 0.082, TBT: 1.23s, Load: 647ms, speedIndex: 0ms, visualComplete85: 0ms, lastVisualChange: 0ms
[2022-02-01 22:45:53] ERROR: Could not find the right index 0 for har for url https://qasvetlana2--lexcall.lightning.force.com/lightning/r/Account/00146000006dwxdAAA/view
[2022-02-01 22:45:53] ERROR: Caught error from Browsertime Error: PageIndex out of range
at module.exports.pickAPage (/usr/src/app/node_modules/coach-core/lib/har/harCutter.js:18:11)
at Object.pickAPage (/usr/src/app/node_modules/coach-core/lib/index.js:84:12)
at Object.processMessage (/usr/src/app/lib/plugins/browsertime/index.js:263:31)
Below is the javascript.
let login = "https://test.salesforce.com/";
let test = "https://abc.lightning.force.com/lightning/o/Account/list?filterName=AllAccounts";
let username = "xxx";
let passwd = "xxx";
module.exports = async function(context, commands) {
await commands.navigate(login);
try {
await commands.addText.byId(username, "username");
await commands.addText.byId(passwd, "password");
await commands.click.byIdAndWait("Login");
await commands.wait.byTime(1000);
context.log.info("***Logging in...***");
await commands.navigate(test);
await commands.wait.byTime(5000);
context.log.info("***Locating the first professional account...***");
await commands.click.byXpath('(//td[@role="gridcell" and span/span[@title="Professional"]]/preceding-sibling::th[1]/span/a)[1]');
await commands.wait.byTime(2000);
context.log.info("***Click record a call button")
await commands.measure.start();
await commands.click.byXpathAndWait('//runtime_platform_actions-action-renderer[@apiname="Record_a_Call"]');
return commands.measure.stop();
context.log.info("***Done***")
} catch (e) {
throw e;
}
};
I have this.userGroups
[ { “id”: 46, “group_id”: 38, “url”: “1”, “url_num”: 1, “max_iteration”: 2 }, { “id”: 45, “group_id”: 38, “url”: “2”, “url_num”: 1, “max_iteration”: 2 }, { “id”: 44, “group_id”: 38, “url”: “3”, “url_num”: 1, “max_iteration”: 2 }, { “id”: 43, “group_id”: 38, “url”: “4”, “url_num”: 1, “max_iteration”: 2 } ]
<v-row v-for="(urlGroup, index) in urlGroups" :key="index">
<v-col cols="12" sm="6" md="3">
<v-text-field required v-model="urlGroup.url" label="URL" clear-icon="mdi-close-circle" clearable type="text" @click:clear="removeUrl(index)"></v-text-field>
</v-col>
</v-row>
requireddoesn’t seem to work because I can still submit the form without providing any value. I used to do this in a single text field, but now it’s dynamic, I have no idea how to do that.
url: [(v) => !!v || 'URL is required']
How can I add a validation rule to all of them to be typed URL, and required?
I need to object to server but need to format
example of object ->
let obj =
{
id: 1,
title: title
}
This is okay butt any time i got different property
I need to format if I got name property i need to replace instead title
if i got name i need to format object
let obj =
{
id: 1,
name: name
}
Title property i got always but when i got name i need to replace…
i am try with:
if(name){
return name: name
} else {
return title: title
}
I can’t for the life of me figure out why this external JS file isn’t loading. I’ve tried every help question out there and it still won’t work so maybe someone else can see what I can’t.
So I’m working on a ReactJS project and I’m trying to link an external JS file.
The external javascript file is in public/js/script.js.
I’ve tried every method I’ve found to get it to work.
I’ve linked it in index.html as follows:
<script src="./js/script.js" type="text/jsx"></script>
I’ve added the following to my main App component:
componentDidMount() {
const script = document.createElement('script');
let url = '../public/js/script.js'
script.src = url; //(This is external js url)
script.async = true;
document.body.appendChild(script);
}
I’ve added this into the functional component where I really need the external javascript to work:
useEffect(() => {
const script = document.createElement('script');
script.src = '../public/js/script.js'; //(This is external js url)
script.async = true;
document.body.appendChild(script);
}, [])
And yet not matter any of these attempts nothing seems to make the file work.
I am running the project on localhost, so I’m not sure if there’s an issue there. I’d just like to figure out how to make external javascript files work. I’ve tried using Helmet.
I don’t know what I’m doing wrong. Anyways, appreciate any help I can get trying to figure this out.