Tutorial by Examples: ecto

git diff myfile.txt Shows the changes between the previous commit of the specified file (myfile.txt) and the locally-modified version that has not yet been staged. This also works for directories: git diff documentation The above shows the changes between the previous commit of all files in ...
Comparing sets In R, a vector may contain duplicated elements: v = "A" w = c("A", "A") However, a set contains only one copy of each element. R treats a vector like a set by taking only its distinct elements, so the two vectors above are regarded as the same: set...
The %in% operator compares a vector with a set. v = "A" w = c("A", "A") w %in% v # TRUE TRUE v %in% w # TRUE Each element on the left is treated individually and tested for membership in the set associated with the vector on the right (consisting of all its...
To find every vector of the form (x, y) where x is drawn from vector X and y from Y, we use expand.grid: X = c(1, 1, 2) Y = c(4, 5) expand.grid(X, Y) # Var1 Var2 # 1 1 4 # 2 1 4 # 3 2 4 # 4 1 5 # 5 1 5 # 6 2 5 The result is a data.frame with one...
unique drops duplicates so that each element in the result is unique (only appears once): x = c(2, 1, 1, 2, 1) unique(x) # 2 1 Values are returned in the order they first appeared. duplicated tags each duplicated element: duplicated(x) # FALSE FALSE TRUE TRUE TRUE anyDuplicated(x) >...
To count how many elements of two sets overlap, one could write a custom function: xtab_set <- function(A, B){ both <- union(A, B) inA <- both %in% A inB <- both %in% B return(table(inA, inB)) } A = 1:20 B = 10:30 xtab_set(A, B) # inB ...
BeautifulSoup has a limited support for CSS selectors, but covers most commonly used ones. Use select() method to find multiple elements and select_one() to find a single element. Basic example: from bs4 import BeautifulSoup data = """ <ul> <li class="item&quo...
A vector is denoted by square brackets: [] ;;=> [] [:foo] ;;=> [:foo] [:foo :bar] ;;=> [:foo :bar] [1 (+ 1 1) 3] ;;=> [1 2 3] In addition using to the literal syntax, you can also use the vector function to construct a vector: (vector) ;;=> [] (vector :foo) ;;=&...
To ignore a file foo.txt in any directory you should just write its name: foo.txt # matches all files 'foo.txt' in any directory If you want to ignore the file only in part of the tree, you can specify the subdirectories of a specific directory with ** pattern: bar/**/foo.txt # matches all file...
You can access SharedPreferences in several ways: Get the default SharedPreferences file: import android.preference.PreferenceManager; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Get a specific SharedPreferences file: public static final String PREF_FILE_NAM...
The Protractor API allows CSS element locators to use the jQuery-like shortcut notation $(). Normal CSS Element Locator: element(by.css('h1.documentation-text[ng-bind="title"]')); element(by.css('[ng-click="submit"])); Shortcut $() CSS Element Locator: $('h1.documentatio...
A VectorDrawable should consist of at least one <path> tag defining a shape <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24.0" android:viewpor...
An AnimatedVectorDrawable requires at least 3 components: A VectorDrawable which will be manipulated An objectAnimator which defines what property to change and how The AnimatedVectorDrawable itself which connects the objectAnimator to the VectorDrawable to create the animation The following...
The most simple data structure available in R is a vector. You can make vectors of numeric values, logical values, and character strings using the c() function. For example: c(1, 2, 3) ## [1] 1 2 3 c(TRUE, TRUE, FALSE) ## [1] TRUE TRUE FALSE c("a", "b", "c") ## ...
Atomic vectors (which excludes lists and expressions, which are also vectors) are subset using the [ operator: # create an example vector v1 <- c("a", "b", "c", "d") # select the third element v1[3] ## [1] "c" The [ operator can also tak...
Deleting files The unlink function deletes a single file and returns whether the operation was successful. $filename = '/path/to/file.txt'; if (file_exists($filename)) { $success = unlink($filename); if (!$success) { throw new Exception("Cannot delete $filename&qu...
fs.access() determines whether a path exists and what permissions a user has to the file or directory at that path. fs.access doesn't return a result rather, if it doesn't return an error, the path exists and the user has the desired permissions. The permission modes are available as a property on ...
Due to Node's asynchronous nature, creating or using a directory by first: checking for its existence with fs.stat(), then creating or using it depending of the results of the existence check, can lead to a race condition if the folder is created between the time of the check and the time of ...
The only time the garbage collector is needed is if you have a reference cycle. The simples example of a reference cycle is one in which A refers to B and B refers to A, while nothing else refers to either A or B. Neither A or B are accessible from anywhere in the program, so they can safely be dest...
Here's how you can destructure a vector: (def my-vec [1 2 3]) Then, for example within a let block, you can extract values from the vector very succinctly as follows: (let [[x y] my-vec] (println "first element:" x ", second element: " y)) ;; first element: 1 , second ele...

Page 3 of 13