Tutorial by Examples: and

The Arbitrary class is for types that can be randomly generated by QuickCheck. The minimal implementation of Arbitrary is the arbitrary method, which runs in the Gen monad to produce a random value. Here is an instance of Arbitrary for the following datatype of non-empty lists. import Test.QuickC...
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...
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 ...
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...
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 ...
Descriptors are objects that are (usually) attributes of classes and that have any of __get__, __set__, or __delete__ special methods. Data Descriptors have any of __set__, or __delete__ These can control the dotted lookup on an instance, and are used to implement functions, staticmethod, classmet...
The UITableViewDelegate is used to control how the table is displayed, and UITableViewDataSource is used to define the UITableView's data. There are two required methods and many optional ones which can be used to customize size, sections, headings, and cells in the UITableView. UITableViewDataSo...
docker rm can be used to remove a specific containers like this: docker rm <container name or id> To remove all containers you can use this expression: docker rm $(docker ps -qa) By default docker will not delete a container that is running. Any container that is running will produce a...
execute the following command to insert the text into a view with a focus (if it supports text input) 6.0 Send text on SDK 23+ adb shell "input keyboard text 'Paste text on Android Device'" If already connected to your device via adb: input text 'Paste text on Android Device' 6...
You can initialize a constant by using the const keyword. const foo = 100; const bar = false; const person = { name: "John" }; const fun = function () = { /* ... */ }; const arrowFun = () => /* ... */ ; Important You must declare and initialize a constant in the same statement....
In all versions of Python, we can represent infinity and NaN ("not a number") as follows: pos_inf = float('inf') # positive infinity neg_inf = float('-inf') # negative infinity not_a_num = float('nan') # NaN ("not a number") In Python 3.5 and higher, we can also us...
.encode and .decode both have error modes. The default is 'strict', which raises exceptions on error. Other modes are more forgiving. Encoding >>> "£13.55".encode('ascii', errors='replace') b'?13.55' >>> "£13.55".encode('ascii', errors='ignore') b'13.55' ...
Template views are fine for static page and you could use them for everything with get_context_data but it would be barely better than using function as views. Enter ListView and DetailView app/models.py from django.db import models class Pokemon(models.Model): name = models.CharField(max...
Writing a view to create object can be quite boring. You have to display a form, you have to validate it, you have to save the item or return the form with an error. Unless you use one of the generic editing views. app/views.py from django.core.urlresolvers import reverse_lazy from django.views.g...
In order to create a random user password we can use the symbols provided in the string module. Specifically punctuation for punctuation symbols, ascii_letters for letters and digits for digits: from string import punctuation, ascii_letters, digits We can then combine all these symbols in a name...
<script> $( ".inclas").datepicker({ minDate: new Date(2007, 1 - 1, 1) maxDate: new Date(2008, 1 - 1, 1) }); </script> <input type ="text" id="datepick" class="inclas">
A Lens' s a means that you can always find an a within any s. A Prism' s a means that you can sometimes find that s actually just is a but sometimes it's something else. To be more clear, we have _1 :: Lens' (a, b) a because any tuple always has a first element. We have _Just :: Prism' (Maybe a) a...
Here is a simple model that we will use to run a few test queries: class MyModel(models.Model): name = models.CharField(max_length=10) model_num = models.IntegerField() flag = models.NullBooleanField(default=False) Get a single model object where the id/pk is 4: (If there are no...
Using Playground it is easy to see that happens inside loops or objects while the change is happening. For example, in the code below, the value of x will change from 1 to 4. import UIKit for x in [1, 2, 3, 4] { x } (1) Clicking on the eye symbol on the right will give us a quick look. (2...
What’s a component? A component is basically a directive that uses a simpler configuration and that is suitable for a component-based architecture, which is what Angular 2 is all about. Think of a component as a widget: A piece of HTML code that you can reuse in several different places in y...

Page 18 of 153