Tutorial by Examples: e

A transaction acts on a single database connection. If you have multiple class-specific databases, the transaction will not protect interaction among them. One workaround is to begin a transaction on each class whose models you alter: Student.transaction do Course.transaction do course.enro...
Both #save and #destroy come wrapped in a transaction that ensures that whatever you do in validations or callbacks will happen under its protected cover. So you can use validations to check for values that the transaction depends on or you can raise exceptions in the callbacks to rollback, includin...
Shade is a library developed by OpenStack to simplify interactions with OpenStack clouds, like DreamHost. $ pip install shade
Create a file named launch-server.yaml, that will be our playbook. The first part of the playbook is a list of hosts that your playbook will run on, we only have one, localhost. - hosts: localhost Then we need to define a list of tasks to perform in this playbook. We will only have one that lau...
Run the Ansible playbook: $ ansible-playbook launch-server.yaml You should see output like PLAY [localhost] *************************************************************** TASK [setup] ******************************************************************* ok: [localhost] TASK [launch an U...
Using NuGet Install-Package Cirrious.FluentLayout An expanded example based on the starter example at the GitHub Page, a simple first name, last name labels and fields all stacked one on top of the other: public override void ViewDidLoad() { //create our labels and fields var firstNa...
User-defined functionals Users can create their own functionals to varying degrees of complexity. The following examples are from Functionals by Hadley Wickham: randomise <- function(f) f(runif(1e3)) lapply2 <- function(x, f, ...) { out <- vector("list", length(x...
Nesting is probably most often used to create more specific selectors, but it can also be used simply for code organization. Using the @at-root directive, you can ‘jump out’ of where you nest it in your Sass, bringing you back at the top level. Doing this allows you to keep styles grouped without cr...
Using SVG stroke makes it easier to create a Vector drawable with unified stroke length, as per Material Design guidelines: Consistent stroke weights are key to unifying the overall system icon family. Maintain a 2dp width for all stroke instances, including curves, angles, and both interior and ...
The number that follows the associativity information describes in what order the operators are applied. It must always be between 0 and 9 inclusive. This is commonly referred to as how tightly the operator binds. For example, consider the following fixity declarations (in base) infixl 6 + infixl ...
The following will prompt a user for input, and then store that input as a string (text) in a variable. The variable is then used to give a message to the user. #!/usr/bin/env bash echo "Who are you?" read name echo "Hello, $name." The command read here reads one line of ...
In same cases different models could have same fields and same procedures in the product life cycle. To handle these similarities without having code repetition inheritance could be used. Instead of inheriting a whole class, mixin design pattern offers us to inherit (or some says include) some met...
When matching the path of a route, you can do it explicitly, matching only one path, like so: get "/hello" do return "Hello!" end You can also use a regular expression to match complex routes. Any route which matches the regular expression will run that code block. If m...
To print a test field (TestField) from a test feature class (TestFC) in a test file geodatabase (Test.gdb) located in a temporary folder (C:\Temp): with arcpy.da.SearchCursor(r"C:\Temp\Test.gdb\TestFC",["TestField"]) as cursor: for row in cursor: print row[0]
long fib(long n) { return n < 2 ? n : fib(n - 1) + fib(n - 2); } struct FibStruct(int n) { // Remarks: n is a template ubyte[fib(n)] data; } void main() { import std.stdio : writeln; enum f10 = fib(10); // execute the function at compile-time pragma(msg, f10); /...
class Animal { abstract int maxSize(); // must be implemented by sub-class final float maxSizeInMeters() // can't be overridden by base class { return maxSize() / 100.0; } } class Lion: Animal { override int maxSize() { return 350; } } void main() { ...
void main() { import std.stdio : writeln; int[] arr = [1, 3, 4]; int i = 0; while (i < arr.length) { arr[i++] *= 2; } writeln(arr); // [2, 6, 8] }
void main() { import std.stdio : writeln; int[] arr = [1, 3, 4]; int i = 0; assert(arr.length > 0, "Array must contain at least one element"); do { arr[i++] *= 2; } while (i < arr.length); writeln(arr); // [2, 6, 8] }
Foreach allows a less error-prone and better readable way to iterate collections. The attribute ref can be used if we want to directly modify the iterated element. void main() { import std.stdio : writeln; int[] arr = [1, 3, 4]; foreach (ref el; arr) { el *= 2; } ...
void main() { import std.stdio : writeln; int[] arr = [1, 3, 4, 5]; foreach (i, el; arr) { if (i == 0) continue; // continue with the next iteration arr[i] *= 2; if (i == 2) break; // stop the loop iteration } writel...

Page 566 of 1191