Tutorial by Examples: c

A comment is marked by an apostrophe ('), and ignored when the code executes. Comments help explain your code to future readers, including yourself. Since all lines starting with a comment are ignored, they can also be used to prevent code from executing (while you debug or refactor). Placing an ap...
Sub RemComments() Rem Comments start with "Rem" (VBA will change any alternate casing to "Rem") Rem is an abbreviation of Remark, and similar to DOS syntax Rem Is a legacy approach to adding comments, and apostrophes should be preferred Rem Comments CANNOT appear af...
Usually authentication&authorization processes are performed by built-in cookie and token supports in .net MVC. But if you decide to do it yourself with Session you can use below logic for both page requests and ajax requests. public class SessionControl : ActionFilterAttribute { public o...
This is an example of how to use the generic type TFood inside Eat method on the class Animal public interface IFood { void EatenBy(Animal animal); } public class Grass: IFood { public void EatenBy(Animal animal) { Console.WriteLine("Grass was eaten by: {0}",...
Along with classic way of route definition MVC WEB API 2 and then MVC 5 frameworks introduced Attribute routing: public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // This...
Currying, according to Wikipedia, is the technique of translating the evaluation of a function that takes multiple arguments into evaluating a sequence of functions. Concretely, in terms of scala types, in the context of a function that take two arguments, (has arity 2) it is the conversion o...
# Generates 5 random numbers from a uniform distribution [0, 1) np.random.rand(5) # Out: array([ 0.4071833 , 0.069167 , 0.69742877, 0.45354268, 0.7220556 ])
# Creates a 5x5 random integer array ranging from 10 (inclusive) to 20 (inclusive) np.random.randint(10, 20, (5, 5)) ''' Out: array([[12, 14, 17, 16, 18], [18, 11, 16, 17, 17], [18, 11, 15, 19, 18], [19, 14, 13, 10, 13], [15, 10, 12, 13, 18]]...
letters = list('abcde') Select three letters randomly (with replacement - same item can be chosen multiple times): np.random.choice(letters, 3) ''' Out: array(['e', 'e', 'd'], dtype='<U1') ''' Sampling without replacement: np.random.choice(letters, 3, replace=False) ''' Out...
Draw samples from a normal (gaussian) distribution # Generate 5 random numbers from a standard normal distribution # (mean = 0, standard deviation = 1) np.random.randn(5) # Out: array([-0.84423086, 0.70564081, -0.39878617, -0.82719653, -0.4157447 ]) # This result can also be achieved with t...
.htaccess can be used to set a custom error pages that matches the theme of your website instead of seeing a white error page with black techno-babble when users end up on at a page with an error server response code. The error page can be any browser parseable file, including (But not limited to)...
In the condition of the for and while loops, it's also permitted to declare an object. This object will be considered to be in scope until the end of the loop, and will persist through each iteration of the loop: for (int i = 0; i < 5; ++i) { do_something(i); } // i is no longer in scope...
Drush status drush status This will give you an overview of your Drupal site. Version, URI, database location, file paths, default theme etc. If you use this command and you do not see this information, it means you are in a wrong folder and Drush does not know which Drupal site you are referrin...
The following method computes the Nth Fibonacci number using recursion. public int fib(final int n) { if (n > 2) { return fib(n - 2) + fib(n - 1); } return 1; } The method implements a base case (n <= 2) and a recursive case (n>2). This illustrates the use of re...
Overload resolution partitions the cost of passing an argument to a parameter into one of four different categorizes, called "sequences". Each sequence may include zero, one or several conversions Standard conversion sequence void f(int a); f(42); User defined conversion seque...
Start two named nodes in two terminal windows: >iex --name [email protected] iex([email protected])> >iex --name [email protected] iex([email protected])> Connect two nodes by instructing one node to connect: iex([email protected])> Node.connect :"[email protected]" true The two n...
Start a named process on one IP address: $ iex --name [email protected] --cookie chocolate iex([email protected])> Node.ping :"[email protected]" :pong iex([email protected])> Node.list [:"[email protected]"] Start another named process on a different IP address: $ iex ...
A factory function is simply a function that returns an object. Factory functions do not require the use of the new keyword, but can still be used to initialize an object, like a constructor. Often, factory functions are used as API wrappers, like in the cases of jQuery and moment.js, so users do ...
Use the HTML or <audio> element to embed video/audio content in a document. The video/audio element contains one or more video/audio sources. To specify a source, use either the src attribute or the <source> element; the browser will choose the most suitable one. Audio tag example: &...
By recursion let rec sumTotal list = match list with | [] -> 0 // empty list -> return 0 | head :: tail -> head + sumTotal tail The above example says: "Look at the list, is it empty? return 0. Otherwise it is a non-empty list. So it could be [1], [1; 2], [1; 2; 3] ...

Page 157 of 826