If you need to know whether a value's type extends or implements a given type, but you don't want to actually cast it as that type, you can use the is operator.
if(value is int)
{
Console.WriteLine(value + "is an int");
}
Explicit casting operators can be used to perform conversions of numeric types, even though they don't extend or implement one another.
double value = -1.1;
int number = (int) value;
Note that in cases where the destination type has less precision than the original type, precision will be lost....
public class Singleton {
private static class InstanceHolder {
static final Singleton INSTANCE = new Singleton();
}
public static Singleton getInstance() {
return InstanceHolder.INSTANCE;
}
private Singleton() {}
}
This initializes the INSTANCE vari...
Prerequisites
The Windows version of Elasticsearch can be obtained from this link: https://www.elastic.co/downloads/elasticsearch. The latest stable release is always at the top.
As we are installing on Windows, we need the .ZIP archive. Click the link in the Downloads: section and save the file t...
class sample{
public function __construct(){
add_action('init', array($this, 'samp') );
}
public function samp(){ // must be public!!
echo 'i did something';
}
}
new sample();
class sample{
public static function add_action_func(){
//note __CLASS__ will also include any namespacing
add_action('init', array(__CLASS__, 'samp') );
}
public static function samp(){
echo 'i did something';
}
}
sample::add_a...
A generator is a combination of two things - an Iterator and an Observer.
Iterator
An iterator is something when invoked returns an iterable. An iterable is something you can iterate upon. From ES6/ES2015 onwards, all collections (Array, Map, Set, WeakMap, WeakSet) conform to the Iterable contract...
OpenSSL is an open source project that provides a robust, commercial-grade, and full-featured toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. It is also a general-purpose cryptography library.
The OpenSSL toolkit is licensed under an Apache-style license, wh...
To create a Grails application, use the grails create-app command. The following command creates a Grails application, named myapp in the current directory:
grails create-app fancy-app
Running it, is as simple as visiting the, newly created, application directory:
cd fancy-app
and then
grai...
Package names
Package names should be all lower case without underscores or other special characters.
Package names begin with the reversed authority part of the web address of the company of the developer. This part can be followed a by project/program structure dependent package substructure.
...
The .split() method splits a string into an array of substrings. By default .split() will break the string into substrings on spaces (" "), which is equivalent to calling .split(" ").
The parameter passed to .split() specifies the character, or the regular expression, to use for...
Memoization consists of caching function results to avoid computing the same result multiple times. This is useful when working with functions that perform costly computations.
We can use a simple factorial function as an example:
let factorial index =
let rec innerLoop i acc =
match...
Most browsers, when configured to block cookies, will also block localStorage. Attempts to use it will result in an exception. Do not forget to manage these cases.
var video = document.querySelector('video')
try {
video.volume = localStorage.getItem('volume')
} catch (error) {
alert('If...
data(AirPassengers)
class(AirPassengers)
1 "ts"
In the spirit of Exploratory Data Analysis (EDA) a good first step is to look at a plot of your time-series data:
plot(AirPassengers) # plot the raw data
abline(reg=lm(AirPassengers~time(AirPassengers))) # fit a trend line
For...