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...
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...
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':...
Consider the utility class pattern:
a class with only static methods and no fields.
It's recommended to prevent instantiation of such classes by adding a private a constructor.
This live template example makes it easy to add a private constructor to an existing class, using the name of the enclos...
Imagine a goroutine with a two step process, where the main thread needs to do some work between each step:
func main() {
ch := make(chan struct{})
go func() {
// Wait for main thread's signal to begin step one
<-ch
// Perform work
time.Sle...
As a non-standard extension to C++, common compilers allow the use of classes as anonymous members.
struct Example {
struct {
int inner_b;
};
int outer_b;
//The anonymous struct's members are accessed as if members of the parent struct
Example() : inner...
mutable modifier in this context is used to indicate that a data field of a const object may be modified without affecting the externally-visible state of the object.
If you are thinking about caching a result of expensive computation, you should probably use this keyword.
If you have a lock (for ...
Maps and keyword lists have different application. For instance, a map cannot have two keys with the same value and it's not ordered. Conversely, a Keyword list can be a little bit hard to use in pattern matching in some cases.
Here's a few use cases for maps vs keyword lists.
Use keyword lists wh...
This example shows a simple image cropping function that takes an image and cropping coordinates and returns the cropped image.
function cropImage(image, croppingCoords) {
var cc = croppingCoords;
var workCan = document.createElement("canvas"); // create a canvas
workCan.wi...
You can also use the IEx (Interactive Elixir) shell to evaluate expressions and execute code.
If you are on Linux or Mac, just type iex on your bash and press enter:
$ iex
If you are on a Windows machine, type:
C:\ iex.bat
Then you will enter into the IEx REPL (Read, Evaluate, Print, Loop),...