Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

The synchronized keyword is all about different threads reading and writing to the same variables, objects and resources. This is not a trivial topic in Java, but here is a quote from Sun:

synchronized methods enable a simple strategy for preventing thread interference and memory consistency errors: if an object is visible to more than one thread, all reads or writes to that object's variables are done through synchronized methods.

In a very, very small nutshell: When you have two threads that are reading and writing to the same 'resource', say a variable named foo, you need to ensure that these threads access the variable in an atomic way. Without the synchronized keyword, your thread 1 may not see the change thread 2 made to foo, or worse, it may only be half changed. This would not be what you logically expect.
4 years ago
Either use a semi-transparent PNG image or use CSS 3:
***
background-color: rgba(255, 0, 0, 0.5);
***
4 years ago
In modern browsers, you can just use the contains a method of Element.classList :
***
testElement.classList.contains(className)
***
4 years ago
Use the CSS 3 property background-size:
***
#my_container {
background-size: 100% auto; /* width and height, can be %, px or whatever. */
}
***
4 years ago
sample code to do this
***



***
4 years ago
There is a difference, but there is no difference in that example.

Using the more verbose method: new Array() does have one extra option in the parameters: if you pass a number to the constructor, you will get an array of that length:
***
x = new Array(5);
alert(x.length); // 5
***
To illustrate the different ways to create an array:
***
var a = [], // these are the same
b = new Array(), // a and b are arrays with length 0

c = ['foo', 'bar'], // these are the same
d = new Array('foo', 'bar'), // c and d are arrays with 2 strings

// these are different:
e = [3] // e.length == 1, e[0] == 3
f = new Array(3), // f.length == 3, f[0] == undefined

;
***
Another difference is that when using new Array() you're able to set the size of the array, which affects the stack size.
4 years ago
For safe content just
***

***
DOMSanitizer

Potential unsafe HTML needs to be explicitly marked as trusted using Angulars DOM sanitizer so doesn't strip potentially unsafe parts of the content
***

***
with a pipe like
***
@Pipe({name: 'safeHtml'})
export class Safe {
constructor(private sanitizer:DomSanitizer){}

transform(style) {
return this.sanitizer.bypassSecurityTrustHtml(style);
//return this.sanitizer.bypassSecurityTrustStyle(style);
// return this.sanitizer.bypassSecurityTrustXxx(style); - see docs
}
}
***
4 years ago
Use the *key* argument to sort the dictionary by value.
For example
***
my_list = [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}]
my_list = sorted(my_list, key=lambda k: k['name'])
***
4 years ago
It can be done using only CSS. No JavaScript required.
Apply the custom HTML attribute.
for example
***

something here

***
Define the :before pseudoelement of each [data-tooltip] object to be transparent, absolutely positioned and with data-tooltip="" value as content:
***
[data-tooltip]:before {
position : absolute;
content : attr(data-tooltip);
opacity : 0;
}
***
Define :hover:before hovering state of each [data-tooltip] to make it visible:
***
[data-tooltip]:hover:before {
opacity : 1;
}
***
Apply your styles (color, size, position etc) to the tooltip object; end of the story.

In the demo I've defined another rule to specify if the tooltip must disappear when hovering over it but outside of the parent, with another custom attribute, data-tooltip-persistent, and a simple rule:
***
[data-tooltip]:not([data-tooltip-persistent]):before {
pointer-events: none;
}
***
4 years ago
If anyone looking with time and timezone, this is for you
***
{{data.ct | date :'dd-MMM-yy h:mm:ss a '}}
***
add z for time zone at the end of date and time format
***
{{data.ct | date :'dd-MMM-yy h:mm:ss a z'}}
***
4 years ago
Create a component inside a specific folder:
***
ng g c folder-name/component-name
***
Create a component inside a folder for a specific (existing) module with Angular-CLI:
***
ng g c folder-name/component-name --module=folder-name/moduleName.module.ts
***
4 years ago
Good News! Basically, Bootstrap 5 can be implemented easily now, and you don't even need jQuery.
From your terminal, just run
***
npm install bootstrap@next --save
***
So, Angular uses webpack, therefore, in your app.module.ts, just add:
***
import "bootstrap";
***
Or if you want to import them separately, do it like:
***
import { ModuleToBeImported } from 'bootstrap';
***
Then to your styles.scss, add:
***
@import '~bootstrap/scss/bootstrap';
***
Basically that's it, BUT beware that some components require popper.js. Components requiring bootstrap's js There you'll see the components dependent on popper.js too, which at the time of writing this are Dropdowns for displaying and positioning, and Tooltips and popovers for displaying and positioning.

Therefore, to install popper.js, just run:
***
npm install @popperjs/core
***
4 years ago