Tutorial by Examples

fn copy_if<F>(slice: &[i32], pred: F) -> Vec<i32> where for<'a> F: Fn(&'a i32) -> bool { let mut result = vec![]; for &element in slice { if pred(&element) { result.push(element); } } result } This s...
Validate that an attribute's value matches a regular expression using format and the with option. class User < ApplicationRecord validates :name, format: { with: /\A\w{6,10}\z/ } end You can also define a constant and set its value to a regular expression and pass it to the with: option. ...
You can check if a value is included in an array using the inclusion: helper. The :in option and its alias, :within show the set of acceptable values. class Country < ApplicationRecord validates :continent, inclusion: { in: %w(Africa Antartica Asia Australia ...
Add the [Serializable] attribute to mark an entire object for binary serialization: [Serializable] public class Vector { public int X; public int Y; public int Z; [NonSerialized] public decimal DontSerializeThis; [OptionalField] public string Name; } All...
If you use the [NonSerialized] attribute, then that member will always have its default value after deserialization (ex. 0 for an int, null for string, false for a bool, etc.), regardless of any initialization done in the object itself (constructors, declarations, etc.). To compensate, the attribut...
That would get more control over serialization, how to save and load types Implement ISerializable interface and create an empty constructor to compile [Serializable] public class Item : ISerializable { private string _name; public string Name { get { return _name; } ...
Implements a serialization surrogate selector that allows one object to perform serialization and deserialization of another As well allows to properly serialize or deserialize a class that is not itself serializable Implement ISerializationSurrogate interface public class ItemSurrogate : ISerial...
The first element of sys.argv[0] is the name of the python file being executed. The remaining elements are the script arguments. # script.py import sys print(sys.argv[0]) print(sys.argv) $ python script.py => script.py => ['script.py'] $ python script.py fizz => script.py ...
You can install NLTK over pip (pip install nltk).After it is installed, many components will not be present, and you will not be able to use some of NLTK's features. From your Python shell, run the function ntlk.download() to select which additional packages you want to install using UI. Alternati...
In order to sort a query, instead of using findAll(), you should use findAllSorted(). RealmResults<SomeObject> results = realm.where(SomeObject.class) .findAllSorted("sortField", Sort.ASCENDING); Note: sort() returns a completely new ...
Every synchronous query method (such as findAll() or findAllSorted()) has an asynchronous counterpart (findAllAsync() / findAllSortedAsync()). Asynchronous queries offload the evaluation of the RealmResults to another thread. In order to receive these results on the current thread, the current thre...
For queries, Realm provides the realmResults.asObservable() method. Observing results is only possible on looper threads (typically the UI thread). For this to work, your configuration must contain the following realmConfiguration = new RealmConfiguration.Builder(context) // ...
This example goes over how to set up CoreNLP from the latest official release. This example will take you through downloading the package, and running a simple command-line invocation of CoreNLP. Prerequisites: Java JVM 8. The command java -version should complete successfully with a line like: ...
In order to dynamically decide what beans to inject, we can use FactoryBeans. These are classes which implement the factory method pattern, providing instances of beans for the container. They are recognized by Spring and can be used transparently, without need to know that the bean comes from a fac...
When referring to gcc's documentation, you should know which version of gcc you are running. The GCC project has a manual for each version of gcc which includes features that are implemented in that version. Use the '-v' option to determine the version of gcc you are running. gcc -v Example Ou...
A class or struct can also define member type aliases, which are type aliases contained within, and treated as members of, the class itself. struct IHaveATypedef { typedef int MyTypedef; }; struct IHaveATemplateTypedef { template<typename T> using MyTemplateTypedef = std::v...
Some languages have a native structure for sets. To make a set in Go, it's best practice to use a map from the value type of the set to an empty struct (map[Type]struct{}). For example, with strings: // To initialize a set of strings: greetings := map[string]struct{}{ "hi": {}, ...
Problem In a similar way that SQL injection allows an attacker to execute arbitrary queries on a database, command-line injection allows someone to run untrusted system commands on a web server. With an improperly secured server this would give an attacker complete control over a system. Let's sa...
Sometimes you want to have a file held in Git but ignore subsequent changes. Tell Git to ignore changes to a file or directory using update-index: git update-index --assume-unchanged my-file.txt The above command instructs Git to assume my-file.txt hasn't been changed, and not to check or repor...
Starting the Erlang shell On a UNIX system you start the Erlang shell from a command prompt with the command erl Example: $ erl Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] Eshell V7.0 (abort with ^G) 1> The text that shows when y...

Page 555 of 1336