Tutorial by Examples: ch

Some JavaScript engines (for example, the current version of Node.js and older versions of Chrome before Ignition+turbofan) don't run the optimizer on functions that contain a try/catch block. If you need to handle exceptions in performance-critical code, it can be faster in some cases to keep the ...
If you want to check that a string contains only a certain set of characters, in this case a-z, A-Z and 0-9, you can do so like this, import re def is_allowed(string): characherRegex = re.compile(r'[^a-zA-Z0-9.]') string = characherRegex.search(string) return not bool(string) ...
Grand Central Dispatch works on the concept of "Dispatch Queues". A dispatch queue executes tasks you designate in the order which they are passed. There are three types of dispatch queues: Serial Dispatch Queues (aka private dispatch queues) execute one task at a time, in order. They a...
3.0 To run tasks on a dispatch queue, use the sync, async, and after methods. To dispatch a task to a queue asynchronously: let queue = DispatchQueue(label: "myQueueName") queue.async { //do something DispatchQueue.main.async { //this will be called in main t...
Letters 3.0 let letters = CharacterSet.letters let phrase = "Test case" let range = phrase.rangeOfCharacter(from: letters) // range will be nil if no letters is found if let test = range { print("letters found") } else { print("letters not found") }...
A common question is how to juxtapose (combine) physically separate geographical regions on the same map, such as in the case of a choropleth describing all 50 American states (The mainland with Alaska and Hawaii juxtaposed). Creating an attractive 50 state map is simple when leveraging Google Maps...
const auto input = "Some people, when confronted with a problem, think \"I know, I'll use regular expressions.\""s; smatch sm; cout << input << endl; // If input ends in a quotation that contains a word that begins with "reg" and another word begining...
Simple check To check if constant is defined use the defined function. Note that this function doesn't care about constant's value, it only cares if the constant exists or not. Even if the value of the constant is null or false the function will still return true. <?php define("GOOD&quo...
IsNotNull This is a very simple and popular method to use to check if an item is not null. It simply checks the object that is passed in to see if it is null. Assert.IsNotNull(database, type, "Name: {0}", item); IsNotNullOrEmpty This is the same as IsNotNull above, but works on strin...
ArgumentCondition This method checks to see if the argument specified is true. It also takes in the name of the argument that is logged if the condition fails. Assert.ArgumentCondition(pageIndex >= 0, "pageIndex", "Value must be greater than or equal to zero."); ArgumentN...
Use try...except: to catch exceptions. You should specify as precise an exception as you can: try: x = 5 / 0 except ZeroDivisionError as e: # `e` is the exception object print("Got a divide by zero! The exception was:", e) # handle exceptional case x = 0 final...
In the process of handling an exception, you may want to raise another exception. For example, if you get an IOError while reading from a file, you may want to raise an application-specific error to present to the users of your library, instead. Python 3.x3.0 You can chain exceptions to show how t...
Exception handling occurs based on an exception hierarchy, determined by the inheritance structure of the exception classes. For example, IOError and OSError are both subclasses of EnvironmentError. Code that catches an IOError will not catch an OSError. However, code that catches an EnvironmentErr...
Definition of Decorator as per Wikiepdia: The Decorator pattern can be used to extend (decorate) the functionality of a certain object statically, or in some cases at run-time, independently of other instances of the same class, provided some groundwork is done at design time. Decorator attach add...
'Attaching to a container' is the act of starting a terminal session within the context that the container (and any programs therein) is running. This is primarily used for debugging purposes, but may also be needed if specific data needs to be passed to programs running within the container. The a...
A type that conforms to the SequenceType protocol can iterate through it's elements within a closure: collection.forEach { print($0) } The same could also be done with a named parameter: collection.forEach { item in print(item) } *Note: Control flow statements (such as break or continu...
If you want to catch all routes, then you could use a regular expression as shown: Route::any('{catchall}', 'CatchAllController@handle')->where('catchall', '.*'); Important: If you have other routes and you don't want for the catch-all to interfere, you should put it in the end. For example: ...
By default, all types in TypeScript allow null: function getId(x: Element) { return x.id; } getId(null); // TypeScript does not complain, but this is a runtime error. TypeScript 2.0 adds support for strict null checks. If you set --strictNullChecks when running tsc (or set this flag in you...
if ([object respondsToSelector:@selector(someOptionalMethodInProtocol:)]) { [object someOptionalMethodInProtocol:argument]; }
Returns a Boolean indicating if the class conform the protocol: [MyClass conformsToProtocol:@protocol(MyProtocol)];

Page 16 of 109