Using the timeit module from the command line:
> python -m timeit 'for x in xrange(50000): b = x**3'
10 loops, best of 3: 51.2 msec per loop
> python -m timeit 'from math import pow' 'for x in xrange(50000): b = pow(x,3)'
100 loops, best of 3: 9.15 msec per loop
The built-in ** operato...
To get basic information about a DataFrame including the column names and datatypes:
import pandas as pd
df = pd.DataFrame({'integers': [1, 2, 3],
'floats': [1.5, 2.5, 3],
'text': ['a', 'b', 'c'],
'ints with None': [1, None, 3]})
...
SilverStripe can be installed via composer or through the extraction of downloaded zip file.
To install through composer we run the following command
composer create-project silverstripe/installer /path/to/project 3.4.0
A download zip file can be found on the download page of the SilverStripe w...
It is possible to detect whether an operator or function can be called on a type. To test if a class has an overload of std::hash, one can do this:
#include <functional> // for std::hash
#include <type_traits> // for std::false_type and std::true_type
#include <utility> // for s...
You can validate any object, even plain ruby.
class User
include ActiveModel::Validations
attr_reader :name, :age
def initialize(name, age)
@name = name
@age = age
end
validates :name, presence: true
validates :age, numericality: { only_integer: true, greater_than...
If you want to support a url parameter more complex than an id number, you may run into trouble with the parser if the value contains a period. Anything following a period will be assumed to be a format (i.e. json, xml).
You can work around this limitation by using a constraint to broaden the accep...
Euler angles are "degree angles" like 90, 180, 45, 30 degrees. Quaternions differ from Euler angles in that they represent a point on a Unit Sphere (the radius is 1 unit). You can think of this sphere as a 3D version of the Unit circle you learn in trigonometry.
Quaternions differ from Eu...
Quaternion.LookRotation(Vector3 forward [, Vector3 up]) will create a Quaternion rotation that looks forward 'down' the forward vector and has the Y axis aligned with the 'up' vector. If the up vector is not specified, Vector3.up will be used.
Rotate this Game Object to look at a target Game Object...
A recursive function is simply a function, that would call itself.
function factorial (n) {
if (n <= 1) {
return 1;
}
return n * factorial(n - 1);
}
The above function shows a basic example of how to perform a recursive function to return a factorial.
Another...
First of all, we need to add our first Fragment at the beginning, we should do it in the onCreate() method of our Activity:
if (null == savedInstanceState) {
getSupportFragmentManager().beginTransaction()
.addToBackStack("fragmentA")
.replace(R.id.container, FragmentA.n...
You can use flatMap(_:) in a similar manner to map(_:) in order to create an array by applying a transform to a sequence's elements.
extension SequenceType {
public func flatMap<T>(@noescape transform: (Self.Generator.Element) throws -> T?) rethrows -> [T]
}
The difference with...
Create a class inheriting from Exception:
class FooException(Exception):
pass
try:
raise FooException("insert description here")
except FooException:
print("A FooException was raised.")
or another exception type:
class NegativeError(ValueError):
pass
...
Add gem to the Gemfile:
gem 'devise'
Then run the bundle install command.
Use command $ rails generate devise:install to generate required configuration file.
Set up the default URL options for the Devise mailer in each environment
In development environment add this line:
config.action_mailer...