Tutorial by Examples: c

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...
Two ways to replace: by regex or by exact match. Note: the original String object will be unchanged, the return value holds the changed String. Exact match Replace single character with another single character: String replace(char oldChar, char newChar) Returns a new string resulting from...
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...
An explicit intent is used for starting an activity or service within the same application package. In this case the name of the intended class is explicitly mentioned: Intent intent = new Intent(this, MyComponent.class); startActivity(intent); However, an implicit intent is sent across the sys...
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...
Router enables navigation from one view to another based on user interactions with the application. Following are the steps in implementing basic routing in Angular 2 - Basic precaution: Ensure you have the tag <base href='/'> as the first child under your head tag in your index.htm...
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...
If you want your script to wait until a certain resource was loaded, such as an image or a PDF you can use .load(), which is a shortcut for shortcut for .on( "load", handler). HTML <img src="image.jpeg" alt="image" id="image"> jQuery $( "#imag...
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...
To select siblings of an item you can use the .siblings() method. A typical example where you want to modify the siblings of an item is in a menu: <ul class="menu"> <li class="selected">Home</li> <li>Blog</li> <li>About</li&...
Returns the first element that matches the selector starting at the element and traversing up the DOM tree. HTML <div id="abc" class="row"> <div id="xyz" class="row"> </div> <p id="origin"> Hello &...
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:...
The complex entity complex, parameter :: x = (1., 4.) has real part 1. and complex part 4.. We can access these individual components as real(x) ! The real component aimag(x) ! The complex component x%re ! The real component y%im ! The complex component The x%.. form is new to F...
There are three types of comment: # This comment continues to the end of line -- This comment continues to the end of line /* This is an in-line comment */ /* This is a multiple-line comment */ Example: SELECT * FROM t1; -- this is comment CREATE TABLE stack( /*id_user int...
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...
Sometimes what you want to do is just too complex for a filter or a simple_tag. Fow this you will need to create a compilation function and a renderer. In this example we will create a template tag verbose_name with the following syntax: ExampleDescription{% verbose_name obj %}Verbose name of a mo...
superman-directive.js angular.module('myApp', []) .directive('superman', function() { return { // restricts how the directive can be used restrict: 'E', templateUrl: 'superman-template.html', controller: function() { this.message = "I'm superman!&qu...

Page 178 of 826