Tutorial by Examples: er

You can use the ** keyword argument unpacking operator to deliver the key-value pairs in a dictionary into a function's arguments. A simplified example from the official documentation: >>> >>> def parrot(voltage, state, action): ... print("This parrot wouldn't", ac...
Consider the following dictionaries: >>> fish = {'name': "Nemo", 'hands': "fins", 'special': "gills"} >>> dog = {'name': "Clifford", 'hands': "paws", 'color': "red"} Python 3.5+ >>> fishdog = {**fish, **dog}...
Create an interface decorated with a ServiceContract attribute and member functions decorated with the OperationContract attribute. namespace Service { [ServiceContract] interface IExample { [OperationContract] string Echo(string s); } } Create a concrete...
$(window).load() was deprecated in jQuery version 1.8 (and completely removed from jQuery 3.0) and as such should not be used anymore. The reasons for the deprecation are noted on the jQuery page about this event Caveats of the load event when used with images A common challenge developers attem...
There are two kinds of boolean operators in Elixir: boolean operators (they expect either true or false as their first argument) x or y # true if x is true, otherwise y x and y # false if x is false, otherwise y not x # false if x is true, otherwise true All of booleans...
Equality: value equality x == y (1 == 1.0 # true) value inequality x == y (1 != 1.0 # false) strict equality x === y (1 === 1.0 # false) strict inequality x === y (1 !== 1.0 # true) Comparison: x > y x >= y x < y x <= y If types are compatible, comparison uses natural o...
Pretty much every header file should follow the include guard idiom: my-header-file.h #ifndef MY_HEADER_FILE_H #define MY_HEADER_FILE_H // Code body for header file #endif This ensures that when you #include "my-header-file.h" in multiple places, you don't get duplicate declara...
Attach an Event Handler Since version 1.7 jQuery has the event API .on(). This way any standard javascript event or custom event can be bound on the currently selected jQuery element. There are shortcuts such as .click(), but .on() gives you more options. HTML <button id="foo">b...
You can create a UIColor from a hexadecimal number or string, e.g. 0xff00cc, "#FFFFFF" Swift Int Value extension UIColor { convenience init(hex: Int, alpha: CGFloat = 1.0) { let r = CGFloat((hex >> 16) & 0xff) / 255 let g = CGFloat((hex >> 08) &amp...
When you need to iterate over the list of jQuery elements. Consider this DOM structure: <div class="container"> <div class="red one">RED 1 Info</div> <div class="red two">RED 2 Info</div> <div class="red three"...
For the character entity character(len=5), parameter :: greeting = "Hello" a substring may be referenced with the syntax greeting(2:4) ! "ell" To access a single letter it isn't sufficient to write greeting(1) ! This isn't the letter "H" but greeting(1:...
Filters allows you to apply a function to a variable. This function may take 0 or 1 argument. Here is the syntax: {{ variable|filter_name }} {{ variable|filter_name:argument }} Filters can be chained so this is perfectly valid: {{ variable|filter_name:argument|another_filter }} If transla...
Validates value as float, and converts to float on success. var_dump(filter_var(1, FILTER_VALIDATE_FLOAT)); var_dump(filter_var(1.0, FILTER_VALIDATE_FLOAT)); var_dump(filter_var(1.0000, FILTER_VALIDATE_FLOAT)); var_dump(filter_var(1.00001, FILTER_VALIDATE_FLOAT)); var_dump(filter_var('1', FILTE...
Remove all characters except digits, plus and minus sign. var_dump(filter_var(1, FILTER_SANITIZE_NUMBER_INT)); var_dump(filter_var(-1, FILTER_SANITIZE_NUMBER_INT)); var_dump(filter_var(+1, FILTER_SANITIZE_NUMBER_INT)); var_dump(filter_var(1.00, FILTER_SANITIZE_NUMBER_INT)); var_dump(filter_var(...
After launching Visual Studio 2015, go to File → New → Project. In the New Project dialog box, browse in the templates tree to Visual C# → Windows → Universal and select Blank App (Universal Windows). Next, we need to fill the form to describe the Application: Name: this is the name of the appli...
Spacemacs is a distribution of emacs that comes with a lot of packages preconfigured and easily installed. Also, it is very friendly for those who are familiar with vim style of editing. Spacemacs provides a CIDER-based Clojure layer. To install and configure it for use with Clojure, first install ...
Interfaces should be named with nouns or noun phrases, or adjectives that describe behaviour. For example IComponent uses a descriptive noun, ICustomAttributeProvider uses a noun phrase and IPersistable uses an adjective. Interface names should be prefixed with the letter I, to indicate that the ty...
An iterable is an object that can return an iterator. Any object with state that has an __iter__ method and returns an iterator is an iterable. It may also be an object without state that implements a __getitem__ method. - The method can take indices (starting from zero) and raise an IndexError whe...
There may be situations where you have setup a pool of MySQL connections, but you have a number of queries you would like to run in sequence: SELECT 1; SELECT 2; You could just run then using pool.query as seen elsewhere, however if you only have one free connection in the pool you must wait un...
You can attach the query executed to your err object when an error occurs: var q = mysql.query('SELECT `name` FROM `pokedex` WHERE `id` = ?', [ 25 ], function (err, result) { if (err) { // Table 'test.pokedex' doesn't exist err.query = q.sql; // SELECT `name` FROM `pokedex` WHERE `id` ...

Page 93 of 417