Tutorial by Examples: e

module.exports.routes = { // This function will be executed for all http verbs on all urls 'all /*', function (req, res, next) { // Expose the function `fooBar` to all views (via the locals object) res.locals.fooBar = function (arg1) { return 'foobar' + arg1; }; }, };...
module.exports.routes = { 'GET /foo/*': { fn: function(req, res) { res.send("FOO!"); }, skipAssets: true }, };
Pattern synonyms are abstractions of patterns similar to how functions are abstractions of expressions. For this example, let's look at the interface Data.Sequence exposes, and let's see how it can be improved with pattern synonyms. The Seq type is a data type that, internally, uses a complicated r...
A real world example using a scientific experiment where certain routines are performed on different types of tissue. The class contains two functions by default to get the tissue or routine separately. In a later version we have then adapted it using a new class to add a function that gets both. Th...
Visitor pattern allows you to add new operations or methods to a set of classes without modifying the structure of those classes. This pattern is especially useful when you want to centralise a particular operation on an object without extending the object Or without modifying the object. UML diag...
Lets assume that in your current codebase, there exists MyLogger interface like so: interface MyLogger { void logMessage(String message); void logException(Throwable exception); } Lets say that you've created a few concrete implementations of these, such as MyFileLogger and MyConsol...
The yield keyword allows lazy-evaluation of the collection. Forcibly loading the whole collection into memory is called eager evaluation. The following code shows this: IEnumerable<int> myMethod() { for(int i=0; i <= 8675309; i++) { yield return i; } } ... // ...
Consider using Extension Methods as Functions which wrap other code, here's a great example that uses both a static method and and extension method to wrap the Try Catch construct. Make your code Bullet Proof... using System; using System.Diagnostics; namespace Samples { /// <summary&g...
Database connections are set up using the CF Administrator tool. See Database Connections for how to connect a datasource. To execute queries all you need is the <cfquery> tag. The <cfquery> tag connects to and opens the database for you, all you need to do is supply it with the name of...
Many database configurations require authentication (in the form of a username and password) before you can query the database. You can supply these using the username and password attributes. Note: the username and password can also be configured against the datasource in the ColdFusion Administra...
A cached query is a query that has its results stored in the server's memory. The results are stored when the query is first run. From then on, whenever that query is requested again, ColdFusion will retrieve the results from memory. You can cache a query using the cachedAfter attribute. If the que...
You can limit the number of rows to be returned by using the maxrows attribute. <cfquery datasource="Entertainment" maxrows="50"> select * from Movies </cfquery>
You can set a timeout limit using the timeout attribute. This can be useful in preventing requests running far longer than they should and impacting on the whole application as a result. The timeout attribute sets the maximum number of seconds that each action of a query is allowed to execute befor...
create destination with <a id="destinationLinkName"></a> link to destination [link text](#destinationLinkName)
If you want to make internal classes or functions of an assembly accessable from another assembly you declare this by InternalsVisibleTo and the assembly name that is allowed to access. In this example code in the assembly MyAssembly.UnitTests is allowed to call internal elements from MyAssembly. ...
Structures in Rust are defined using the struct keyword. The most common form of structure consists of a set of named fields: struct Foo { my_bool: bool, my_num: isize, my_string: String, } The above declares a struct with three fields: my_bool, my_num, and my_string, of the type...
Consider the following struct definitions: struct Foo { my_bool: bool, my_num: isize, my_string: String, } struct Bar (bool, isize, String); struct Baz; Constructing new structure values for these types is straightforward: let foo = Foo { my_bool: true, my_num: 42, my_string: ...
To declare methods on a struct (i.e., functions that can be called "on" the struct, or values of that struct type), create an impl block: impl Foo { fn fiddle(&self) { // "self" refers to the value this method is being called on println!("fiddling...
Structures can be made generic over one or more type parameters. These types are given enclosed in <> when referring to the type: struct Gen<T> { x: T, z: isize, } // ... let _: Gen<bool> = Gen{x: true, z: 1}; let _: Gen<isize> = Gen{x: 42, z: 2}; let _: Gen...
C.I.A.s are intended as a simple way of getting attributes from whatever is calling the targeted method. There is really only 1 way to use them and there are only 3 attributes. Example: //This is the "calling method": the method that is calling the target method public void doProcess() ...

Page 550 of 1191