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...
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...
A Stream of items that are in turn streamable can be flattened into a single continuous Stream:
Array of List of Items can be converted into a single List.
List<String> list1 = Arrays.asList("one", "two");
List<String> list2 = Arrays.asList("three"...
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...
JavaScript does not technically support private members as a language feature.
Privacy - described by Douglas Crockford - gets emulated instead via closures
(preserved function scope) that will be generated each with every instantiation call
of a constructor function.
The Queue example demonstra...
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...
It is sometimes useful to verify that your work on Developer edition hasn't introduced a dependency on any features restricted to Enterprise edition.
You can do this using the sys.dm_db_persisted_sku_features system view, like so:
SELECT * FROM sys.dm_db_persisted_sku_features
Against the datab...
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...
from datetime import datetime
import pandas_datareader.data as wb
stocklist = ['AAPL','GOOG','FB','AMZN','COP']
start = datetime(2016,6,8)
end = datetime(2016,6,11)
p = wb.DataReader(stocklist, 'yahoo',start,end)
p - is a pandas panel, with which we can do funny things:
let's see what...
You can iterate on the object returned by groupby(). The iterator contains (Category, DataFrame) tuples.
# Same example data as in the previous example.
import numpy as np
import pandas as pd
np.random.seed(0)
df = pd.DataFrame({'Age': np.random.randint(20, 70, 100),
'Sex':...
Unnamed class types may also be used when creating type aliases, i.e. via typedef and using:
C++11
using vec2d = struct {
float x;
float y;
};
typedef struct {
float x;
float y;
} vec2d;
vec2d pt;
pt.x = 4.f;
pt.y = 3.f;