Tutorial by Examples: disc

When defining discriminated unions you can name elements of tuple types and use these names during pattern matching. type Shape = | Circle of diameter:int | Rectangle of width:int * height:int let shapeIsTenWide = function | Circle(diameter=10) | Rectangle(width=10) -> t...
Discriminated unions in F# offer a a way to define types which may hold any number of different data types. Their functionality is similar to C++ unions or VB variants, but with the additional benefit of being type safe. // define a discriminated union that can hold either a float or a string type...
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
A single case discriminated union is like any other discriminated union except that it only has one case. // Define single-case discriminated union type. type OrderId = OrderId of int // Construct OrderId type. let order = OrderId 123 // Deconstruct using pattern matching. // Parentheses used...
Sometimes it is useful to create union types with only one case to implement record-like types: type Point = Point of float * float let point1 = Point(0.0, 3.0) let point2 = Point(-2.5, -4.0) These become very useful because they can be decomposed via pattern matching in the same way as tu...
private static final int REQUEST_DISCOVERABLE_BT = 2; // Unique request code private static final int DISCOVERABLE_DURATION = 120; // Discoverable duration time in seconds // 0 means always discoverable ...
redis-cli is the Redis command line interface program that allows to send commands to Redis and read the replies sent by the server, directly from the terminal. Basic command line usage is below: Access to redis: $ redis-cli 127.0.0.1:6379> Access to redis with authentication: $ redis-cli ...
Recursive type Discriminated unions can be recursive, that is they can refer to themselves in their definition. The prime example here is a tree: type Tree = | Branch of int * Tree list | Leaf of int As an example, let's define the following tree: 1 2 5 3 4 We can defi...
By default Code First includes in model Types defined as a DbSet property in context class. Reference types included in entity types even if they are defined in different assembly. Derived classes even if only the base class is defined as DbSet property Here is an example, that we are only...
The revert command allows discarding unwanted uncommitted changes. Reverting changes to a single file. hg revert example.c Reverting all changes. This will discard all changes not just the current directory. hg revert --all hg will output which files were reverted. reverting exa...
C++17 The [[nodiscard]] attribute can be used to indicate that the return value of a function shouldn't be ignored when you do a function call. If the return value is ignored, the compiler should give a warning on this. The attribute can be added to: A function definition A type Adding the a...
If you have predefined ranges and want to use specific colors for those ranges you can declare custom colormap. For example: import matplotlib.pyplot as plt import numpy as np import matplotlib.colors x = np.linspace(-2,2,500) y = np.linspace(-2,2,500) XX, YY = np.meshgrid(x, y) Z = np.sin(...
Assuming that you are running redis server on localhost you can type command redis-cli After this command appear redis command line prompt 127.0.0.1:6379>
Overloading the disconnect function allows you to handle what to do when a user disconnects. public override Task OnDisconnected(bool stopCalled) { //Your disconnect logic here return base.OnDisconnected(stopCalled); }
/// <summary> /// Overrides the onDisconnected function and sets the user object to offline, this can be checked when other players interacts with them... /// </summary> /// <param name="stopCalled"></param> /// <returns></returns&gt...
The Redis PHP module gives access to the same commands as the Redis CLI client so it is quite straightforward to use. The syntax is as follow: // Creates two new keys: $redis->set('mykey-1', 123); $redis->set('mykey-2', 'abcd'); // Gets one key (prints '123') var_dump($redis->get('m...
One day I had a conversation with a friend of mine who uses Laravel PHP framework in his job. When I told him that Django has its own all-included HTML CRUD system, for interacting with the database, called Django admin, his eyes popped off! He told me: "It took me months to build an Admin inte...
A common usecase is to discard certain rest-calls, that are not needed any more after certain user-inputs. The most prominent example would be, when a user uses some search-function, makes a request, makes another request and for some reason the first request arrives after the second request and the...
The PERCENTILE_DISC function lists the value of the first entry where the cumulative distribution is higher than the percentile that you provide using the numeric_literal parameter. The values are grouped by rowset or partition, as specified by the WITHIN GROUP clause. The PERCENTILE_CONT functi...
In the case of a discriminated record type, some of the components are known as discriminants and the remaining components can depend upon these. The discriminants can be thought of as parameterizing the type and the syntax reveals this analogy. In this example we create a type that provide a sq...

Page 1 of 2