Tutorial by Examples: ai

The function chomp will remove one newline character, if present, from each scalar passed to it. chomp will mutate the original string and will return the number of characters removed my $str = "Hello World\n\n"; my $removed = chomp($str); print $str; # "Hello World\n" pr...
Introduction and motivation Expression templates (denoted as ETs in the following) are a powerful template meta-programming technique, used to speed-up calculations of sometimes quite expensive expressions. It is widely used in different domains, for example in implementation of linear algebra ...
def str = ''' multiline string''' assert str.readLines().size() == 3
def str = '''\ multiline string''' assert str.readLines().size() == 2
You can resolve data into your state when you transition into it, usually it's useful when the state needs to use that data, or to resolve into a state when some provided input needs to be authenticated. When you define your states, you will need to provide a map of values to be resolved into the ....
Use appearanceWhenContainedInInstancesOfClasses: to customize the appearance for instance of a class when contained within an instance of container class. For example customization of UILabel's textColor and backgroundColor within ViewController class will look like this: Set UILabel text color Sw...
Like any other java program, every swing program starts with a main method. The main method is initiated by the main thread. However, Swing components need to be created and updated on the event dispatch thread (or short: EDT). To illustrate the dynamic between the main thread and the EDT take a loo...
Const baseString As String = "Foo Bar" Dim containsBar As Boolean 'Check if baseString contains "bar" (case insensitive) containsBar = InStr(1, baseString, "bar", vbTextCompare) > 0 'containsBar = True 'Check if baseString contains bar (case insensitive) co...
'Trim the leading and trailing spaces in a string Const paddedText As String = " Foo Bar " Dim trimmedText As String trimmedText = Trim$(paddedText) 'trimmedText = "Foo Bar"
Setup First, install the necessary packages with: npm install express cors mongoose Code Then, add dependencies to server.js, create the database schema and the name of the collection, create an Express.js server, and connect to MongoDB: var express = require('express'); var cors = require('...
Note: Before upgrading your Rails app, always make sure to save your code on a version control system, such as Git. To upgrade from Rails 4.2 to Rails 5.0, you must be using Ruby 2.2.2 or newer. After upgrading your Ruby version if required, go to your Gemfile and change the line: gem 'rails', '...
we can create a new controller with rails g controller command. $ bin/rails generate controller controller_name The controller generator is expecting parameters in the form of generate controller ControllerName action1 action2. The following creates a Greetings controller with an action of hell...
public class App : Application { internal static NavigationPage NavPage; public App () { // The root page of your application MainPage = new RootPage(); } } public class RootPage : MasterDetailPage { public RootPage() { var menuPage = ne...
Assume an application with a MainActivity which can call the Next Activity using a button click. public class MainActivity extends AppCompatActivity { private final String LOG_TAG = MainActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { ...
When performing tasks asynchronously there typically becomes a need to ensure a piece of code is run on the main thread. For example you may want to hit a REST API asynchronously, but put the result in a UILabel on the screen. Before updating the UILabel you must ensure that your code is run on th...
The Builder pattern allows you to create an instance of a class with many optional variables in an easy to read way. Consider the following code: public class Computer { public GraphicsCard graphicsCard; public Monitor[] monitors; public Processor processor; public Memory[] r...
This will trigger the native email client for sharing text. Parameters : Email To address, Subject, Body. Code Sample : you can call the function wherever you need, (mostly inside click listeners) like below Calling function shareEmail("[email protected]", "Email sharing example&q...
Coming from imperative languages many developers wonder how to write a for-loop that exits early as F# doesn't support break, continue or return. The answer in F# is to use tail-recursion which is a flexible and idiomatic way to iterate while still providing excellent performance. Say we want to ...
One common scenario is to wait for a number of requests to finish before continuing. This can be accomplished using the forkJoin method. In the following example, forkJoin is used to call two methods that return Observables. The callback specified in the .subscribe method will be called when both O...
Matching an email address within a string is a hard task, because the specification defining it, the RFC2822, is complex making it hard to implement as a regex. For more details why it is not a good idea to match an email with a regex, please refer to the antipattern example when not to use a ...

Page 16 of 47