If you want two or more arguments to be mutually exclusive. You can use the function argparse.ArgumentParser.add_mutually_exclusive_group(). In the example below, either foo or bar can exist but not both at the same time.
import argparse
parser = argparse.ArgumentParser()
group = parser.add_mut...
Create a DataFrame from multiple lists by passing a dict whose values lists. The keys of the dictionary are used as column labels. The lists can also be ndarrays. The lists/ndarrays must all be the same length.
import pandas as pd
# Create DF from dict of lists/ndarrays
df = pd.DataFrame({'...
If a class extends another class and would use the same metadata, providing it @inheritDoc is a simple way for use the same documentation. If multiple classes inherit from a base, only the base would need to be changed for the children to be affected.
abstract class FooBase
{
/**
* @par...
In order to define a variable inside a linq expression, you can use the let keyword. This is usually done in order to store the results of intermediate sub-queries, for example:
int[] numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
var aboveAverages = from number in numbers
l...
The \b metacharacter
To make it easier to find whole words, we can use the metacharacter \b. It marks the beginning and the end of an alphanumeric sequence*. Also, since it only serves to mark this locations, it actually matches no character on its own.
*: It is common to call an alphanumeric sequ...
A reference is a scalar variable (one prefixed by $ ) which “refers to” some other data.
my $value = "Hello";
my $reference = \$value;
print $value; # => Hello
print $reference; # => SCALAR(0x2683310)
To get the referred-to data, you de-reference it.
say ${$reference}...
Array References are scalars ($) which refer to Arrays.
my @array = ("Hello"); # Creating array, assigning value from a list
my $array_reference = \@array;
These can be created more short-hand as follows:
my $other_array_reference = ["Hello"];
Modifying / Using array ref...
The URLRequest and URLLoader classes work together to make requests from Flash to external resources. The URLRequest defines information about the request e.g. the request body and the request method type, and the URLLoader references this to perform the actual request and provide a means of being n...
The URLVariables class allows you to define data to be sent along with a URLRequest.
Example:
var variables:URLVariables = new URLVariables();
variables.prop = "hello";
variables.anotherProp = 10;
var request:URLRequest = new URLRequest('http://someservice.com');
request.data = v...
Assuming we have an array myArray:
var value:* = myArray[int(Math.random() * myArray.length)];
Note we use int to cast the result of Math.random() to an int because values like 2.4539543 would not be a valid array index.
To get any random color:
function randomColor():uint
{
return Math.random() * 0xFFFFFF;
}
If you need more control over the red, green and blue channels:
var r:uint = Math.random() * 0xFF;
var g:uint = Math.random() * 0xFF;
var b:uint = Math.random() * 0xFF;
var color:uint = r <&...
array_chunk() splits an array into chunks
Let's say we've following single dimensional array,
$input_array = array('a', 'b', 'c', 'd', 'e');
Now using array_chunk() on above PHP array,
$output_array = array_chunk($input_array, 2);
Above code will make chunks of 2 array elements and create a...
To round a value to the nearest multiple of x:
function roundTo(value:Number, to:Number):Number {
return Math.round(value / to) * to;
}
Example:
roundTo(8, 5); // 10
roundTo(17, 3); // 18
The static method Date.now returns the number of milliseconds that have elapsed since 1 January 1970 00:00:00 UTC. To get the number of milliseconds that have elapsed since that time using an instance of a Date object, use its getTime method.
// get milliseconds using static method now of Date
co...
cd ~/Projects
valet park
This command will register your current working directory as a path that Valet should search for sites. Now, any Laravel project you create within your "parked" directory will automatically be served using the http://folder-name.dev convention.
Equality
For basic equality testing, the equal operator == is used. For more comprehensive checks, use the identical operator ===.
The identical operator works the same as the equal operator, requiring its operands have the same value, but also requires them to have the same data type.
For exampl...
from pandas_datareader import data
# Only get the adjusted close.
aapl = data.DataReader("AAPL",
start='2015-1-1',
end='2015-12-31',
data_source='yahoo')['Adj Close']
>>> aapl.plot(title='AAPL Adj. C...
This method will work on modern versions of Arch, CentOS, CoreOS, Debian, Fedora, Mageia, openSUSE, Red Hat Enterprise Linux, SUSE Linux Enterprise Server, Ubuntu, and others. This wide applicability makes it an ideal as a first approach, with fallback to other methods if you need to also identify o...