Tutorial by Examples

Calling .Equals() on a delegate compares by reference equality: Action action1 = () => Console.WriteLine("Hello delegates"); Action action2 = () => Console.WriteLine("Hello delegates"); Action action1Again = action1; Console.WriteLine(action1.Equals(action1)) // True ...
Lambdas can be used to create anonymous methods to assign to a delegate: Func<int,int> addOne = x => x+1; Note that the explicit declaration of type is required when creating a variable this way: var addOne = x => x+1; // Does not work
One feature provided for free by case classes is an auto-generated equals method that checks the value equality of all individual member fields instead of just checking the reference equality of the objects. With ordinary classes: class Foo(val i: Int) val a = new Foo(3) val b = new Foo(3) prin...
PHP will generally correctly guess the data type you intend to use from the context it's used in, however sometimes it is useful to manually force a type. This can be accomplished by prefixing the declaration with the name of the required type in parenthesis: $bool = true; var_dump($bool); // bool...
In Python 2, exec is a statement, with special syntax: exec code [in globals[, locals]]. In Python 3 exec is now a function: exec(code, [, globals[, locals]]), and the Python 2 syntax will raise a SyntaxError. As print was changed from statement into a function, a __future__ import was also added. ...
SwiftyJSON is a Swift framework built to remove the need for optional chaining in normal JSON serialization. You can download it here: https://github.com/SwiftyJSON/SwiftyJSON Without SwiftyJSON, your code would look like this to find the name of the first book in a JSON object: if let jsonObject...

Do

Do-loops are useful when you always want to run a codeblock at least once. A Do-loop will evaluate the condition after executing the codeblock, unlike a while-loop which does it before executing the codeblock. You can use do-loops in two ways: Loop while the condition is true: Do { code_...
Closures in Python are created by function calls. Here, the call to makeInc creates a binding for x that is referenced inside the function inc. Each call to makeInc creates a new instance of this function, but each instance has a link to a different binding of x. def makeInc(x): def inc(y): ...
On either Linux/UNIX or Windows, a script can be passed as an argument to the PHP executable, with that script's options and arguments following: php ~/example.php foo bar c:\php\php.exe c:\example.php foo bar This passes foo and bar as arguments to example.php. On Linux/UNIX, the preferred me...
The for keyword is also used for conditional loops, traditionally while loops in other programming languages. package main import ( "fmt" ) func main() { i := 0 for i < 3 { // Will repeat if condition is true i++ fmt.Println(i) } } play ...
In Python 2, when a property raise a error, hasattr will ignore this property, returning False. class A(object): @property def get(self): raise IOError class B(object): @property def get(self): return 'get in b' a = A() b = B() print 'a hasattr get:...
The dynamics of the Geometric Brownian Motion (GBM) are described by the following stochastic differential equation (SDE): I can use the exact solution to the SDE to generate paths that follow a GBM. Given daily parameters for a year-long simulation mu = 0.08/250; sigma = 0.25/sqrt(...
int getListOfFriends(size_t size, int friend_indexes[]) { size_t i = 0; for (; i < size; i++) { friend_indexes[i] = i; } } C99C11 /* Type "void" and VLAs ("int friend_indexes[static size]") require C99 at least. In C11 VLAs are optional. */ void getLis...
Leiningen Note: If you're going to use Leiningen, you first need to download and install JDK 6 or newer. The easiest way to get started with Clojure is to download and install Leiningen, the de facto standard tool to manage Clojure projects. Linux: curl https://raw.githubusercontent.com/technoma...
One of the things that can really boost your productivity while writing the code is effectively navigating the workspace. This also means making it comfortable for the moment. It's possible to achieve this by adjusting which areas of workspaces you see. The buttons on the top of the navigation and ...
/** * Enables output buffer streaming. Calling this function * immediately flushes the buffer to the client, and any * subsequent output will be sent directly to the client. */ function _stream() { ob_implicit_flush(true); ob_end_flush(); }
dnf install erlang elixir
When in a loop, the loop variable (val) in the following example is a single variable that changes value as it goes over the loop. Therefore one must do the following to actually pass each val of values to the goroutine: for val := range values { go func(val interface{}) { fmt.Println...
Template may accept both lvalue and rvalue references using forwarding reference: template <typename T> void f(T &&t); In this case, the real type of t will be deduced depending on the context: struct X { }; X x; f(x); // calls f<X&>(x) f(X()); // calls f<X>(...
<?php for ($i = 0; $i < 10; $i++): do_something($i); endfor; ?> <?php for ($i = 0; $i < 10; $i++): ?> <p>Do something in HTML with <?php echo $i; ?></p> <?php endfor; ?>

Page 147 of 1336