Tutorial by Examples: ase

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...
The above forest methodology is actually a disjoint-set data structure, which involves three main operations: subalgo makeSet(v: a node): v.parent = v <- make a new tree rooted at v subalgo findSet(v: a node): if v.parent == v: return v return findSet(v.parent...
We can do two things to improve the simple and sub-optimal disjoint-set subalgorithms: Path compression heuristic: findSet does not need to ever handle a tree with height bigger than 2. If it ends up iterating such a tree, it can link the lower nodes directly to the root, optimizing future trav...
We can optimize a simple xor function for only architectures that support unaligned reads/writes by creating two files that define the function and prefixing them with a build constraint (for an actual example of the xor code which is out of scope here, see crypto/cipher/xor.go in the standard libra...
Sometimes we want to give a type a more descriptive name. Let's say our app has a data type representing users: { name : String, age : Int, email : String } And our functions on users have type signatures along the lines of: prettyPrintUser : { name : String, age : Int, email : String } -> S...
For example, if you are sending an email to a customer after starting a task, it's best to immediately redirect the user to the next page while queuing the email to be sent in the background. This will speed up the load time for the next page, since sending an email can sometimes take several second...
Firebase Authentication allows the users of your app to sign-in with social providers or their email+password. But what if you want to store additional information about a user, beyond what Firebase Authentication allows you to specify? Or what if you want to display a list of the users in your app...
extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; #[derive(Serialize)] struct Person { #[serde(rename="firstName")] first_name: String, #[serde(rename="lastName")] last_name: String, } fn main() { let person = ...
Run command below to install nginx. sudo apt-get install nginx By default, Nginx automatically starts when it is installed. You can access the default Nginx landing page to confirm that the software is running properly by visiting your server's domain name or public IP address in your web browse...
You can test if a string matches several regular expressions using a switch statement. Example case "Ruby is #1!" when /\APython/ puts "Boooo." when /\ARuby/ puts "You are right." else puts "Sorry, I didn't understand that." end This w...
Like if, when can also be used as an expression: val greeting = when (x) { "English" -> "How are you?" "German" -> "Wie geht es dir?" else -> "I don't know that language yet :(" } print(greeting) To be used as an express...
Given a file sample: hello Hello HELLO_there A normal grep for "hello" returns: $ grep "hello" sample hello Using -i allows to ignore case and match any "hello": $ grep -i "hello" sample hello Hello HELLO_there
A database is created with the following SQL command: CREATE DATABASE myDatabase; This would create an empty database named myDatabase where you can create tables.
Go to File -> Settings -> Editor -> Colors & Fonts -> Android Logcat Change the colors as you need: Choose the appropriate color:
It is also possible to create archives of other items than HEAD, such as branches, commits, tags, and directories. To create an archive of a local branch dev: git archive --output=archive-dev.zip --prefix=src-directory-name dev To create an archive of a remote branch origin/dev: git archive --...
This hook is called before git rebase begins to alter code structure. This hook is typically used for making sure a rebase operation is appropriate. This hook takes 2 parameters: the upstream branch that the series was forked from, and the branch being rebased (empty when rebasing the current b...
If you need to search an ActiveRecord model for similar values, you might be tempted to use LIKE or ILIKE but this isn't portable between database engines. Similarly, resorting to always downcasing or upcasing can create performance issues. You can use ActiveRecord's underlying Arel matches method...
Database configuration of a rails project lies in a file config/database.yml. If you create a project using rails new command and don't specify a database engine to be used then rails uses sqlite as the default database. A typical database.yml file with default configuration will look similar to fol...
Consumable Managed Products are products that can be bought multiple times such as in-game currency, game lives, power-ups, etc. In this example, we are going to implement 4 different consumable managed products "item1", "item2", "item3", "item4". Steps in...
The Set object lets you store unique values of any type, whether primitive values or object references. You can push items into a set and iterate them similar to a plain JavaScript array, but unlike array, you cannot add a value to a Set if the value already exist in it. To create a new set: cons...

Page 9 of 40