Tutorial by Examples: ce

Declaration-site variance can be thought of as declaration of use-site variance once and for all the use-sites. class Consumer<in T> { fun consume(t: T) { ... } } fun charSequencesConsumer() : Consumer<CharSequence>() = ... val stringConsumer : Consumer<String> = cha...
Use-site variance is similar to Java wildcards: Out-projection: val takeList : MutableList<out SomeType> = ... // Java: List<? extends SomeType> val takenValue : SomeType = takeList[0] // OK, since upper bound is SomeType takeList.add(takenValue) // Error, lower bound for...
You can declare properties in interfaces. Since an interface cannot have state you can only declare a property as abstract or by providing default implementation for the accessors. interface MyInterface { val property: Int // abstract val propertyWithImplementation: String g...
If you wish to copy the contents of a slice into an initially empty slice, following steps can be taken to accomplish it- Create the source slice: var sourceSlice []interface{} = []interface{}{"Hello",5.10,"World",true} Create the destination slice, with: Length =...
The canvas element was introduced in HTML5 for drawing graphics. <canvas id="myCanvas"> Cannot display graphic. Canvas is not supported by your browser (IE<9) </canvas> The above will create a transparent HTML<canvas> element of 300×150 px in size. You can us...
Compile errors can be generated using the preprocessor. This is useful for a number of reasons some of which include, notifying a user if they are on an unsupported platform or an unsupported compiler. e.g. Return Error if gcc version is 3.0.0 or earlier. #if __GNUC__ < 3 #error "This cod...
NSArray *array1 = [NSArray arrayWithObjects:@"one", @"two", @"three", nil]; NSArray *array2 = @[@"one", @"two", @"three"];
Procedures do something. Name them after what they're doing, using a verb. If accurately naming a procedure is not possible, likely the procedure is doing too many things and needs to be broken down into smaller, more specialized procedures. Some common VBA naming conventions go thus: For all Pr...
To avoid repetition in nested routes, concerns provide a great way of sharing common resources that are reusable. To create a concern use the method concern within the routes.rb file. The method expects a symbol and block: concern :commentable do resources :comments end While not creating a...
When assigning named methods to delegates, they will refer to the same underlying object if: They are the same instance method, on the same instance of a class They are the same static method on a class public class Greeter { public void WriteInstance() { Console.Write...
One of the things that can really boost your productivity while writing the code is effectively navigating the workspace. This also means making it comfortable for the moment. It's possible to achieve this by adjusting which areas of workspaces you see. The buttons on the top of the navigation and ...
m := make(map[string][]int) Accessing a non-existent key will return a nil slice as a value. Since nil slices act like zero length slices when used with append or other built-in functions you do not normally need to check to see if a key exists: // m["key1"] == nil && len(m[&qu...
Python uses the C3 linearization algorithm to determine the order in which to resolve class attributes, including methods. This is known as the Method Resolution Order (MRO). Here's a simple example: class Foo(object): foo = 'attr foo of Foo' class Bar(object): foo = 'attr foo o...
The UITableViewDelegate is used to control how the table is displayed, and UITableViewDataSource is used to define the UITableView's data. There are two required methods and many optional ones which can be used to customize size, sections, headings, and cells in the UITableView. UITableViewDataSo...
execute the following command to insert the text into a view with a focus (if it supports text input) 6.0 Send text on SDK 23+ adb shell "input keyboard text 'Paste text on Android Device'" If already connected to your device via adb: input text 'Paste text on Android Device' 6...
It is common to want two views to be side by side, centered in their superview. The common answer given on Stack Overflow is to embed these two views in a UIView and center the UIView. This is not necessary or recommended. From the UILayoutGuide docs: There are a number of costs associated with...
In Go, an interface is just a set of methods. We use an interface to specify a behavior of a given object. type Painter interface { Paint() } The implementing type need not declare that it is implementing the interface. It is enough to define methods of the same signature. type Rembrandt ...
Assuming you have a model called Post defined in your models.py file that contains blog posts, and has a date_published field. Step 1: Write the context processor Create (or add to) a file in your app directory called context_processors.py: from myapp.models import Post def recent_blog_posts...
This example of the Sortable using a Placeholder is common usage. Sortable is applied to a group of DOM elements, allowing the user to move items around in the list via Drag'n Drop style actions. <!doctype html> <html lang="en"> <head> <meta charset="utf-8&q...
It is possible to configure Django to output log to a local or remote syslog service. This configuration uses the python builtin SysLogHandler. from logging.handlers import SysLogHandler LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'formatters': { 'standard':...

Page 15 of 134