Tutorial by Examples: al

import std.stdio; void main() { int[] arr = [1, 2, 3, 4]; writeln(arr.length); // 4 writeln(arr[2]); // 3 // type inference still works auto arr2 = [1, 2, 3, 4]; writeln(typeof(arr2).stringof); // int[] }
import std.format; void main() { string s = "Name Surname 18"; string name, surname; int age; formattedRead(s, "%s %s %s", &name, &surname, &age); // %s selects a format based on the corresponding argument's type } Official documentatio...
[^0-9a-zA-Z] This will match all characters that are neither numbers nor letters (alphanumerical characters). If the underscore character _ is also to be negated, the expression can be shortened to: [^\w] Or: \W In the following sentences: Hi, what's up? I can't wait for 2017!...
SequenceEqual is used to compare two IEnumerable<T> sequences with each other. int[] a = new int[] {1, 2, 3}; int[] b = new int[] {1, 2, 3}; int[] c = new int[] {1, 3, 2}; bool returnsTrue = a.SequenceEqual(b); bool returnsFalse = a.SequenceEqual(c);
The internal keyword is an access modifier for types and type members. Internal types or members are accessible only within files in the same assembly usage: public class BaseClass { // Only accessible within the same assembly internal static int x = 0; } The difference between dif...
pip doesn't current contain a flag to allow a user to update all outdated packages in one shot. However, this can be accomplished by piping commands together in a Linux environment: pip list --outdated --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U This command takes all pa...
pip doesn't current contain a flag to allow a user to update all outdated packages in one shot. However, this can be accomplished by piping commands together in a Windows environment: for /F "delims= " %i in ('pip list --outdated --local') do pip install -U %i This command takes all pa...
pip assists in creating requirements.txt files by providing the freeze option. pip freeze > requirements.txt This will save a list of all packages and their version installed on the system to a file named requirements.txt in the current folder.
pip assists in creating requirements.txt files by providing the freeze option. pip freeze --local > requirements.txt The --local parameter will only output a list of packages and versions that are installed locally to a virtualenv. Global packages will not be listed.
You can use all() to determine if all the values in an iterable evaluate to True nums = [1, 1, 0, 1] all(nums) # False chars = ['a', 'b', 'c', 'd'] all(chars) # True Likewise, any() determines if one or more values in an iterable evaluate to True nums = [1, 1, 0, 1] any(nums) # True val...
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <circle r="30" cx="100" cy="100" fill="#ff0000" stroke="#00ff00" /> <rect x="200" y="200" width="50&...
Sometimes it is useful to have multiple validations use one condition. It can be easily achieved using with_options. class User < ApplicationRecord with_options if: :is_admin? do |admin| admin.validates :password, length: { minimum: 10 } admin.validates :email, presence: true end...
The idea here is to move the computationally intensive jobs to C (using special macros), independent of Python, and have the C code release the GIL while it's working. #include "Python.h" ... PyObject *pyfunc(PyObject *self, PyObject *args) { ... Py_BEGIN_ALLOW_THREADS //...
git blame <file> will show the file with each line annotated with the commit that last modified it.
Because LINQ uses deferred execution, we can have a query object that doesn't actually contain the values, but will return the values when evaluated. We can thus dynamically build the query based on our control flow, and evaluate it once we are finished: IEnumerable<VehicleModel> BuildQuery(i...
If the help function is called in the console without any arguments, Python presents an interactive help console, where you can find out about Python modules, symbols, keywords and more. >>> help() Welcome to Python 3.4's help utility! If this is your first time using Python, you sho...
Install the SDK Download & unzip the SDK Make sure you are using the latest version of Xcode (7.0+) and targeting iOS 7.0 or highe Download SDK Add the SDKs to your app Drag the Parse.framework and Bolts.framework you downloaded into your Xcode project folder target. Make sure th...
Sometimes you need to keep a linear (non-branching) history of your code commits. If you are working on a branch for a while, this can be tricky if you have to do a regular git pull since that will record a merge with upstream. [alias] up = pull --rebase This will update with your upstream so...
A common use case for *args in a function definition is to delegate processing to either a wrapped or inherited function. A typical example might be in a class's __init__ method class A(object): def __init__(self, b, c): self.y = b self.z = c class B(A): def __init__(...
You can use a dictionary to assign values to the function's parameters; using parameters name as keys in the dictionary and the value of these arguments bound to each key: def test_func(arg1, arg2, arg3): # Usual function with three arguments print("arg1: %s" % arg1) print("a...

Page 62 of 269