Tutorial by Examples: c

The ngCopy directive specifies behavior to be run on a copy event. Prevent a user from copying data <p ng-copy="blockCopy($event)">This paragraph cannot be copied</p> In the controller $scope.blockCopy = function(event) { event.preventDefault(); console.log(&quo...
Get current time: Time.now Time.new # is equivalent if used with no parameters Get specific time: Time.new(2010, 3, 10) #10 March 2010 (Midnight) Time.new(2015, 5, 3, 10, 14) #10:14 AM on 3 May 2015 Time.new(2050, "May", 3, 21, 8, 16, "+10:00") #09:08:16 PM on 3 May 2050...
For example: ActiveRecord::Base.transaction do david.withdrawal(100) mary.deposit(100) end This example will only take money from David and give it to Mary if neither withdrawal nor deposit raise an exception. Exceptions will force a ROLLBACK that returns the database to the state before ...
Though the transaction class method is called on some ActiveRecord class, the objects within the transaction block need not all be instances of that class. This is because transactions are per-database connection, not per-model. In this example a balance record is transactionally saved even though ...
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...
There are two types of callbacks associated with committing and rolling back transactions: after_commit and after_rollback. after_commit callbacks are called on every record saved or destroyed within a transaction immediately after the transaction is committed. after_rollback callbacks are called o...
ActiveRecord::Base.transaction uses the ActiveRecord::Rollback exception to distinguish a deliberate rollback from other exceptional situations. Normally, raising an exception will cause the .transaction method to rollback the database transaction and pass on the exception. But if you raise an Activ...
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...
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...
Built-in functionals: lapply(), sapply(), and mapply() R comes with built-in functionals, of which perhaps the most well-known are the apply family of functions. Here is a description of some of the most common apply functions: lapply() = takes a list as an argument and applies the specified ...
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...
infixl vs infixr vs infix describe on which sides the parens will be grouped. For example, consider the following fixity declarations (in base) infixl 6 - infixr 5 : infix 4 == The infixl tells us that - has left associativity, which means that 1 - 2 - 3 - 4 gets parsed as ((1 - 2) - 3) - 4 ...
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 ...
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() { ...
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 397 of 826