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':...
@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...
Atoms are constants that represent a name of some thing. The value of an atom is it's name. An atom name starts with a colon.
:atom # that's how we define an atom
An atom's name is unique. Two atoms with the same names always are equal.
iex(1)> a = :atom
:atom
iex(2)> b = :atom
:at...
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),...
When you document your code with @doc, you can supply code examples like so:
# myproject/lib/my_module.exs
defmodule MyModule do
@doc """
Given a number, returns `true` if the number is even, otherwise `false`.
## Example
iex> MyModule.even?(2)
true
ie...
The code listing below attempts to classify handwritten digits from the MNIST dataset. The digits look like this:
The code will preprocess these digits, converting each image into a 2D array of 0s and 1s, and then use this data to train a neural network with upto 97% accuracy (50 epochs).
"...
struct FileAttributes
{
unsigned int ReadOnly: 1;
unsigned int Hidden: 1;
};
Here, each of these two fields will occupy 1 bit in memory. It is specified by : 1 expression after the variable names. Base type of bit field could be any integral type (8-bit int to 64-bit int). Using u...
C++11
In C++11, compilers are required to implicitly move from a local variable that is being returned. Moreover, most compilers can perform copy elision in many cases and elide the move altogether. As a result of this, returning large objects that can be moved cheaply no longer requires special ha...
Let's have a basic failing program:
#include <iostream>
void fail() {
int *p1;
int *p2(NULL);
int *p3 = p1;
if (p3) {
std::cout << *p3 << std::endl;
}
}
int main() {
fail();
}
Build it (add -g to include debug info):
g++ -g -o m...