Tutorial by Examples

from itertools import imap from future_builtins import map as fmap # Different name to highlight differences image = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] list(map(None, *image)) # Out: [(1, 4, 7), (2, 5, 8), (3, 6, 9)] list(fmap(None, *image)) # Out: [(1, 4, 7), (2, 5, 8),...
The system header TargetConditionals.h defines several macros which you can use from C and Objective-C to determine which platform you're using. #import <TargetConditionals.h> // imported automatically with Foundation - (void)doSomethingPlatformSpecific { #if TARGET_OS_IOS // code t...
Abbreviated from https://blogs.dropbox.com/developers/2013/07/using-oauth-2-0-with-the-core-api/: Step 1: Begin authorization Send the user to this web page, with your values filled in: https://www.dropbox.com/oauth2/authorize?client_id=<app key>&response_type=code&redirect_uri=<...
R has several built-in functions that can be used to print or display information, but print and cat are the most basic. As R is an interpreted language, you can try these out directly in the R console: print("Hello World") #[1] "Hello World" cat("Hello World\n") #H...
To have Git ignore certain files across all repositories you can create a global .gitignore with the following command in your terminal or command prompt: $ git config --global core.excludesfile <Path_To_Global_gitignore_file> Git will now use this in addition to each repository's own .git...
A submodule is always checked out at a specific commit SHA1 (the "gitlink", special entry in the index of the parent repo) But one can request to update that submodule to the latest commit of a branch of the submodule remote repo. Rather than going in each submodule, doing a git checkout...
If your latest commit is not published yet (not pushed to an upstream repository) then you can amend your commit. git commit --amend This will put the currently staged changes onto the previous commit. Note: This can also be used to edit an incorrect commit message. It will bring up the default...
The trap is reset for subshells, so the sleep will still act on the SIGINT signal sent by ^C (usually by quitting), but the parent process (i.e. the shell script) won't. #!/bin/sh # Run a command on signal 2 (SIGINT, which is what ^C sends) sigint() { echo "Killed subshell!" } ...
You can use the trap command to "trap" signals; this is the shell equivalent of the signal() or sigaction() call in C and most other programming languages to catch signals. One of the most common uses of trap is to clean up temporary files on both an expected and unexpected exit. Unfortu...
This is an example of dereferencing a NULL pointer, causing undefined behavior. int * pointer = NULL; int value = *pointer; /* Dereferencing happens here */ A NULL pointer is guaranteed by the C standard to compare unequal to any pointer to a valid object, and dereferencing it invokes undefined...
int i = 42; i = i++; /* Assignment changes variable, post-increment as well */ int a = i++ + i--; Code like this often leads to speculations about the "resulting value" of i. Rather than specifying an outcome, however, the C standards specify that evaluating such an expression produc...
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...
The ls command lists the contents of a specified directory, excluding dotfiles. If no directory is specified then, by default, the contents of the current directory are listed. Listed files are sorted alphabetically, by default, and aligned in columns if they don’t fit on one line. $ ls apt conf...
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...
alias -p will list all the current aliases.
The type of the literal Prelude> :t 1 1 :: Num a => a choosing a concrete type with annotations You can specify the type as long as the target type is Num with an annotation: Prelude> 1 :: Int 1 it :: Int Prelude> 1 :: Double 1.0 it :: Double Prelude> 1 :: Word 1 it :: ...
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...
Sets are unordered collections of unique values. Unique values must be of the same type. var colors = Set<String>() You can declare a set with values by using the array literal syntax. var favoriteColors: Set<String> = ["Red", "Blue", "Green", "Blu...
To access the event object, include an event parameter in the event listener callback function: var foo = document.getElementById("foo"); foo.addEventListener("click", onClick); function onClick(event) { // the `event` parameter is the event object // e.g. `event.type`...

Page 45 of 1336