Tutorial by Examples: c

class CustomException implements Exception { String cause; CustomException(this.cause); } void main() { try { throwException(); } on CustomException { print("custom exception is been obtained"); } } throwException() { throw new CustomException('This is m...
Fortran originally was designed for a fixed format form based on an 80 column punched card: Yes: This is a line of the author's own code These were created on a card punch machine, much like this: Images are original photography by the author The format, as shown on the illustrated sample ca...
It is a good practice to provide expression string arguments as braced strings. The heading "Double Substitution" outlines important reasons behind the same. The expr command evaluates an operator-based expression string to calculate a value. This string is constructed from the arguments ...
To implement the hashCode method of an object easily you could use the HashCodeBuilder class. Selecting the fields: @Override public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(); builder.append(field1); builder.append(field2); builder.append(field3); ...
When the view controller is presented within a tab bar controller, you can access the tab bar controller like this: Swift let tabBarController = viewController.tabBarController Objective-C UITabBarController *tabBarController = self.tabBarController; When the view controller is part on an n...
C99 Added in the C standard version C99, _Bool is also a native C data type. It is capable of holding the values 0 (for false) and 1 (for true). #include <stdio.h> int main(void) { _Bool x = 1; _Bool y = 0; if(x) /* Equivalent to if (x == 1) */ { puts("T...
You can use gradle to have BuildConfig constants and res values on a per flavor basis. Just add the value to the flavor you want to support. android { defaultConfig { resValue "string", "app_name", "Full App" buildConfigField "boolean",...
To change PS1, you just have to change the value of PS1 shell variable. The value can be set in ~/.bashrc or /etc/bashrc file, depending on the distro. PS1 can be changed to any plain text like: PS1="hello " Besides the plain text, a number of backslash-escaped special characters are s...
Matlab supports synchronous and asynchronous communication with a serial port. It is important to chose the right communication mode. The choice will depend on: how the instrument you are communicating with behave. what other functions your main program (or GUI) will have to do aside from managi...
You can convert a numeric string to various Java numeric types as follows: String to int: String number = "12"; int num = Integer.parseInt(number); String to float: String number = "12.0"; float num = Float.parseFloat(number); String to double: String double = "1...
namespace App\Controller; class PostsController extends AppController { public function initialize(){ parent::initialize(); // code that you want to run before every action } public function view($id) { //Your code here } }
The beforeFilter() method executes before any other method executes in the controller. First use the Event namespace before defining the class in your controller file. use Cake\Event\Event; In your controller, add the beforeFilter() method as shown below. public function beforeFilter(Event $ev...
By default CakePHP loads the related model in the controller. In order to load another model in the controller, use the loadModel() method: $this->loadModel('Articles'); or load on the fly $table = TableRegistry::get('Articles'); $table->find();
When inheriting from base Controller class provided by the framework, you can use the convenience method ViewComponent() to return a view component from the action: public IActionResult GetMyComponent() { return ViewComponent("Login", new { param1 = "foo", param2 = 42 }); ...
There are a several different ways of sorting a collection. Sort() The sort method sorts the collection: $collection = collect([5, 3, 1, 2, 4]); $sorted = $collection->sort(); echo $sorted->values()->all(); returns : [1, 2, 3, 4, 5] The sort method also allows for passing in ...
The format of a playbook is quite straightforward, but strict in terms of spacing and layout. A playbook consists of plays. A play is a combination of targets hosts and the tasks we want to apply on these hosts, so a drawing of a playbook is this: To execute this playbook, we simply run: ansible...
Here’s a simple play: - name: Configure webserver with git hosts: webserver become: true vars: package: git tasks: - name: install git apt: name={{ package }} state=present As we said earlier, every play must contain: A set of hosts to configure A list of t...
Sometimes it is required to display a notification at a specific time, a task that unfortunately is not trivial on the Android system, as there is no method setTime() or similiar for notifications. This example outlines the steps needed to schedule notifications using the AlarmManager: Add a Broa...
The sensor values returned by Android are with respective to the phone's coordinate system (e.g. +Y points towards the top of the phone). We can transform these sensor values into a world coordinate system (e.g. +Y points towards magnetic North, tangential to the ground) using the sensor managers ro...
You can use the adb backup command to backup your device. adb backup [-f <file>] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared] [-all] [-system|nosystem] [<packages...>] -f <filename> specify filename default: creates backup.ab in the current directory -apk|noapk...

Page 272 of 826