Tutorial by Examples: and

var object = { key1: 10, key2: 3, key3: 40, key4: 20 }; var array = []; for(var people in object) { array.push([people, object[people]]); } Now array is [ ["key1", 10], ["key2", 3], ["key3", 40], ["key4", 20] ] ...
struct Square { private(set) var area = 0 var side: Int = 0 { didSet { area = side*side } } } public struct Square { public private(set) var area = 0 public var side: Int = 0 { didSet { area = side*side } ...
Python 2.x2.6 The format() method can be used to change the alignment of the string. You have to do it with a format expression of the form :[fill_char][align_operator][width] where align_operator is one of: < forces the field to be left-aligned within width. > forces the field to be righ...
#include <stdio.h> /* for perror(), fopen(), fputs() and fclose() */ #include <stdlib.h> /* for the EXIT_* macros */ int main(int argc, char **argv) { int e = EXIT_SUCCESS; /* Get path from argument to main else default to output.txt */ char *path = (argc > 1...
c := exec.Command(name, arg...) b := &bytes.Buffer{} c.Stdout = b c.Stdin = stdin if err := c.Start(); err != nil { return nil, err } timedOut := false intTimer := time.AfterFunc(timeout, func() { log.Printf("Process taking too long. Interrupting: %s %s", name, strings...
// Execute a command a capture standard out. exec.Command creates the command // and then the chained Output method gets standard out. Use CombinedOutput() // if you want both standard out and standerr output out, err := exec.Command("echo", "foo").Output() if err != nil { ...
cmd := exec.Command("sleep", "5") // Does not wait for command to complete before returning err := cmd.Start() if err != nil { log.Fatal(err) } // Wait for cmd to Return err = cmd.Wait() log.Printf("Command finished with error: %v", err)
In a nutshell, conditional pre-processing logic is about making code-logic available or unavailable for compilation using macro definitions. Three prominent use-cases are: different app profiles (e.g. debug, release, testing, optimised) that can be candidates of the same app (e.g. with extra log...
To make all the characters in a String uppercase or lowercase: 2.2 let text = "AaBbCc" let uppercase = text.uppercaseString // "AABBCC" let lowercase = text.lowercaseString // "aabbcc" 3.0 let text = "AaBbCc" let uppercase = text.uppercased() // &qu...
Slices have both length and capacity. The length of a slice is the number of elements currently in the slice, while the capacity is the number of elements the slice can hold before needing to be reallocated. When creating a slice using the built-in make() function, you can specify its length, and ...
public enum DayOfWeek { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday } // Enum to string string thursday = DayOfWeek.Thursday.ToString(); // "Thursday" string seventhDay = Enum.GetName(typeof(DayOfWeek), 6); // "Satur...
You can create a new hash with the keys or values modified, indeed you can also add or delete keys, using inject (AKA, reduce). For example to produce a hash with stringified keys and upper case values: fruit = { name: 'apple', color: 'green', shape: 'round' } # => {:name=>"apple",...
The background property can be used to set one or more background related properties: ValueDescriptionCSS Ver.background-imageBackground image to use1+background-colorBackground color to apply1+background-positionBackground image's position1+background-sizeBackground image's size3+background-repeat...
Nginx is a Web server used to serve HTTP requests over the Internet. Nginx is available on Linux, Windows and other OSes as direct download, and can also be built from source. For detailed instructions see Nginx official reference. ubuntu/debian nginx stable version is available in official repo,...
// The Option type can either contain Some value or None. fn find(value: i32, slice: &[i32]) -> Option<usize> { for (index, &element) in slice.iter().enumerate() { if element == value { // Return a value (wrapped in Some). return Some(index);...
Whenever you attempt to retrieve a certain field from a class like so: $animal = new Animal(); $height = $animal->height; PHP invokes the magic method __get($name), with $name equal to "height" in this case. Writing to a class field like so: $animal->height = 10; Will invoke...
A binary is a sequence of unsigned 8-bit bytes. 1> <<1,2,3,255>>. <<1,2,3,255>> 2> <<256,257,258>>. <<0,1,2>> 3> <<"hello","world">>. <<"helloworld">> A bitstring is a generalized ...
.rds and .Rdata (also known as .rda) files can be used to store R objects in a format native to R. There are multiple advantages of saving this way when contrasted with non-native storage approaches, e.g. write.table: It is faster to restore the data to R It keeps R specific information encoded ...
CSS div { height: 100px; width: 100px; border: 1px solid; transition-property: height, width; transition-duration: 1s, 500ms; transition-timing-function: linear; transition-delay: 0s, 1s; } div:hover { height: 200px; width: 200px; } HTML <div></div> ...
The filter or map functions should often be replaced by list comprehensions. Guido Van Rossum describes this well in an open letter in 2005: filter(P, S) is almost always written clearer as [x for x in S if P(x)], and this has the huge advantage that the most common usages involve predicates tha...

Page 16 of 153