Tutorial by Examples: al

It was common practice to use NSRunLoop to show modal UIAlertView to block code execution until user input is processed in iOS; until Apple released the iOS7, it broke few existing apps. Fortunately, there is a better way of implementing it with C#’s async/await. Here’s the new code taking advantag...
User input Imagine you want a user to enter a number via input. You want to ensure that the input is a number. You can use try/except for this: Python 3.x3.0 while True: try: nb = int(input('Enter a number: ')) break except ValueError: print('This is not a num...
Functions have two built-in methods that allow the programmer to supply arguments and the this variable differently: call and apply. This is useful, because functions that operate on one object (the object that they are a property of) can be repurposed to operate on another, compatible object. Addi...
If you have a variable declared before, you can assign some value to it: For example: int a; // declared previously a = 2; Or change the value: int a = 3; // initalized previously a = 2;
DECLARE @Var1 INT = 5, @Var2 NVARCHAR(50) = N'Hello World', @Var3 DATETIME = GETDATE()
(let [x true y true z true] (match [x y z] [_ false true] 1 [false true _ ] 2 [_ _ false] 3 [_ _ true] 4)) ;=> 4
(match [['asymbol]] [['asymbol]] :success) ;=> :success
Some API calls return a single failure/success flag, without any additional information (e.g. GetObject): if ( GetObjectW( obj, 0, NULL ) == 0 ) { // Failure: no additional information available. }
In addition to a failure/success return value, some API calls also set the last error on failure (e.g. CreateWindow). The documentation usually contains the following standard wording for this case: If the function succeeds, the return value is <API-specific success value>. If the function...
Some API calls can succeed or fail in more than one way. The APIs commonly return additional information for both successful invocations as well as errors (e.g. CreateMutex). if ( CreateMutexW( NULL, TRUE, L"Global\\MyNamedMutex" ) == NULL ) { // Failure: get additional information. ...
HRESULTs are numeric 32-bit values, where bits or bit ranges encode well-defined information. The MSB is a failure/success flag, with the remaining bits storing additional information. Failure or success can be determined using the FAILED or SUCCEEDED macros. HRESULTs are commonly used with COM, but...
When implementing SFINAE using std::enable_if, it is often useful to have access to helper templates that determines if a given type T matches a set of criteria. To help us with that, the standard already provides two types analog to true and false which are std::true_type and std::false_type. The...
Add the following code (known as the "JavaScript tracking snippet") to your site's templates. The code should be added before the closing tag, and the string 'UA-XXXXX-Y' should be replaced with the property ID (also called the "tracking ID") of the Google Analytics property yo...
CSS body { counter-reset: item-counter; } .item { counter-increment: item-counter; } .item:before { content: counter(item-counter, upper-roman) ". "; /* by specifying the upper-roman as style the output would be in roman numbers */ } HTML <div class='item'>Item...
A HTTP 500 Internal Server Error is a general message meaning that the server encountered something unexpected. Applications (or the overarching web server) should use a 500 when there's an error processing the request - i.e. an exception is thrown, or a condition of the resource prevents the proces...
Start with iter() built-in to get iterator over iterable and use next() to get elements one by one until StopIteration is raised signifying the end: s = {1, 2} # or list or generator or even iterator i = iter(s) # get iterator a = next(i) # a = 1 b = next(i) # b = 2 c = next(i) # raises S...
Setting up settings.py from django.utils.translation import ugettext_lazy as _ USE_I18N = True # Enable Internationalization LANGUAGE_CODE = 'en' # Language in which original texts are written LANGUAGES = [ # Available languages ('en', _("English")), ('de', _("Germ...
We can do two things to improve the simple and sub-optimal disjoint-set subalgorithms: Path compression heuristic: findSet does not need to ever handle a tree with height bigger than 2. If it ends up iterating such a tree, it can link the lower nodes directly to the root, optimizing future trav...
JSON stands for "JavaScript Object Notation", but it's not JavaScript. Think of it as just a data serialization format that happens to be directly usable as a JavaScript literal. However, it is not advisable to directly run (i.e. through eval()) JSON that is fetched from an external source...
' This method is useful for iterating Enum values ' Enum Animal Dog = 1 Cat = 2 Frog = 4 End Enum Dim Animals = [Enum].GetValues(GetType(Animal)) For Each animal in Animals Console.WriteLine(animal) Next Prints: 1 2 4

Page 65 of 269