Tutorial by Examples

Rust tuples, as in most other languages, are fixed-size lists whose elements can all be of different types. // Tuples in Rust are comma-separated values or types enclosed in parentheses. let _ = ("hello", 42, true); // The type of a tuple value is a type tuple with the same number of el...
Rust programs use pattern matching extensively to deconstruct values, whether using match, if let, or deconstructing let patterns. Tuples can be deconstructed as you might expect using match fn foo(x: (&str, isize, bool)) { match x { (_, 42, _) => println!("it's 42"),...
To access elements of a tuple directly, you can use the format .n to access the n-th element let x = ("hello", 42, true); assert_eq!(x.0, "hello"); assert_eq!(x.1, 42); assert_eq!(x.2, true); You can also partially move out of a tuple let x = (String::from("hello&quo...
Storing Properties in a XML File The way you store properties files as XML files is very similar to the way you would store them as .properties files. Just instead of using the store() you would use storeToXML(). public void saveProperties(String location) throws IOException{ // make new inst...
This example discusses extending the below type class. trait Show[A] { def show: String } To make a class you control (and is written in Scala) extend the type class, add an implicit to its companion object. Let us show how we can get the Person class from this example to extend Show: class...
If we just try the following: import json from datetime import datetime data = {'datetime': datetime(2016, 9, 26, 4, 44, 0)} print(json.dumps(data)) we get an error saying TypeError: datetime.datetime(2016, 9, 26, 4, 44) is not JSON serializable. To be able to serialize the datetime object p...
In the Project.pro file we add : CONFIG += sql in MainWindow.h we write : #include <QMainWindow> #include <QSql> #include <QDebug> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget...
The Common Language Runtime (CLR) is a virtual machine environment and part of the .NET Framework. It contains: A portable bytecode language called Common Intermediate Language (abbreviated CIL, or IL) A Just-In-Time compiler that generates machine code A tracing garbage collector that provides...
# provision/bootstrap-controller.sh : path and shell filename from vagrantfile location config.vm.define "configcontroller" do |controller| ... controller.vm.provision :shell do |shell| shell.path = "provision/bootstrap-controller.sh" end ...
Considering the following document : <?xml version='1.0' encoding='UTF-8' ?> <library> <book id='1'>Effective Java</book> <book id='2'>Java Concurrency In Practice</book> </library> One can use the following code to build a DOM tree out of a St...
Considering the following document : <?xml version='1.0' encoding='UTF-8' ?> <library> <book id='1'>Effective Java</book> <book id='2'>Java Concurrency In Practice</book> <notABook id='3'>This is not a book element</notABook> </librar...
Method references make excellent self-documenting code, and using method references with Streams makes complicated processes simple to read and understand. Consider the following code: public interface Ordered { default int getOrder(){ return 0; } } public interface Valued&lt...
An object cannot occupy less than 1 byte, as then the members of an array of this type would have the same address. Thus sizeof(T)>=1 always holds. It's also true that a derived class cannot be smaller than any of its base classes. However, when the base class is empty, its size is not necessaril...
How to install the Android Debugging Bridge (ADB) to a Linux system with the terminal using your distro's repositories. Install to Ubuntu/Debian system via apt: sudo apt-get update sudo apt-get install adb Install to Fedora/CentOS system via yum: sudo yum check-update sudo yum install androi...
Gradient Boosting for classification. The Gradient Boosting Classifier is an additive ensemble of a base model whose error is corrected in successive iterations (or stages) by the addition of Regression Trees which correct the residuals (the error of the previous stage). Import: from sklearn.ensem...
Starting an Ionic App $ ionic start myapp [template] Starter templates can either come from a named template, a Github repo, a Codepen, or a local directory. A starter template is what becomes the www directory within the Cordova project. Named template starters tabs (Default) sidemen...
Given a file file.txt with the following content: line 1 line 2 line 3 You can add a new line using below command sed '/line 2/{x;p;x;}' file.txt The above command will output line 1 line 2 line 3 Explanation: x command is eXchange. sed has a buffer that you can use to store some ...
$ cat ip.txt address range substitution pattern sample Range specified is inclusive of those line numbers $ sed -n '2,4p' ip.txt range substitution pattern $ can be used to specify last line. Space can be used between address and command for clarity $ sed -n '3,$ s/[aeiou]/...
$ cat ip.txt address range substitution pattern sample Add Sub Mul Div Lines matching a pattern $ sed '/add/d' ip.txt range substitution pattern sample Add Sub Mul Div $ sed -n '/t/p' ip.txt substitution pattern $ sed -n '/[A-Z]/ s| |/|gp' ip.txt Add/Sub/Mul/Div ...
$ cat ip.txt address range substitution pattern sample Add Sub Mul Div Line number to line matching pattern $ sed -n '2,/pat/p' ip.txt range substitution pattern Line matching pattern to line number $ sed '/pat/,$d' ip.txt address range substitution GNU sed ...

Page 529 of 1336