Tutorial by Examples

The operator for an "exclusive or" (for short XOR) is: ^ This operator returns true when one, but only one, of the supplied bools are true. true ^ false // Returns true false ^ true // Returns true false ^ false // Returns false true ^ true // Returns false
It's possible to declare protocol name without methods: @protocol Person; use it your code (class definition, etc): @interface World : NSObject @property (strong, nonatomic) NSArray<id<some>> *employees; @end and later define protocol's method somewhere in your code: @protocol...
It is possible to bind values to names using @: struct Badger { pub age: u8 } fn main() { // Let's create a Badger instances let badger_john = Badger { age: 8 }; // Now try to find out what John's favourite activity is, based on his age match badger_john.age { ...
// Create a boolean value let a = true; // The following expression will try and find a pattern for our value starting with // the topmost pattern. // This is an exhaustive match expression because it checks for every possible value match a { true => println!("a is true"), ...
It's possible to treat multiple, distinct values the same way, using |: enum Colour { Red, Green, Blue, Cyan, Magenta, Yellow, Black } enum ColourModel { RGB, CMYK } // let's take an example colour let colour = Colour::Red; let model = match ...
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...
To select the children of an element you can use the children() method. <div class="parent"> <h2>A headline</h2> <p>Lorem ipsum dolor sit amet...</p> <p>Praesent quis dolor turpis...</p> </div> Change the color of all the ...
// View to hold the CAGradientLayer. let view: UIView = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 320)) // Initialize gradient layer. let gradientLayer: CAGradientLayer = CAGradientLayer() // Set frame of gradient layer. gradientLayer.frame = view.bounds // Color at...
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...
index.html <!doctype html> <html> <head> <title>D3 Sample</title> </head> <body> <!-- This will serve as a container for our chart. This does not have to be a div, and can in fact, just be the body if you want. --> <div id=...
docker restart <container> [<container>...] Option --time : Seconds to wait for stop before killing the container (default 10) docker restart <container> --time 10
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 ...
This thread-safe version of a singleton was necessary in the early versions of .NET where static initialization was not guaranteed to be thread-safe. In more modern versions of the framework a statically initialized singleton is usually preferred because it is very easy to make implementation mistak...
To avoid repetition in nested routes, concerns provide a great way of sharing common resources that are reusable. To create a concern use the method concern within the routes.rb file. The method expects a symbol and block: concern :commentable do resources :comments end While not creating a...
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_...
The flow of execution of a Ruby block may be controlled with the break, next, and redo statements. break The break statement will exit the block immediately. Any remaining instructions in the block will be skipped, and the iteration will end: actions = %w(run jump swim exit macarena) index = 0 ...
When assigning named methods to delegates, they will refer to the same underlying object if: They are the same instance method, on the same instance of a class They are the same static method on a class public class Greeter { public void WriteInstance() { Console.Write...
The following syntax creates a delegate type with name NumberInOutDelegate, representing a method which takes an int and returns an int. public delegate int NumberInOutDelegate(int input); This can be used as follows: public static class Program { static void Main() { Number...
The System namespace contains Func<..., TResult> delegate types with between 0 and 15 generic parameters, returning type TResult. private void UseFunc(Func<string> func) { string output = func(); // Func with a single generic type parameter returns that type Console.WriteLine...
Named methods can be assigned to delegates with matching signatures: public static class Example { public static int AddOne(int input) { return input + 1; } } Func<int,int> addOne = Example.AddOne Example.AddOne takes an int and returns an int, its signature ...

Page 146 of 1336