Tutorial by Examples: o

When pasting text through a terminal emulator, the auto-indent feature may destroy the indentation of the pasted text. For example: function () { echo 'foo' echo 'bar' echo 'baz' } will be pasted as: function () { echo 'foo' echo 'bar' echo 'baz' ...
When static_cast is used to convert T D::* to T B::*, the member pointed to must belong to a class that is a base class or derived class of B. Otherwise the behavior is undefined. See Derived to base conversion for pointers to members
The following uses of pointer arithmetic cause undefined behavior: Addition or subtraction of an integer, if the result does not belong to the same array object as the pointer operand. (Here, the element one past the end is considered to still belong to the array.) int a[10]; int* p1 = &a...
For the built-in shift operator, the right operand must be nonnegative and strictly less than the bit width of the promoted left operand. Otherwise, the behavior is undefined. const int a = 42; const int b = a << -1; // UB const int c = a << 0; // ok const int d = a << 32; // ...
C++11 Example from the Standard, [dcl.attr.noreturn]: [[ noreturn ]] void f() { throw "error"; // OK } [[ noreturn ]] void q(int i) { // behavior is undefined if called with an argument <= 0 if (i > 0) throw "positive"; }
In this example, a destructor is explicitly invoked for an object that will later be automatically destroyed. struct S { ~S() { std::cout << "destroying S\n"; } }; int main() { S s; s.~S(); } // UB: s destroyed a second time here A similar issue occurs when a st...
Example from the Standard, [temp.inst]/17: template<class T> class X { X<T>* p; // OK X<T*> a; // implicit generation of X<T> requires // the implicit instantiation of X<T*> which requires // the implicit instantiation of X<T**&...
TestNG requires JDK 7 or higher to use. According to http://testng.org/doc/download.html in order to install testng you need to add testng dependency to your maven pom.xml or gradle build.gradle file Maven: <repositories> <repository> <id>jcenter</id> <name...
Creating a list of KeyValuePair: Dictionary<int, int> dictionary = new Dictionary<int, int>(); List<KeyValuePair<int, int>> list = new List<KeyValuePair<int, int>>(); list.AddRange(dictionary); Creating a list of keys: Dictionary<int, int> dictionary ...
To change a text file is not easy because its content must be moved around. For small files easiest method is to read its content in memory and then write back modified text. In this example we read all lines from a file and drop all blank lines then we write back to original path: File.WriteAllLi...
Text is saved encoded (see also Strings topic) then sometimes you may need to change its encoding, this example assumes (for simplicity) that file is not too big and it can be entirely read in memory: public static void ConvertEncoding(string path, Encoding from, Encoding to) { File.WriteAllT...
This example updates last write time of a huge number of files (using System.IO.Directory.EnumerateFiles instead of System.IO.Directory.GetFiles()). Optionally you can specify a search pattern (default is "*.*" and eventually search through a directory tree (not only the specified director...
This snippet is an helper function to enumerate all files older than a specified age, it's useful - for example - when you have to delete old log files or old cached data. static IEnumerable<string> EnumerateAllFilesOlderThan( TimeSpan maximumAge, ...
Having example type like this: public TestClass { public static string StaticPublicField = "StaticPublicFieldValue"; } We can retrieve value of StaticPublicField: var fieldExpr = Expression.Field(null, typeof(TestClass), "StaticPublicField"); var labmda = Expression....
Autostash is a very useful configuration option when using rebase for local changes. Oftentimes, you may need to bring in commits from the upstream branch, but are not ready to commit just yet. However, Git does not allow a rebase to start if the working directory is not clean. Autostash to the res...
echo off cls sqlcmd.exe -S "your server name" -U "sql user name" -P "sql password" -d "name of databse" -Q "here you may write your query/stored procedure" Batch files like these can be used to automate tasks, for example to make backups of ...
Basic Error Handling By default, Express will look for an 'error' view in the /views directory to render. Simply create the 'error' view and place it in the views directory to handle errors. Errors are written with the error message, status and stack trace, for example: views/error.pug html bo...
It's a good practice to run NodeJS apps controlled by process managers. Process manager helps to keep application alive forever, restart on failure, reload without downtime and simplifies administrating. Most powerful of them (like PM2) have a built-in load balancer. PM2 also enables you to manage ...
The canonical way of writing code inside documentation is with the {@code } construct. If you have multiline code wrap inside <pre></pre>. /** * The Class TestUtils. * <p> * This is an {@code inline("code example")}. * <p> * You should wrap it in pre tags...
Detailed instructions on getting aspectj set up or installed.

Page 573 of 1038