Tutorial by Examples: e

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...
Detailed instructions on getting math set up or installed.
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...
generate sample DF In [39]: df = pd.DataFrame(np.random.randint(0, 10, size=(5, 6)), columns=['a10','a20','a25','b','c','d']) In [40]: df Out[40]: a10 a20 a25 b c d 0 2 3 7 5 4 7 1 3 1 5 7 2 6 2 7 4 9 0 8 7 3 5 8 8 9 6 8 4 8 1 ...
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...
import os import glob import pandas as pd def get_merged_csv(flist, **kwargs): return pd.concat([pd.read_csv(f, **kwargs) for f in flist], ignore_index=True) path = 'C:/Users/csvfiles' fmask = os.path.join(path, '*mask*.csv') df = get_merged_csv(glob.glob(fmask), index_col=None, use...
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':...
@org.junit.Test public void should_$name$() { $END$ } Make sure to check the Shorted FQ names box when creating this template. When you type "should" (the abbreviation), this will add the necessary import org.junit.Test; statement at the top of the file, and this code: @Test...
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...
You can join (concatenate) binaries (including strings) and lists: iex(1)> [1, 2, 3] ++ [4, 5] [1, 2, 3, 4, 5] iex(2)> [1, 2, 3, 4, 5] -- [1, 3] [2, 4, 5] iex(3)> "qwe" <> "rty" "qwerty"
in operator allows you to check whether a list or a range includes an item: iex(4)> 1 in [1, 2, 3, 4] true iex(5)> 0 in (1..5) false
main.go: package main import ( "fmt" "io/ioutil" "log" "net/http" ) func fetchContent(url string) (string, error) { res, err := http.Get(url) if err != nil { return "", nil } defer res.Body.Clo...
Unlike a named class or struct, unnamed classes and structs must be instantiated where they are defined, and cannot have constructors or destructors. struct { int foo; double bar; } foobar; foobar.foo = 5; foobar.bar = 4.0; class { int baz; public: int buzz; ...
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...
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;
extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; use std::collections::BTreeMap as Map; #[derive(Serialize)] struct Resource { // Always serialized. name: String, // Never serialized. #[serde(skip_serializing)] hash: String, ...
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 ...
By default, the implicit operator() of a lambda is const. This disallows performing non-const operations on the lambda. In order to allow modifying members, a lambda may be marked mutable, which makes the implicit operator() non-const: int a = 0; auto bad_counter = [a] { return a++; // er...

Page 304 of 1191