The default box model (content-box) can be counter-intuitive, since the width / height for an element will not represent its actual width or height on screen as soon as you start adding padding and border styles to the element.
The following example demonstrates this potential issue with content-...
A less known builtin feature is Controller Action injection using the FromServicesAttribute.
[HttpGet]
public async Task<IActionResult> GetAllAsync([FromServices]IProductService products)
{
return Ok(await products.GetAllAsync());
}
An important note is that the [FromServices] c...
Given a Person struct
struct Person {
let name: String
let birthYear: Int?
}
and an Array of Person(s)
let persons = [
Person(name: "Walter White", birthYear: 1959),
Person(name: "Jesse Pinkman", birthYear: 1984),
Person(name: "Skyler White&quo...
The ng-mouseenter and ng-mouseleave directives are useful to run events and apply CSS styling when you hover into or out of your DOM elements.
The ng-mouseenter directive runs an expression one a mouse enter event (when the user enters his mouse pointer over the DOM element this directive resides i...
This directive is useful to limit input events based on certain existing conditions.
The ng-disabled directive accepts and expression that should evaluate to either a truthy or a falsy values.
ng-disabled is used to conditionally apply the disabled attribute on an input element.
HTML
<input t...
The ng-dblclick directive is useful when you want to bind a double-click event into your DOM elements.
This directive accepts an expression
HTML
<input type="number" ng-model="num = num + 1" ng-init="num=0">
<button ng-dblclick="num++">Double...
RxJava is handy when making serial request. If you want to use the result from one request to make another you can use the flatMap operator:
api.getRepo(repoId).flatMap(repo -> api.getUser(repo.getOwnerId())
.subscribe(/*do something with the result*/);
You can use the zip operator to make request in parallel and combine the results eg:
Observable.zip(api.getRepo(repoId1), api.getRepo(repoId2), (repo1, repo2) ->
{
//here you can combine the results
}).subscribe(/*do something with the result*/);
C++11 introduced core language and standard library support for moving an object. The idea is that when an object o is a temporary and one wants a logical copy, then its safe to just pilfer o's resources, such as a dynamically allocated buffer, leaving o logically empty but still destructible and co...
Variable tensors are used when the values require updating within a session. It is the type of tensor that would be used for the weights matrix when creating neural networks, since these values will be updated as the model is being trained.
Declaring a variable tensor can be done using the tf.Varia...
Set MONGO_URL to any arbitrary value except for a database URL and ensure no collections are defined in your Meteor project (including collections defined by Meteor packages) to run Meteor without MongoDB.
Note that without MongoDB, server/client methods alongside any packages related to Meteor's u...
XSS attacks consist in injecting HTML (or JS) code in a page. See What is cross site scripting for more information.
To prevent from this attack, by default, Django escapes strings passed through a template variable.
Given the following context:
context = {
'class_name': 'large" style=&...
The intent attribute of a dummy argument in a subroutine or function declares its intended use. The syntax is either one of
intent(IN)
intent(OUT)
intent(INOUT)
For example, consider this function:
real function f(x)
real, intent(IN) :: x
f = x*x
end function
The intent(IN) specif...
It is possible to create custom routing constraint which can be used inside routes to constraint a parameter to specific values or pattern.
This constrain will match a typical culture/locale pattern, like en-US, de-DE, zh-CHT, zh-Hant.
public class LocaleConstraint : IRouteConstraint
{
pri...
A Bag/ultiset stores each object in the collection together with a count of occurrences. Extra methods on the interface allow multiple copies of an object to be added or removed at once. JDK analog is HashMap<T, Integer>, when values is count of copies this key.
TypeGuavaApache Commons Collec...
This multimap allows duplicate key-value pairs. JDK analogs are HashMap<K, List>, HashMap<K, Set> and so on.
Key's orderValue's orderDuplicateAnalog keyAnalog valueGuavaApacheEclipse (GS) CollectionsJDKnot definedInsertion-orderyesHashMapArrayListArrayListMultimapMultiValueMapFastListMu...
Types of columns can be checked by .dtypes atrribute of DataFrames.
In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 'C': [True, False, True]})
In [2]: df
Out[2]:
A B C
0 1 1.0 True
1 2 2.0 False
2 3 3.0 True
In [3]: df.dtypes
Out[3]:
A int64
...
astype() method changes the dtype of a Series and returns a new Series.
In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0],
'C': ['1.1.2010', '2.1.2011', '3.1.2011'],
'D': ['1 days', '2 days', '3 days'],
...
select_dtypes method can be used to select columns based on dtype.
In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 'C': ['a', 'b', 'c'],
'D': [True, False, True]})
In [2]: df
Out[2]:
A B C D
0 1 1.0 a True
1 2 2.0 b False
2...