There is also a way to have a single method accept a covariant argument, instead of having the whole trait covariant. This may be necessary because you would like to use T in a contravariant position, but still have it covariant.
trait LocalVariance[T]{
/// ??? throws a NotImplementedError
de...
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...
int *ptr = nullptr;
*ptr = 1; // Undefined behavior
This is undefined behavior, because a null pointer does not point to any valid object, so there is no object at *ptr to write to.
Although this most often causes a segmentation fault, it is undefined and anything can happen.
Omitting the return statement in a function which is has a return type that is not void is undefined behavior.
int function() {
// Missing return statement
}
int main() {
function(); //Undefined Behavior
}
Most modern day compilers emit a warning at compile time for this kind o...
C++11
char *str = "hello world";
str[0] = 'H';
"hello world" is a string literal, so modifying it gives undefined behaviour.
The initialisation of str in the above example was formally deprecated (scheduled for removal from a future version of the standard) in C++03. A num...
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...
It is best practice in any programming language to avoid premature optimization. However, if testing reveals that your code is running too slowly, you may gain some speed by switching off some of the application’s properties while it runs. Add this code to a standard module:
Public Sub SpeedUp( _
...
pd.read_excel('path_to_file.xls', sheetname='Sheet1')
There are many parsing options for read_excel (similar to the options in read_csv.
pd.read_excel('path_to_file.xls',
sheetname='Sheet1', header=[0, 1, 2],
skiprows=3, index_col=0) # etc.
To rename a folder from oldName to newName
git mv directoryToFolder/oldName directoryToFolder/newName
Followed by git commit and/or git push
If this error occurs:
fatal: renaming 'directoryToFolder/oldName' failed: Invalid argument
Use the following command:
git mv directoryToFolder/oldN...
// 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, ...
Unlike regular functions, lambda expressions can capture their environments. Such lambdas are called closures.
// variable definition outside the lambda expression...
let lucky_number: usize = 663;
// but the our function can access it anyway, thanks to the closures
let print_lucky_number = ...
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...
The primary way that you make UI updates to your React applications is through a call to the setState() function. This function will perform a shallow merge between the new state that you provide and the previous state, and will trigger a re-render of your component and all decedents.
Parameters
...
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 ...
// Include sequence containers
#include <vector>
#include <deque>
#include <list>
// Insert sorting algorithm
#include <algorithm>
class Base {
public:
// Constructor that set variable to the value of v
Base(int v): variable(v) {
}
i...