Tutorial by Examples

git diff HEAD^ HEAD This will show the changes between the previous commit and the current commit.
Freeing memory twice is undefined behavior, e.g. int * x = malloc(sizeof(int)); *x = 9; free(x); free(x); Quote from standard(7.20.3.2. The free function of C99 ): Otherwise, if the argument does not match a pointer earlier returned by the calloc, malloc, or realloc function, or if the sp...
Using an incorrect format specifier in the first argument to printf invokes undefined behavior. For example, the code below invokes undefined behavior: long z = 'B'; printf("%c\n", z); Here is another example printf("%f\n",0); Above line of code is undefined behavior. %...
These examples assume that you already know what Java 7's NIO is in general, and you are used to writing code using java.io.File. Use these examples as a means to quickly find more NIO-centric documentation for migrating. There is much more to Java 7's NIO such as memory-mapped files or opening a Z...
instance Monoid [a] where mempty = [] mappend = (++) Checking the Monoid laws for this instance: mempty `mappend` x = x <-> [] ++ xs = xs -- prepending an empty list is a no-op x `mappend` mempty = x <-> xs ++ [] = xs -- appending an empty list is a no-op x...
mconcat :: [a] -> a is another method of the Monoid typeclass: ghci> mconcat [Sum 1, Sum 2, Sum 3] Sum {getSum = 6} ghci> mconcat ["concat", "enate"] "concatenate" Its default definition is mconcat = foldr mappend mempty.
In the following examples, we'll be using the following samples: List<Product> Products = new List<Product>() { new Product() { ProductId = 1, Name = "Book nr 1", Price = 25 }, new Product() { ProductId = 2, Name = "Book nr 2&quot...
By default, user input history in IEx do not persist across different sessions. erlang-history adds history support to both the Erlang shell and IEx: git clone [email protected]:ferd/erlang-history.git cd erlang-history sudo make install You can now access your previous inputs using the up and d...
Numbers are monoidal in two ways: addition with 0 as the unit, and multiplication with 1 as the unit. Both are equally valid and useful in different circumstances. So rather than choose a preferred instance for numbers, there are two newtypes, Sum and Product to tag them for the different functional...
Wikipedia currently defines a pure function as follows: The function always evaluates the same result value given the same argument value(s). The function result value cannot depend on any hidden information or state that may change while program execution proceeds or between different executions...
Suppose we need to do the sum of each column in a dataset set.seed(20) df1 <- data.frame(ID = rep(c("A", "B", "C"), each = 3), V1 = rnorm(9), V2 = rnorm(9)) m1 <- as.matrix(df1[-1]) There are many ways to do this. Using base R, the best option would be col...
A common question is "I have a value of IO a, but I want to do something to that a value: how do I get access to it?" How can one operate on data that comes from the outside world (for example, incrementing a number typed by the user)? The point is that if you use a pure function on data ...
Suppose you have this type: data Person = Person { name :: String, age:: Int } deriving (Show, Eq) and two values: alex = Person { name = "Alex", age = 21 } jenny = Person { name = "Jenny", age = 36 } a new value of type Person can be created by copying from alex, specif...
import pandas as pd # Save dataframe to pickled pandas object df.to_pickle(file_name) # where to save it usually as a .plk # Load dataframe from pickled pandas object df= pd.read_pickle(file_name)

for

The for statement is used when you know how many times you want to execute a statement or a block of statements. The initializer is used to set the start value for the counter of the number of loop iterations. A variable may be declared here for this purpose and it is traditional to name it $i....
The foreach statement is used to loop through arrays. For each iteration the value of the current array element is assigned to $value variable and the array pointer is moved by one and in the next iteration next element will be processed. The following example displays the items in the array a...
The break keyword immediately terminates the current loop. Similar to the continue statement, a break halts execution of a loop. Unlike a continue statement, however, break causes the immediate termination of the loop and does not execute the conditional statement again. $i = 5; while(true) {...
The do...while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true. The following example will increment the value of $i at least once, and it will continue incrementing the variable $i as long as it has a value of less than 25; $i...
The continue keyword halts the current iteration of a loop but does not terminate the loop. Just like the break statement the continue statement is situated inside the loop body. When executed, the continue statement causes execution to immediately jump to the loop conditional. In the followin...
The while statement will execute a block of code if and as long as a test expression is true. If the test expression is true then the code block will be executed. After the code has executed the test expression will again be evaluated and the loop will continue until the test expression is foun...

Page 272 of 1336