Tutorial by Examples: class

To obtain a reference to a KClass object representing some class use double colons: val c1 = String::class val c2 = MyClass::class
In comparison to regular classes – case classes notation provides several benefits: All constructor arguments are public and can be accessed on initialized objects (normally this is not the case, as demonstrated here): case class Dog1(age: Int) val x = Dog1(18) println(x.age) // 18 (success!...
[^0-9a-zA-Z] This will match all characters that are neither numbers nor letters (alphanumerical characters). If the underscore character _ is also to be negated, the expression can be shortened to: [^\w] Or: \W In the following sentences: Hi, what's up? I can't wait for 2017!...
[^0-9] This will match all characters that are not ASCII digits. If Unicode digits are also to be negated, the following expression can be used, depending on your flavor/language settings: [^\d] This can be shortened to: \D You may need to enable Unicode character properties support expl...
Class composition allows explicit relations between objects. In this example, people live in cities that belong to countries. Composition allows people to access the number of all people living in their country: class Country(object): def __init__(self): self.cities=[] ...
In the timeline of any DisplayObject that is attached as a descendant of the display tree, you can utilise the root property. This property points to the main timeline in the case of no custom document class, or the document class if you do define one. Because root is typed DisplayObject, the compi...
A random forest is a meta estimator that fits a number of decision tree classifiers on various sub-samples of the dataset and use averaging to improve the predictive accuracy and control over-fitting. A simple usage example: Import: from sklearn.ensemble import RandomForestClassifier Define tr...
The Scala compiler prefixes every argument in the parameter list by default with val. This means that, by default, case classes are immutable. Each parameter is given an accessor method, but there are no mutator methods. For example: case class Foo(i: Int) val fooInstance = Foo(1) val j = fooIn...
It's fairly common that you may create a class that implements IDisposable, and then derive classes that also contain managed resources. It is recommendeded to mark the Dispose method with the virtual keyword so that clients have the ability to cleanup any resources they may own. public class Paren...
You can write the default protocol implementation for a specific class. protocol MyProtocol { func doSomething() } extension MyProtocol where Self: UIViewController { func doSomething() { print("UIViewController default protocol implementation") } } class M...
Generic classes can be inherited: // Models class MyFirstModel { } class MySecondModel: MyFirstModel { } // Generic classes class MyFirstGenericClass<T: MyFirstModel> { func doSomethingWithModel(model: T) { // Do something here } } class MySecondGe...
Get the Source Package from http://typo3.org/download/ and upload this package to your web server. Put it one level above the document root. For this manual, we will use the .tar.gz file. Use the shell to execute the according commands: /var/www/site/htdocs/$ cd .. /var/www/site/$ wget get.typo3....
A common task is to convert all columns of a data.frame to character class for ease of manipulation, such as in the cases of sending data.frames to a RDBMS or merging data.frames containing factors where levels may differ between input data.frames. The best time to do this is when the data is read ...
Metaclass syntax Python 2.x2.7 class MyClass(object): __metaclass__ = SomeMetaclass Python 3.x3.0 class MyClass(metaclass=SomeMetaclass): pass Python 2 and 3 compatibility with six import six class MyClass(six.with_metaclass(SomeMetaclass)): pass
document.getElementsByClassName('class-name') will retrieve <a class="class-name">Any</a> <b class="class-name">tag</b> <div class="class-name an-extra-class">with that class.</div> If no existing elements contain the given c...
Imagine that a system want to detect apples and oranges in a basket of fruits. System can pick a fruit, extract some property of it (e.g weight of that fruit). Suppose System has a Teacher! that teaches the system which objects are apples and which are oranges. This is an example of a supervised cl...
Describes ranges of symbols You can enumerate symbols explicitly /[abc]/ # 'a' or 'b' or 'c' Or use ranges /[a-z]/ # from 'a' to 'z' It is possible to combine ranges and single symbols /[a-cz]/ # 'a' or 'b' or 'c' or 'z' Leading dash (-) is treated as charachter /[-a-c]/ # '-' or 'a' o...
Build a text report showing the main classification metrics, including the precision and recall, f1-score (the harmonic mean of precision and recall) and support (the number of observations of that class in the training set). Example from sklearn docs: from sklearn.metrics import classification_re...
public class Singleton { private static class InstanceHolder { static final Singleton INSTANCE = new Singleton(); } public static Singleton getInstance() { return InstanceHolder.INSTANCE; } private Singleton() {} } This initializes the INSTANCE vari...
class sample{ public function __construct(){ add_action('init', array($this, 'samp') ); } public function samp(){ // must be public!! echo 'i did something'; } } new sample();

Page 8 of 28