Tutorial by Examples

[HttpPost] public ActionResult ContactUs(ContactUsModel contactObject) { // This line checks to see if the Model is Valid by verifying each Property in the Model meets the data validation rules if(ModelState.IsValid) { } return View(contactObject); } The model class p...
def addNumbers = { a, b -> a + b } addNumbers(-7, 15) // returns 8
['cat', 'dog', 'fish'].collect { it.length() } it is the default name of the parameter if you have a single parameter and do not explicitly name the parameter. You can optionally declare the parameter as well. ['cat', 'dog', 'fish'].collect { animal -> animal.length() }
Build a text report showing the main classification metrics, including the precision and recall, f1-score (the harmonic mean of precision and recall) and support (the number of observations of that class in the training set). Example from sklearn docs: from sklearn.metrics import classification_re...
Groovy has access to all java classes, in fact Groovy classes ARE Java classes and can be run by the JVM directly. If you are working on a Java project, using Groovy as a simple scripting language to interact with your java code is a no-brainer. To make things even better, nearly any Java class ca...
String literals represent null-terminated, static-duration arrays of char. Because they have static storage duration, a string literal or a pointer to the same underlying array can safely be used in several ways that a pointer to an automatic array cannot. For example, returning a string literal f...
val str = "Hello!" if (str.length == 0) { print("The string is empty!") } else if (str.length > 5) { print("The string is short!") } else { print("The string is long!") } The else-branches are optional in normal if-statements.
If-statements can be expressions: val str = if (condition) "Condition met!" else "Condition not met!" Note that the else-branch is not optional if the if-statement is used as an expression. This can also been done with a multi-line variant with curly brackets and multiple el...
The when-statement is an alternative to an if-statement with multiple else-if-branches: when { str.length == 0 -> print("The string is empty!") str.length > 5 -> print("The string is short!") else -> print("The string is long!") ...
When given an argument, the when-statement matches the argument against the branches in sequence. The matching is done using the == operator which performs null checks and compares the operands using the equals function. The first matching one will be executed. when (x) { "English" -...
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...
(This pitfall applies equally to all primitive wrapper types, but we will illustrate it for Integer and int.) When working with Integer objects, it is tempting to use == to compare values, because that is what you would do with int values. And in some cases this will seem to work: Integer int1_1 =...
To get the next element you can use the .next() method. <ul> <li>Mark</li> <li class="anna">Anna</li> <li>Paul</li> </ul> If you are standing on the "Anna" element and you want to get the next element, "Paul...
1. Fix your contexts: Try using the appropriate context: For example since a Toast can be seen in many activities instead of in just one, use getApplicationContext() for toasts, and since services can keep running even though an activity has ended start a service with: Intent myService = new Inten...
Getting a reference to a named sheet tab var spread_sheet = SpreadsheetApp.getActiveSpreadsheet();//Get active spreadsheet var sheet_with_name_a = spread_sheet.getSheetByName("sheet_tab_name"); Getting active sheet tab var spread_sheet = SpreadsheetApp.getActiveSpreadsheet(); var ac...
Custom constructors can be made for derived types by using an interface to overload the type name. This way, keyword arguments that don't correspond to components can be used when constructing an object of that type. module ball_mod implicit none ! only export the derived type, and not any ...
The .format() method can interpret a number in different formats, such as: >>> '{:c}'.format(65) # Unicode character 'A' >>> '{:d}'.format(0x0a) # base 10 '10' >>> '{:n}'.format(0x0a) # base 10 using current locale for separators '10' Format integers to d...
union U { int a; short b; float c; }; U u; u.a = 10; if (u.b == 10) { // this is undefined behavior since 'a' was the last member to be // written to. A lot of compilers will allow this and might issue a // warning, but the result will be "as expected"; thi...
Properties can be set when an object is instantiated. var redCar = new Car { Wheels = 2, Year = 2016, Color = Color.Red };
functions.php //Localize the AJAX URL and Nonce add_action('wp_enqueue_scripts', 'example_localize_ajax'); function example_localize_ajax(){ wp_localize_script('jquery', 'ajax', array( 'url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('example_ajax_nonc...

Page 341 of 1336