Tutorial by Examples: c

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...
Descriptors are objects that are (usually) attributes of classes and that have any of __get__, __set__, or __delete__ special methods. Data Descriptors have any of __set__, or __delete__ These can control the dotted lookup on an instance, and are used to implement functions, staticmethod, classmet...
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...
Sometimes it's not a good practice expose an internal collection since it can lead to a malicious code vulnerability due to it's mutable characteristic. In order to provide "read-only" collections java provides its unmodifiable versions. An unmodifiable collection is often a copy of a mod...
Consider the following tough-to-vectorize for loop, which creates a vector of length len where the first element is specified (first) and each element x_i is equal to cos(x_{i-1} + 1): repeatedCosPlusOne <- function(first, len) { x <- numeric(len) x[1] <- first for (i in 2:len) { ...
Let's create our own error type for this example. 2.2 enum CustomError: ErrorType { case SomeError case AnotherError } func throwing() throws { throw CustomError.SomeError } 3.0 enum CustomError: Error { case someError case anotherError } func throwing() thr...
If you are using the default bash prompt on Linux, you should see the name of the virtual environment at the start of your prompt. (my-project-env) user@hostname:~$ which python /home/user/my-project-env/bin/python
In order to specify which version of python the Linux shell should use the first line of Python scripts can be a shebang line, which starts with #!: #!/usr/bin/python If you are in a virtual environment, then python myscript.py will use the Python from your virtual environment, but ./myscript.py...
In Rails, you find yourself looking at controllers, views, and models for your database. To reduce the need for heavy configuration, Rails implements rules to ease up working with the application. You may define your own rules but for the beginning (and for later on) it's a good idea to stick to co...
By default, the various Collection types are not thread-safe. However, it's fairly easy to make a collection thread-safe. List<String> threadSafeList = Collections.synchronizedList(new ArrayList<String>()); Set<String> threadSafeSet = Collections.synchronizedSet(new HashSet<S...
Given the following history, imagine you make a change that you want to squash into the commit bbb2222 A second commit: $ git log --oneline --decorate ccc3333 (HEAD -> master) A third commit bbb2222 A second commit aaa1111 A first commit 9999999 Initial commit Once you've made your change...
Now that the router is configured and our app knows how to handle the routes, we need to show the actual components that we configured. To do so, configure your HTML template/file for your top-level (app) component like so: //app.ts import {Component} from '@angular/core'; import {Router, ROUT...
Now that the routes are set up, we need some way to actually change routes. This example will show how to change routes using the template, but it is possible to change routes in TypeScript. Here is one example (without binding): <a routerLink="/home">Home</a> If the user...
git cherry-pick <commit-A>..<commit-B> will place every commit after A and up to and including B on top of the currently checked-out branch. git cherry-pick <commit-A>^..<commit-B> will place commit A and every commit up to and including B on top of the currently checked-out...
The @import CSS at-rule is used to import style rules from other style sheets. These rules must precede all other types of rules, except @charset rules; as it is not a nested statement, @import cannot be used inside conditional group at-rules. @import. How to use @import You can use @import rule ...
To generate a controller (for example Posts), navigate to your project directory from a command line or terminal, and run: $ rails generate controller Posts You can shorten this code by replacing generate with g, for example: $ rails g controller Posts If you open up the newly generated app/...
Python uses indentation to define control and loop constructs. This contributes to Python's readability, however, it requires the programmer to pay close attention to the use of whitespace. Thus, editor miscalibration could result in code that behaves in unexpected ways. Python uses the colon symbo...
docker rm can be used to remove a specific containers like this: docker rm <container name or id> To remove all containers you can use this expression: docker rm $(docker ps -qa) By default docker will not delete a container that is running. Any container that is running will produce a...
Browsers have a default set of CSS styles they use for rendering elements. Some of these styles can even be customised using the browser's settings to change default font face and size definitions, for example. The styles contain the definition of which elements are supposed to be block-level or inl...
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...

Page 91 of 826