Tutorial by Examples

class Lion { private double weight; // only accessible with-in class this(double weight) { this.weight = weight; } double weightInPounds() const @property // const guarantees no modifications // @property functions are treated as fields { ret...
void main() { import std.stdio : writeln; int[] arr = [1, 3, 4]; for (int i = 0; i < arr.length; i++) { arr[i] *= 2; } writeln(arr); // [2, 6, 8] }
void main() { import std.stdio : writeln; int[] arr = [1, 3, 4]; int i = 0; while (i < arr.length) { arr[i++] *= 2; } writeln(arr); // [2, 6, 8] }
void main() { import std.stdio : writeln; int[] arr = [1, 3, 4]; int i = 0; assert(arr.length > 0, "Array must contain at least one element"); do { arr[i++] *= 2; } while (i < arr.length); writeln(arr); // [2, 6, 8] }
Foreach allows a less error-prone and better readable way to iterate collections. The attribute ref can be used if we want to directly modify the iterated element. void main() { import std.stdio : writeln; int[] arr = [1, 3, 4]; foreach (ref el; arr) { el *= 2; } ...
void main() { import std.stdio : writeln; int[] arr = [1, 3, 4, 5]; foreach (i, el; arr) { if (i == 0) continue; // continue with the next iteration arr[i] *= 2; if (i == 2) break; // stop the loop iteration } writel...
void main() { import std.algorithm : group; import std.range; [1, 2].chain([3, 4]).retro; // [4, 3, 2, 1] [1, 1, 2, 2, 2].group.dropOne.front; // tuple(2, 3u) }
from django.db import models from django.contrib.auth.models import User from django.db.models.signals import post_save from django.dispatch import receiver class UserProfile(models.Model): user = models.OneToOneField(User, related_name='user') website = models.URLField(default='', ...
If an arithmetic operation that yields a floating point type produces a value that is not in the range of representable values of the result type, the behavior is undefined according to the C++ standard, but may be defined by other standards the machine might conform to, such as IEEE 754. float x =...
When either a signed or unsigned integer is converted to a signed integer type, and its value is not representable in the destination type, the value produced is implementation-defined. Example: // Suppose that on this implementation, the range of signed char is -128 to +127 and // the range of un...
C++11 The type_traits header contains a set of template classes and helpers to transform and check properties of types at compile-time. These traits are typically used in templates to check for user errors, support generic programming, and allow for optimizations. Most type traits are used to c...
Here is a simple JsonArray which you would like to convert to a Java ArrayList: { "list": [ "Test_String_1", "Test_String_2" ] } Now pass the JsonArray 'list' to the following method which returns a corresponding...
infixr 5 ++ infixl 4 <*>, <*, *>, <**> infixl 8 `shift`, `rotate`, `shiftL`, `shiftR`, `rotateL`, `rotateR` infix 4 ==, /=, <, <=, >=, > infix ??
Sometimes in a development or testing environment, the SSL certificate chain might not have been fully established (yet). To continue developing and testing, you can turn off SSL verification programmatically by installing an "all-trusting" trust manager: try { // Create a trust mana...
Config values can be set in three ways: Via private static variables on any class within a SilverStripe project Via yaml config files (stored in module-folder/_config/[file].yml) Via PHP at run time (Config::inst()->update('Director', 'environment_type', 'dev') Generally it's best to se...
Emacs uses the terms point, mark, and region to provide more precision about the selected text and position of the cursor. By understanding these terms, it'll help you understand and use other operations and functions. The point is the place in a buffer where editing (i.e. insertion) is currently t...
Killing and yanking more or less correspond to what is usually called "cutting" and "pasting". Killing killing means deleting text, and copying it to the kill-ring (which could be seen as a sort of "clipboard" in the "cut & paste" terminology). The kill ...
Exceptions are powerful, but a single overzealous except clause can take it all away in a single line. try: res = get_result() res = res[0] log('got result: %r' % res) except: if not res: res = '' print('got exception') This example demonstrates 3 symptoms of t...
Download Use Firebird site to download the correct "server package" for your system. First, select the version of Firebird that you would like to install. Next, select the appropriated installer for your system. Example, for almost any version of Windows 32 bits, you would select under ...
The Scala Collections framework, according to its authors, is designed to be easy to use, concise, safe, fast, and universal. The framework is made up of Scala traits that are designed to be building blocks for creating collections. For more information on these building blocks, read the official S...

Page 640 of 1336