Tutorial by Examples: al

The GlobalFetch interface exposes the fetch function, which can be used to request resources. fetch('/path/to/resource.json') .then(response => { if (!response.ok()) { throw new Error("Request failed!"); } return response.json(...
man <command> This will show the manual page for the specified command. For example, man ping will show: PING(8) BSD System Manager's Manual PING(8) NAME ping -- send ICMP ECHO_REQUEST packets to network hosts SYNOPSIS ping [-AaCDdfno...
int a; printf("%d", a); The variable a is an int with automatic storage duration. The example code above is trying to print the value of an uninitialized variable (a was never initialized). Automatic variables which are not initialized have indeterminate values; accessing these can le...
Consider the below list comprehension: >>> def f(x): ... import time ... time.sleep(.1) # Simulate expensive function ... return x**2 >>> [f(x) for x in range(1000) if f(x) > 10] [16, 25, 36, ...] This results in two calls to f(x) for 1,000 values of...
Browse to File > New > Project to bring you up the New Project dialog. Navigate to Visual C# > iOS > iPhone and select Single View App: Give your app a Name and press OK to create your project. Select the Mac Agent icon from the toolbar, as illustrated below: Select the Mac tha...
Signal numbers can be synchronous (like SIGSEGV – segmentation fault) when they are triggered by a malfunctioning of the program itself or asynchronous (like SIGINT - interactive attention) when they are initiated from outside the program, e.g by a keypress as Cntrl-C. The signal() function is part...
To conditionally include a block of code, the preprocessor has several directives (e.g #if, #ifdef, #else, #endif, etc). /* Defines a conditional `printf` macro, which only prints if `DEBUG` * has been defined */ #ifdef DEBUG #define DLOG(x) (printf(x)) #else #define DLOG(x) #endif Norm...
Swift's built-in numeric types are: Word-sized (architecture-dependent) signed Int and unsigned UInt. Fixed-size signed integers Int8, Int16, Int32, Int64, and unsigned integers UInt8, UInt16, UInt32, UInt64. Floating-point types Float32/Float, Float64/Double, and Float80 (x86-only). Literal...
Factorials can be computed at compile-time using template metaprogramming techniques. #include <iostream> template<unsigned int n> struct factorial { enum { value = n * factorial<n - 1>::value }; }; template<> struct factorial<0> { ...
When working with dictionaries, it's often necessary to access all the keys and values in the dictionary, either in a for loop, a list comprehension, or just as a plain list. Given a dictionary like: mydict = { 'a': '1', 'b': '2' } You can get a list of keys using the keys() method: ...
Conditional comments can be used to customize code for different versions of Microsoft Internet Explorer. For example, different HTML classes, script tags, or stylesheets can be provided. Conditional comments are supported in Internet Explorer versions 5 through 9. Older and newer Internet Explorer ...
An if statement checks whether a Bool condition is true: let num = 10 if num == 10 { // Code inside this block only executes if the condition was true. print("num is 10") } let condition = num == 10 // condition's type is Bool if condition { print("num is 10&...
Optionals must be unwrapped before they can be used in most expressions. if let is an optional binding, which succeeds if the optional value was not nil: let num: Int? = 10 // or: let num: Int? = nil if let unwrappedNum = num { // num has type Int?; unwrappedNum has type Int print(&quo...
var favoriteColors: Set = ["Red", "Blue", "Green"] //favoriteColors = {"Blue", "Green", "Red"} You can use the insert(_:) method to add a new item into a set. favoriteColors.insert("Orange") //favoriteColors = {"Red&q...
from collections import Counter c = Counter(["a", "b", "c", "d", "a", "b", "a", "c", "d"]) c # Out: Counter({'a': 3, 'b': 2, 'c': 2, 'd': 2}) c["a"] # Out: 3 c[7] # not in the list (7 oc...
Counting the keys of a Mapping isn't possible with collections.Counter but we can count the values: from collections import Counter adict = {'a': 5, 'b': 3, 'c': 5, 'd': 2, 'e':2, 'q': 5} Counter(adict.values()) # Out: Counter({2: 2, 3: 1, 5: 3}) The most common elements are avaiable by the m...
var favoriteColors: Set = ["Red", "Blue", "Green"] //favoriteColors = {"Blue", "Green", "Red"} You can use the contains(_:) method to check whether a set contains a value. It will return true if the set contains that value. if favorite...
Final classes When used in a class declaration, the final modifier prevents other classes from being declared that extend the class. A final class is a "leaf" class in the inheritance class hierarchy. // This declares a final class final class MyFinalClass { /* some code */ } ...
Introduction Package is a term used by npm to denote tools that developers can use for their projects. This includes everything from libraries and frameworks such as jQuery and AngularJS to task runners such as Gulp.js. The packages will come in a folder typically called node_modules, which will a...
Sometimes you may encounter members that have really long member names, such as thisIsWayTooLongOfAName(). In this case, you can import the member and give it a shorter name to use in your current module: import {thisIsWayTooLongOfAName as shortName} from 'module' shortName() You can import m...

Page 11 of 269