Tutorial by Examples: al

Patterns can be matched based on values independent to the value being matched using if guards: // Let's imagine a simplistic web app with the following pages: enum Page { Login, Logout, About, Admin } // We are authenticated let is_authenticated = true; // But we aren't admins...
By default the Python random module use the Mersenne Twister PRNG to generate random numbers, which, although suitable in domains like simulations, fails to meet security requirements in more demanding environments. In order to create a cryptographically secure pseudorandom number, one can use Syst...
public class Singleton { private readonly static Singleton instance = new Singleton(); private Singleton() { } public static Singleton Instance => instance; } This implementation is thread-safe because in this case instance object is initialized in the static constructor. The ...
git shortlog summarizes git log and groups by author If no parameters are given, a list of all commits made per committer will be shown in chronological order. $ git shortlog Committer 1 (<number_of_commits>): Commit Message 1 Commit Message 2 ... Committer 2 (<number_of_...
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 ...
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...
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 ...
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...
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...
<?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; ?>
<?php while ($condition): do_something(); endwhile; ?> <?php while ($condition): ?> <p>Do something in HTML</p> <?php endwhile; ?>
<?php foreach ($collection as $item): do_something($item); endforeach; ?> <?php foreach ($collection as $item): ?> <p>Do something in HTML with <?php echo $item; ?></p> <?php endforeach; ?>
<?php switch ($condition): case $value: do_something(); break; default: do_something_else(); break; endswitch; ?> <?php switch ($condition): ?> <?php case $value: /* having whitespace before your cases will cause an error */ ?&g...
<?php if ($condition): do_something(); elseif ($another_condition): do_something_else(); else: do_something_different(); endif; ?> <?php if ($condition): ?> <p>Do something in HTML</p> <?php elseif ($another_condition): ?> <p>...
Numpy installation through pypi (the default package index used by pip) generally fails on Windows computers. The easiest way to install on Windows is by using precompiled binaries. One source for precompiled wheels of many packages is Christopher Gohkle's site. Choose a version according to your ...
Sometimes, migrations generated by Django are not sufficient. This is especially true when you want to make data migrations. For instance, let's you have such model: class Article(models.Model): title = models.CharField(max_length=70) This model already have existing data and now you want ...
m := make(map[string][]int) Accessing a non-existent key will return a nil slice as a value. Since nil slices act like zero length slices when used with append or other built-in functions you do not normally need to check to see if a key exists: // m["key1"] == nil && len(m[&qu...
Prerequisites nodejs To install the latest stable release of sails with the command-line tool issue following command: $ sudo npm install sails -g Depending on your OS you might not need to use sudo.
If you are using the default bash prompt on Linux, you should see the name of the virtual environment at the start of your prompt. (my-project-env) user@hostname:~$ which python /home/user/my-project-env/bin/python

Page 31 of 269