struct A
{
~A() noexcept(false) try
{
// destructor body
}
catch (...)
{
// exceptions of destructor body are caught here
// if no exception is thrown here
// then the caught exception is re-thrown.
}
};
Note that, although this...
It is very convenient to use extension methods with interfaces as implementation can be stored outside of class and all it takes to add some functionality to class is to decorate class with interface.
public interface IInterface
{
string Do()
}
public static class ExtensionMethods{
pu...
dotimes is a macro for integer iteration over a single variable from 0 below some parameter value. One of the simples examples would be:
CL-USER> (dotimes (i 5)
(print i))
0
1
2
3
4
NIL
Note that NIL is the returned value, since we did not provide one ourselves; the v...
Installation
The preferred way to install Mockito is to declare a dependency on mockito-core with a build system of choice. As of July 22nd, 2016, the latest non-beta version is 1.10.19, but 2.x is already encouraged to be migrated to.
Maven
<dependency>
<groupId>org.mockito</...
List doesn't support "random access", which means it takes more work to get, say, the fifth element from the list than the first element, and as a result there's no List.get nth list function. One has to go all the way from the beginning (1 -> 2 -> 3 -> 4 -> 5).
If you need ra...
Arrays can have more than one dimension. The following example creates a two-dimensional array of ten rows and ten columns:
int[,] arr = new int[10, 10];
An array of three dimensions:
int[,,] arr = new int[10, 10, 10];
You can also initialize the array upon declaration:
int[,] arr = new int...
Usually authentication&authorization processes are performed by built-in cookie and token supports in .net MVC. But if you decide to do it yourself with Session you can use below logic for both page requests and ajax requests.
public class SessionControl : ActionFilterAttribute
{
public o...
Along with classic way of route definition MVC WEB API 2 and then MVC 5 frameworks introduced Attribute routing:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// This...
Draw samples from a normal (gaussian) distribution
# Generate 5 random numbers from a standard normal distribution
# (mean = 0, standard deviation = 1)
np.random.randn(5)
# Out: array([-0.84423086, 0.70564081, -0.39878617, -0.82719653, -0.4157447 ])
# This result can also be achieved with t...
Install
npm is bundled with Node.js, so if you install Node.js you'll automatically have npm installed too. You can choose between a Current and a LTS version
Windows
For Microsoft Windows you can download a MSI installer from https://nodejs.org/en/download/.
OS X
For Apple OS X you can downloa...
In the condition of the for and while loops, it's also permitted to declare an object. This object will be considered to be in scope until the end of the loop, and will persist through each iteration of the loop:
for (int i = 0; i < 5; ++i) {
do_something(i);
}
// i is no longer in scope...
The following method computes the Nth Fibonacci number using recursion.
public int fib(final int n) {
if (n > 2) {
return fib(n - 2) + fib(n - 1);
}
return 1;
}
The method implements a base case (n <= 2) and a recursive case (n>2). This illustrates the use of re...
Overload resolution partitions the cost of passing an argument to a parameter into one of four different categorizes, called "sequences". Each sequence may include zero, one or several conversions
Standard conversion sequence
void f(int a); f(42);
User defined conversion seque...