I try to validate this line combinations:
33 33
333
33-33
Using reg express:
d{2}(^s|s|-)d{2}
As you can see I use (^s|s|-) but it does not work for 333 string
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
I try to validate this line combinations:
33 33
333
33-33
Using reg express:
d{2}(^s|s|-)d{2}
As you can see I use (^s|s|-) but it does not work for 333 string
How can I check if a string contains either one of 2 other strings? For example, I want to check if a URL contains either one of these string localhost or 10.0.2.2
http://localhost:5000 -> true
10.0.2.2:5000 -> true
dasdasdasdasdlocalhostdasdasd -> true
dasdasdasd10.0.2.2:5000dasdasd -> true
http://example.com -> false
Sometimes when I am using the console in devtools (chrome/edge/etc), I use common functions that I write.
For example a sort function or something likewise.
How can I add functions (or classes) by default, so that everytime I open the console these functions or classes are automatically available?
I am trying to initiate a modal component on ngOnInit() by passing fragments in route link
ngOnInit() {
this.getCandidateDetails()
this.route.fragment.subscribe(qp => {
if ('openjobeditmodal' == qp) {
this.editJobRole();
}
})
}
now I am able to open a modal component on page initiation but the issue is that component takes this.getCandidateDetails() response as Input,and this.getCandidateDetails() is getting called after modal initiate,how can I ensure thatI only subscribe to modal only after this.getCandidateDetails() gets called
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
print_r(file_get_contents('php://input'));
This is my PHP server page to handle a request from a react.js client on localhost:3000
this is the code of the client
let handleSubmitDesign = (event) => {
event.preventDefault();
let url = 'https://www.myserver.com/test.php'; //Server example
let data = {
key: k,
code: code,
role: role,
cat: 1
};
sendPostRequest(data, url, fun);
}
This is the first function
function sendPostRequest(data, url, fun) {
let newData = JSON.stringify(data);
axios.post(url, newData)
.then(function (response) {
//console.log(response.data);
fun(response.data);
})
.catch(function (error) {
console.log(error);
});
}
Of course the data are not empty and i can check using a log , if a use a third party API tool test as https://reqbin.com/ i can check my server page works fine , same thing with a React Native mobile app, but not for this React.js app
the print_r funcion , or an echo function let me see i don’t recive anything
I decided to integrate prettier to work together with my eslint, and because of this I have to disable some eslint rules that from what I learned in my researches wont work together with prettier, like the rules implicit-arrow-linebreak and multiline-ternary.
I just want this rules to be disabled. I tried to comment them out in .eslint.js, set them to 'off', ['off'] and ['off', {}]. It all works in the editor, but when I run my app, the errors for this two rules are still shown in the screen and in the console.
My .eslint.js:
module.exports = {
env: {
node: true,
es6: true,
browser: true
},
extends: ['react-app', 'prettier'],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
modules: true,
experimentalObjectRestSpread: true
}
},
rules: {
'no-console': 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
// Best Practices
eqeqeq: 'error',
'no-invalid-this': 'error',
'no-return-assign': 'error',
'no-unused-expressions': ['error', { allowTernary: true }],
'no-useless-concat': 'error',
'no-useless-return': 'error',
// Variable
// 'init-declarations': 'error',
'no-use-before-define': 'error',
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z]' }],
// Stylistic Issues
'array-bracket-newline': ['error', { multiline: true, minItems: null }],
// 'array-bracket-spacing': 'error',
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
'block-spacing': 'error',
'comma-dangle': 'error',
'comma-spacing': 'error',
'comma-style': 'error',
'computed-property-spacing': 'error',
'func-call-spacing': 'error',
'implicit-arrow-linebreak': 'off',
indent: ['error', 2],
'keyword-spacing': 'error',
'multiline-ternary': 'off',
// 'no-lonely-if': 'error',
'no-mixed-operators': 'error',
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }],
'no-tabs': 'error',
'no-unneeded-ternary': 'error',
'no-whitespace-before-property': 'error',
'nonblock-statement-body-position': 'error',
'object-property-newline': [
'error',
{ allowAllPropertiesOnSameLine: true }
],
'quote-props': ['error', 'as-needed'],
// quotes: ['error', 'prefer-single'],
semi: ['error', 'never'],
'semi-spacing': 'error',
'space-before-blocks': 'error',
// 'space-before-function-paren': 'error',
'space-in-parens': 'error',
'space-infix-ops': 'error',
'space-unary-ops': 'error',
// ES6
'arrow-spacing': 'error',
'no-confusing-arrow': 'error',
'no-duplicate-imports': 'error',
'no-var': 'error',
'object-shorthand': 'error',
'prefer-const': 'error',
'prefer-template': 'error'
}
}
What I see when running the app:
Any tips on why this is happening and how to fix this?
I have a countdown timer that I’d like to show the exact same amount of remaining hours and minutes for every user regardless of timezone or location (days aren’t important).
I’m assuming I need to target and output UTC somehow. Will I have any daylight-saving problems with this? I just want everyone to see the same remaining time.
I’ve researched similar posts here but they’re a few years old and didn’t find answers. Hoping a solution or newer approach is available. All programming languages considered.
// Set the date we're counting down to
var countDownDate = new Date("May 10, 2022 24:00:00").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h " +
minutes + "m " + seconds + "s ";
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
#demo {
font: normal 20px arial
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="demo"></div>
I’m using the library ‘dom-to-image’ and I’m finding that when I set the target to a parent div containing an image and nested text elements it produces a blank PNG of the same dimensions.
I’ve reproduced the issue in a JSFiddle
The DOM structure is this:
<div id="target">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/7f/Speech_bubble.svg/2560px-Speech_bubble.svg.png">
<div>
<span>Enter text</span>
</div>
</div>
domtoimage.toPng(document.getElementById("target"))
.then(function (dataUrl) {
var img = new Image();
img.src = dataUrl;
document.body.appendChild(img);
})
.catch(function (error) {
console.error('oops, something went wrong!', error);
});
In my own codebase I’m using a locally hosted image, but for the JSFiddle I’m just using an imgur link. I’ve been able to get it to reproduce the image element, but as soon as I set it to the parent div in order to capture the overlaying text it produces an empty png.
I am trying to make Editable or resizeable Polygon in cesium; for example if we draw a zone/polygon around some area
and i want user to have the ability to move polygon corners to size the polygon. For example
how we resize shapes. i want to change polygon on run Time.
this is how i create polygon according to User needs.
Source : https://sandcastle.cesium.com/index.html?src=Drawing%20on%20Terrain.html
//////////////////////////////////////////////////free style polygon
var PolygonCollection = [];
viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(
Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
);
function createPoint(worldPosition) {
var point = viewer.entities.add({
position: worldPosition,
point: {
color: Cesium.Color.WHITE,
pixelSize: 5,
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
},
});
PolygonCollection.push(point);
return point;
}
drawingMode = "polygon";
function drawShape(positionData) {
var shape;
if (drawingMode === "polygon") {
shape = viewer.entities.add({
name: 'bander',
polygon: {
hierarchy: positionData,
material: new Cesium.ColorMaterialProperty(
Cesium.Color.WHITE.withAlpha(0.7)
),
},
});
}
PolygonCollection.push(shape);
return shape;
}
handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
handler.setInputAction(function(event) {
if (free_Style_poly == 1) {
if (shape_done == 1) {
freeStyleShapes = [];
shape_done = 0;
}
//viewer._container.style.cursor = "crosshair";
var ellipsoid = viewer.scene.globe.ellipsoid;
var cartesian = viewer.camera.pickEllipsoid(event.position, ellipsoid);
//Converting Cartesian coordinates to geographic coordinates
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
//Decimal representation of radians to degrees
var lon = Cesium.Math.toDegrees(cartographic.longitude);
var lat = Cesium.Math.toDegrees(cartographic.latitude);
freeStyleShapes.push(lon, lat);
// We use `viewer.scene.pickPosition` here instead of `viewer.camera.pickEllipsoid` so that
// we get the correct point when mousing over terrain.
var earthPosition = viewer.scene.pickPosition(event.position);
// `earthPosition` will be undefined if our mouse is not over the globe.
if (Cesium.defined(earthPosition)) {
if (activeShapePoints.length === 0) {
floatingPoint = createPoint(earthPosition);
activeShapePoints.push(earthPosition);
var dynamicPositions = new Cesium.CallbackProperty(function() {
if (drawingMode === "polygon") {
return new Cesium.PolygonHierarchy(activeShapePoints);
}
return activeShapePoints;
}, false);
activeShape = drawShape(dynamicPositions);
}
activeShapePoints.push(earthPosition);
createPoint(earthPosition);
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
handler.setInputAction(function(event) {
if (Cesium.defined(floatingPoint)) {
var newPosition = viewer.scene.pickPosition(event.endPosition);
if (Cesium.defined(newPosition)) {
floatingPoint.position.setValue(newPosition);
activeShapePoints.pop();
activeShapePoints.push(newPosition);
}
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
// Redraw the shape so it's not dynamic and remove the dynamic shape.
function terminateShape() {
// console.log(activeShapePoints);
// plotJson();
activeShapePoints.pop();
drawShape(activeShapePoints);
viewer.entities.remove(floatingPoint);
viewer.entities.remove(activeShape);
floatingPoint = undefined;
activeShape = undefined;
activeShapePoints = [];
}
handler.setInputAction(function(event) {
if (free_Style_poly == 1) {
shape_done = 1;
terminateShape();
$('#submitPopup').show();
//saveGeoJson();
}
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
this is how i draw Polygon
now Drawing is complete i want user to be able to edit its coner or move it.
i would appricate any guidance. thank you
I did some Research my findings are
https://stackoverflow.com/questions/35476302/dynamically-change-polygon-position-in-cesium
this was in angular
this as well
https://stackoverflow.com/questions/32869814/best-and-most-performant-implementation-of-dynamic-shapes-in-cesium
I need to change addClass() to attr() that can add data-*attribute on body tag substitute for addClass().
This code can not store multiple class stores in multiple instances
I need to add data-*attr() substitute for addClass()
$box.addClass($this.data(‘color’));
to like :
$box.attr($this.data(‘color’));
that can add data-attribute on the body tag like as:
<body data-attribute-color=”color-name”
Thanks for your time.
// JavaScript
$(document).ready(function() {
let csscol = localStorage["activecol"];
let $box = $('.box');
//save original box classes
$box.data('initial-classes', $box.attr('class'));
if (csscol) {
$box.addClass(csscol);
// Restore checkbox as well
$('#colors-list [type="radio"][data-color="' + csscol + '"]').attr("checked", true);
}
$('#colors-list [type="radio"]').on("change", function() {
let $this = $(this);
if ($this.is(":checked")) {
//Replace all classes with initial classes
$box.attr('class', $box.data('initial-classes'));
$box.addClass($this.data('color'));
localStorage.setItem('activecol', $this.data('color'));
}
});
});
/* CSS Style */
.box {
width: 100px;
height: 100px;
background-color: #eee;
margin: 50px;
margin-top: 0;
margin-left: 80px;
}
.color1 {
background: #aaaaaa;
}
.color2 {
background: #888888;
}
.color3 {
background: #555555;
}
.color4 {
background: #222222;
}
#colors-list {
padding: 80px;
}
<!-- HTML Markup -->
<div id="colors-list">
<label>
<input type="radio" id="color1" name="colors-radio" value="1" checked="checked" data-color="color1">
<span class="color1" title="color #1"></span>
</label>
<label>
<input type="radio" id="color2" name="colors-radio" value="2" data-color="color2">
<span class="color2" title="color #2"></span>
</label>
<label>
<input type="radio" id="color3" name="colors-radio" value="3" data-color="color3">
<span class="color3" title="color #3"></span>
</label>
<label>
<input type="radio" id="color4" name="colors-radio" value="4" data-color="color4">
<span class="color4" title="color #4"></span>
</label>
</div>
<div class="box"></div>
i am working on a project where the code is written like this
<S.Checkout>{checkout}</S.Checkout>
when i control click on this it takes me to this
loading,
checkout,
cartSummary,
totalPrice,
button,
showPrepaidOffer,
}: IProps) => {
const history = useHistory();
const overlay = useContext(OverlayContext);
const { show } = overlay;
const { user } = useAuth();
const isMobile = useIsMobile(); ```
when i control click on checkout
it takes me to types.ts
i am unable to find the location of the component where the code is written.
Relevant TypeScript code:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-ng-class-example',
templateUrl: './ng-class-example.component.html'
})
export class NgClassExampleComponent implements OnInit {
isBordered: boolean;
classesObj: Object;
classList: string[];
constructor() { }
ngOnInit(): void {
this.isBordered = true;
this.classList = ['blue', 'round']
this.toggleBorder();
}
toggleBorder(): void {
this.isBordered = !this.isBordered;
this.classesObj = {
bordered: this.isBordered
};
}
}
Corresponding template (the relevant part).
<div [ngClass]="classesObj">
Using object var. Border {{ classesObj.bordered ? "ON" : "OFF" }}
</div>
Now I get an error in my .html file (around the attribute .bordered) stating that: “Property ‘bordered’ does not exist on type ‘Object'”.
I am new to TypeScript (and also JavaScript) but it seems to me that ‘bordered’ is defined on the object, so what is going on?
Thank you in advance!
Hey i want to get the listing id from the table row when i press the button on that specific row. So how can i read the value of listing.id when i press followItem. I am able to get the userID from localstorage but i cant get the listing.id when i press the button. thx:)
i get this error, which is at the listing.id :
allListings.js:82 Uncaught ReferenceError: res is not defined
at followItem (allListings.js:82:19)
findAllListings.addEventListener("click", async () => {
let maxPriceInput = document.getElementById("price")
let maxPrice = maxPriceInput.value
let maxDateInput = document.getElementById("date")
let maxDate = maxDateInput.value
let data = {
maxPrice,
maxDate
};
table.innerHTML = "";
table.innerHTML += `
<tr>
<th>picture</th>
<th>name</th>
<th>category</th>
<th>price</th>
</tr>
`;
await fetch("http://localhost:4000/allListings", {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((res) => res.json())
.then((res) => {
console.log(data)
for (const key in res) {
if (output == res[key].category) {
table.innerHTML += `
<tr>
<td><img src="${res[key].picture}" style="height:200px;width:auto;"/></th>
<td>${res[key].name}</th>
<td>${res[key].category}</th>
<td>${res[key].price}</th>
<td>${res[key].listing_id}</th>
<td><input type="button" value="Show" class="knapper" onclick="followItem()" /></td>
</td>
</tr>
`;
}
}
})
.catch((error) => {
console.log(error);
});
});
function followItem() {
let userId = localStorage.getItem("loggedInUser");
let listingid = res[key].listing_id;
let data = {
userId: userId,
listingid: listingid
};
fetch("http://localhost:4000/allListings/follow", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((response) => response.json())
.then((data) => {
if (data.msg === true) {
window.alert("you are now following this item");
window.location = "./allListings.html";
} else if (data.msg === false) {
window.alert("Error, please try again");
}
})
.catch((error) => {
console.log(error);
});
};
I want this function to return the url of the file.
fileUpload(file: any): string {
const contentType = file.type;
let imgurl = 'nofile';
const bucket = new S3({
accessKeyId: 'aaaa',
secretAccessKey: 'aaa',
region: 'eu-central-1',
});
const params = {
Bucket: 'namebucket',
Key: file.name,
Body: file,
ACL: 'public-read',
ContentType: contentType
};
bucket.upload(params, (err: any, data: any) => {
console.log('File Uploaded.', data.Location);
imgurl = data.Location;
console.log(data.lolcation);
return imgurl;
});
return imgurl;
}
But the second return, always returns the imgurl = 'nofile';
I need to return the data.Location.
What I am doin wrong?
it is my problem please help me. please resolve my problem?
https://i.stack.imgur.com/SY14o.png
click this image link