Tutorial by Examples

A method of a struct that change the value of the struct itself must be prefixed with the mutating keyword struct Counter { private var value = 0 mutating func next() { value += 1 } } When you can use mutating methods The mutating methods are only available on str...
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)
Generally, the syntax is: SELECT <column names> FROM <table name> WHERE <condition> For example: SELECT FirstName, Age FROM Users WHERE LastName = 'Smith' Conditions can be complex: SELECT FirstName, Age FROM Users WHERE LastName = 'Smith' AND (City = 'New York' OR C...
A header file may be included by other header files. A source file (compilation unit) that includes multiple headers may therefore, indirectly, include some headers more than once. If such a header file that is included more than once contains definitions, the compiler (after preprocessing) dete...
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...
Macros are categorized into two main groups: object-like macros and function-like macros. Macros are treated as a token substitution early in the compilation process. This means that large (or repeating) sections of code can be abstracted into a preprocessor macro. // This is an object-like macro ...
In PowerShell, there are many ways to achieve the same result. This can be illustrated nicely with the simple & familiar Hello World example: Using Write-Host: Write-Host "Hello World" Using Write-Output: Write-Output 'Hello world' It's worth noting that although Write-Outp...
./mongo localhost:27017/mydb myjsfile.js Explanation: This operation executes the myjsfile.js script in a mongo shell that connects to the mydb database on the mongod instance accessible via the localhost interface on port 27017. localhost:27017 is not mandatory as this is the default port mongo...
Struct fields can have tags associated with them. These tags can be read by the reflect package to get custom information specified about a field by the developer. struct Account { Username string `json:"username"` DisplayName string `json:"display_name"` F...
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...
It can also be installed by downloading the source code and placing it in a directory of your project. However there are many benefits to using composer. require '/path/to/lib/Twig/Autoloader.php'; Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem('/path/to/templates'); $opti...
Basic installation: You can download redux javascript file, using this link. Also you can install redux, using bower : bower install https://npmcdn.com/redux@latest/dist/redux.min.js Next, you need to include redux to your page: <html> <head> <script type="text/jav...
In order to filter out values from an array and obtain a new array containing all the values that satisfy the filter condition, you can use the array_filter function. Filtering non-empty values The simplest case of filtering is to remove all "empty" values: $my_array = [1,0,2,null,3,'',...
$sku = 'sku-goes-here'; $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
$id = 1; $product = Mage::getModel('catalog/product')->load($id); if($product->getId()){ //product was found }
$collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToFilter('sku', array('like' => 'UX%'));
$collection = Mage::getModel('catalog/product')->getCollection(); // Using operator $collection->addAttributeToFilter('status', array('eq' => 1)); // Without operator (automatically uses 'equal' operator $collection->addAttributeToFilter('status', 1);
If you are matching on an Option type: def f(x: Option[Int]) = x match { case Some(i) => doSomething(i) case None => doSomethingIfNone } This is functionally equivalent to using fold, or map/getOrElse: def g(x: Option[Int]) = x.fold(doSomethingIfNone)(doSomething) def h(x: ...

Page 133 of 1336