Tutorial by Examples: correct

An iterator method is not executed until the return value is enumerated. It's therefore advantageous to assert preconditions outside of the iterator. public static IEnumerable<int> Count(int start, int count) { // The exception will throw when the method is called, not when the result i...
The web.config system.web.httpRuntime must target 4.5 to ensure the thread will renter the request context before resuming your async method. <httpRuntime targetFramework="4.5" /> Async and await have undefined behavior on ASP.NET prior to 4.5. Async / await will resume on an arb...
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. %...
Most times when people have to reverse a string, they do it more or less like this: char[] a = s.ToCharArray(); System.Array.Reverse(a); string r = new string(a); However, what these people don't realize is that this is actually wrong. And I don't mean because of the missing NULL check. It ...
CSS and JS files should be reside under 'static' directory in the root directory of module (the rest of subdirectory tree under 'static' is an optional convention): static/src/css/your_file.css static/src/js/your_file.js Then add links to these files unsing one of the 3 ways listed in the fol...
The following might have undefined behavior due to incorrect pointer alignment: char *memory_block = calloc(sizeof(uint32_t) + 1, 1); uint32_t *intptr = (uint32_t*)(memory_block + 1); /* possible undefined behavior */ uint32_t mvalue = *intptr; The undefined behavior happens as the pointer...
This is a huge topic, but it is also the most important "performance" issue. The main lesson for a novice is to learn of "composite" indexes. Here's a quick example: INDEX(last_name, first_name) is excellent for these: WHERE last_name = '...' WHERE first_name = '...' AND ...
innodb_buffer_pool_size should be about 70% of available RAM.
An object can only be deallocated by delete if it was allocated by new and is not an array. If the argument to delete was not returned by new or is an array, the behavior is undefined. An object can only be deallocated by delete[] if it was allocated by new and is an array. If the argument to delet...
$productFound = ($product->getId() !== null)
This is a relatively common mistake: You created an rect element, in a bar chart for instance, and you want to add a text label (let's say, the value of that bar). So, using the same variable that you used to append the rect and define its x and y position, you append your text element. Very logic, ...
git config --global help.autocorrect 17 This enables autocorrect in git and will forgive you for your minor mistakes (e.g. git stats instead of git status). The parameter you supply to help.autocorrect determines how long the system should wait, in tenths of a second, before automatically applyin...
The methods object.wait(), object.notify() and object.notifyAll() are meant to be used in a very specific way. (see http://stackoverflow.com/documentation/java/5409/wait-notify#t=20160811161648303307 ) The "Lost Notification" problem One common beginner mistake is to unconditionally cal...
One of the primary uses for this cv-qualifiers is const correctness. This is the practice of guaranteeing that only accesses that need to modify an object are able to modify the object, and that any (member or non-member) function that doesn't need to modify an object doesn't have write access to t...
By default, Import-CSV imports all values as strings, so to get DateTime- and integer-objects, we need to cast or parse them. Using Foreach-Object: > $listOfRows = Import-Csv .\example.csv > $listOfRows | ForEach-Object { #Cast properties $_.DateTime = [datetime]$_.DateTime $...
private static final String TAG = "IntentBitmapFetch"; private static final String COLON_SEPARATOR = ":"; private static final String IMAGE = "image"; @Nullable public Bitmap getBitmap(@NonNull Uri bitmapUri, int maxDimen) { InputStream is = context.getConten...
public class HomepageTests { private IWebDriver _driver; [SetUp] public void LoadDriver() { _driver = new ChromeDriver(); } [Test] public void Valid_Home_Page_Title() { _driver.Navigate().GoToUrl("Your homeoage url / loc...
This example shows how to take image and display it correctly on the Android device. Firstly we have to create sample application with one button and one imageview. Once user clicks on the button camera is launched and after user selects picture it will be displayed with the proper orientation on ...
In a const-correct class, all member functions which don't change logical state have this cv-qualified as const, indicating that they don't modify the object (apart from any mutable fields, which can freely be modified even in const instances); if a const cv-qualified function returns a reference, t...
In a const-correct function, all passed-by-reference parameters are marked as const unless the function directly or indirectly modifies them, preventing the programmer from inadvertently changing something they didn't mean to change. This allows the function to take both const and non-cv-qualified ...

Page 1 of 2