With the <Flags> attribute, the enum becomes a set of flags. This attribute enables assigning multiple values to an enum variable. The members of a flags enum should be initialized with powers of 2 (1, 2, 4, 8...).
Module Module1
<Flags>
Enum Material
Wood = 1
...
public class Email
{
public string To { get; set; }
public string From { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
}
public class EmailBuilder
{
private readonly Email _email;
public EmailBuilder()
{
_email = ...
Bitwise operators perform operations on bit values of data. These operators convert operands to signed 32-bit integers in two's complement.
Conversion to 32-bit integers
Numbers with more than 32 bits discard their most significant bits. For example, the following integer with more than 32 bits i...
Events that work with most form elements (e.g., change, keydown, keyup, keypress) do not work with contenteditable.
Instead, you can listen to changes of contenteditable contents with the input event. Assuming contenteditableHtmlElement is a JS DOM object that is contenteditable:
contenteditableH...
// A simple adder function defined as a lambda expression.
// Unlike with regular functions, parameter types often may be omitted because the
// compiler can infer their types
let adder = |a, b| a + b;
// Lambdas can span across multiple lines, like normal functions.
let multiplier = |a: i32, ...
Since lambda functions are values themselves, you store them in collections, pass them to functions, etc like you would with other values.
// This function takes two integers and a function that performs some operation on the two arguments
fn apply_function<T>(a: i32, b: i32, func: T) -> ...
Returning lambdas (or closures) from functions can be tricky because they implement traits and thus their exact size is rarely known.
// Box in the return type moves the function from the stack to the heap
fn curried_adder(a: i32) -> Box<Fn(i32) -> i32> {
// 'move' applies move se...
State in React components is essential to manage and communicate data in your application. It is represented as a JavaScript object and has component level scope, it can be thought of as the private data of your component.
In the example below we are defining some initial state in the constructor f...
If no ordering function is passed, std::sort will order the elements by calling operator< on pairs of elements, which must return a type contextually convertible to bool (or just bool). Basic types (integers, floats, pointers etc) have already build in comparison operators.
We can overload this ...
C++11
// Include sequence containers
#include <vector>
#include <deque>
#include <list>
#include <array>
#include <forward_list>
// Include sorting algorithm
#include <algorithm>
class Base {
public:
// Constructor that set variable to the va...
To add a new unique column email to users, run the following command:
rails generate migration AddEmailToUsers email:string:uniq
This will create the following migration:
class AddEmailToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :email, :string
add_index...
BigInteger is in an immutable object, so you need to assign the results of any mathematical operation, to a new BigInteger instance.
Addition:
10 + 10 = 20
BigInteger value1 = new BigInteger("10");
BigInteger value2 = new BigInteger("10");
BigInteger sum = value1.add(value...
You can access each property that belongs to an object with this loop
for (var property in object) {
// always check if an object has a property
if (object.hasOwnProperty(property)) {
// do stuff
}
}
You should include the additional check for hasOwnProperty because an o...
It is undefined behavior to access an index that is out of bounds for an array (or standard library container for that matter, as they are all implemented using a raw array):
int array[] = {1, 2, 3, 4, 5};
array[5] = 0; // Undefined behavior
It is allowed to have a pointer pointing to the en...
The syntax for Java generics bounded wildcards, representing the unknown type by ? is:
? extends T represents an upper bounded wildcard. The unknown type represents a type that must be a subtype of T, or type T itself.
? super T represents a lower bounded wildcard. The unknown type repres...
A belongs_to association sets up a one-to-one connection with another model, so each instance of the declaring model "belongs to" one instance of the other model.
For example, if your application includes users and posts, and each post can be assigned to exactly one user, you'd declare th...
When using labels, both the start and the stop are included in the results.
import pandas as pd
import numpy as np
np.random.seed(5)
df = pd.DataFrame(np.random.randint(100, size=(5, 5)), columns = list("ABCDE"),
index = ["R" + str(i) for i in range(5)])
...
DataFrame:
import pandas as pd
import numpy as np
np.random.seed(5)
df = pd.DataFrame(np.random.randint(100, size=(5, 5)), columns = list("ABCDE"),
index = ["R" + str(i) for i in range(5)])
df
Out[12]:
A B C D E
R0 99 78 61 16 73...
Group by one column
Using the following DataFrame
df = pd.DataFrame({'A': ['a', 'b', 'c', 'a', 'b', 'b'],
'B': [2, 8, 1, 4, 3, 8],
'C': [102, 98, 107, 104, 115, 87]})
df
# Output:
# A B C
# 0 a 2 102
# 1 b 8 98
# 2 c 1 107
# 3 a...