Tutorial by Examples: at

int foo(void) { /* do stuff */ /* no return here */ } int main(void) { /* Trying to use the (not) returned value causes UB */ int value = foo(); return 0; } When a function is declared to return a value then it has to do so on every possible code path through it. Undefined beh...
alias word='command' Invoking word will run command. Any arguments supplied to the alias are simply appended to the target of the alias: alias myAlias='some command --with --options' myAlias foo bar baz The shell will then execute: some command --with --options foo bar baz To include mul...
The type of the literal Prelude> :t 1.0 1.0 :: Fractional a => a Choosing a concrete type with annotations You can specify the type with a type annotation. The only requirement is that the type must have a Fractional instance. Prelude> 1.0 :: Double 1.0 it :: Double Prelude> 1....
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char **argv) { /* Exit if no second argument is found. */ if (argc != 2) { puts("Argument missing."); return EXIT_FAILURE; } size_t len = str...
A simple function that does not accept any parameters and does not return any values: func SayHello() { fmt.Println("Hello!") }
A basic struct is declared as follows: type User struct { FirstName, LastName string Email string Age int } Each value is called a field. Fields are usually written one per line, with the field's name preceeding its type. Consecutive fields of the sa...
Struct fields whose names begin with an uppercase letter are exported. All other names are unexported. type Account struct { UserID int // exported accessToken string // unexported } Unexported fields can only be accessed by code within the same package. As such, if you are ev...
Any function can be invoked as a goroutine by prefixing its invocation with the keyword go: func DoMultiply(x,y int) { // Simulate some hard work time.Sleep(time.Second * 1) fmt.Printf("Result: %d\n", x * y) } go DoMultiply(1,2) // first execution, non-blocking go DoMu...
PorterDuff.Mode is used to create a PorterDuffColorFilter. A color filter modifies the color of each pixel of a visual resource. ColorFilter filter = new PorterDuffColorFilter(Color.BLUE, PorterDuff.Mode.SRC_IN); The above filter will tint the non-transparent pixels to blue color. The color fil...
An Xfermode (think "transfer" mode) works as a transfer step in drawing pipeline. When an Xfermode is applied to a Paint, the pixels drawn with the paint are combined with underlying pixels (already drawn) as per the mode: paint.setColor(Color.BLUE); paint.setXfermode(new PorterDuffXferm...
In info.plist set View controller-based status bar appearance to YES In view controllers not contained by UINavigationController implement this method. In Objective-C: - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } In Swift: override func pre...
Warning: be sure you have at least 15 GB of free disk space. Compilation in Ubuntu >=13.04 Option A) Use Git Use git if you want to stay in sync with the latest Ubuntu kernel source. Detailed instructions can be found in the Kernel Git Guide. The git repository does not include necessary ...
Python's str type also features a number of methods that can be used to evaluate the contents of a string. These are str.isalpha, str.isdigit, str.isalnum, str.isspace. Capitalization can be tested with str.isupper, str.islower and str.istitle. str.isalpha str.isalpha takes no arguments and retu...
try { StyledDocument doc = new DefaultStyledDocument(); doc.insertString(0, "This is the beginning text", null); doc.insertString(doc.getLength(), "\nInserting new line at end of doc", null); MutableAttributeSet attrs = new SimpleAttributeSet(); StyleCons...
Static methods and properties are defined on the class/constructor itself, not on instance objects. These are specified in a class definition by using the static keyword. class MyClass { static myStaticMethod() { return 'Hello'; } static get myStaticProperty() { r...
6 Fetch request promises initially return Response objects. These will provide response header information, but they don't directly include the response body, which may not have even loaded yet. Methods on the Response object such as .json() can be used to wait for the response body to load, then p...
An array in go is an ordered collection of same types elements. The basic notation to represent arrays is to use [] with the variable name. Creating a new array looks like var array = [size]Type, replacing size by a number (for example 42 to specify it will be a list of 42 elements), and replacing...
The function rand() can be used to generate a pseudo-random integer value between 0 and RAND_MAX (0 and RAND_MAX included). srand(int) is used to seed the pseudo-random number generator. Each time rand() is seeded wih the same seed, it must produce the same sequence of values. It should only be see...
Here's a standalone random number generator that doesn't rely on rand() or similar library functions. Why would you want such a thing? Maybe you don't trust your platform's builtin random number generator, or maybe you want a reproducible source of randomness independent of any particular library ...
Truncate > Create specified file if it does not exist. Truncate (remove file's content) Write to file $ echo "first line" > /tmp/lines $ echo "second line" > /tmp/lines $ cat /tmp/lines second line Append >> Create specified file if it does not e...

Page 12 of 442